123use std::{ffi::CStr, os::raw::c_char};45use jrsonnet_evaluator::State;67891011121314#[no_mangle]15pub unsafe extern "C" fn jsonnet_ext_var(vm: &State, name: *const c_char, value: *const c_char) {16 let name = CStr::from_ptr(name);17 let value = CStr::from_ptr(value);1819 let any_initializer = vm.context_initializer();20 any_initializer21 .as_any()22 .downcast_ref::<jrsonnet_stdlib::ContextInitializer>()23 .expect("only stdlib context initializer supported")24 .add_ext_str(25 name.to_str().expect("name is not utf-8").into(),26 value.to_str().expect("value is not utf-8").into(),27 )28}293031323334353637#[no_mangle]38pub unsafe extern "C" fn jsonnet_ext_code(vm: &State, name: *const c_char, code: *const c_char) {39 let name = CStr::from_ptr(name);40 let code = CStr::from_ptr(code);4142 let any_initializer = vm.context_initializer();43 any_initializer44 .as_any()45 .downcast_ref::<jrsonnet_stdlib::ContextInitializer>()46 .expect("only stdlib context initializer supported")47 .add_ext_code(48 name.to_str().expect("name is not utf-8"),49 code.to_str().expect("code is not utf-8"),50 )51 .expect("can't parse ext code")52}535455565758596061#[no_mangle]62pub unsafe extern "C" fn jsonnet_tla_var(vm: &State, name: *const c_char, value: *const c_char) {63 let name = CStr::from_ptr(name);64 let value = CStr::from_ptr(value);65 vm.add_tla_str(66 name.to_str().expect("name is not utf-8").into(),67 value.to_str().expect("value is not utf-8").into(),68 )69}707172737475767778#[no_mangle]79pub unsafe extern "C" fn jsonnet_tla_code(vm: &State, name: *const c_char, code: *const c_char) {80 let name = CStr::from_ptr(name);81 let code = CStr::from_ptr(code);82 vm.add_tla_code(83 name.to_str().expect("name is not utf-8").into(),84 code.to_str().expect("code is not utf-8"),85 )86 .expect("can't parse tla code")87}