123use std::{ffi::CStr, os::raw::c_char};45use jrsonnet_evaluator::State;678#[no_mangle]9pub unsafe extern "C" fn jsonnet_ext_var(vm: &State, name: *const c_char, value: *const c_char) {10 let name = CStr::from_ptr(name);11 let value = CStr::from_ptr(value);1213 let any_resolver = vm.context_initializer();14 any_resolver15 .as_any()16 .downcast_ref::<jrsonnet_stdlib::ContextInitializer>()17 .expect("only stdlib context initializer supported")18 .add_ext_str(19 name.to_str().unwrap().into(),20 value.to_str().unwrap().into(),21 )22}232425#[no_mangle]26pub unsafe extern "C" fn jsonnet_ext_code(vm: &State, name: *const c_char, value: *const c_char) {27 let name = CStr::from_ptr(name);28 let value = CStr::from_ptr(value);2930 let any_resolver = vm.context_initializer();31 any_resolver32 .as_any()33 .downcast_ref::<jrsonnet_stdlib::ContextInitializer>()34 .expect("only stdlib context initializer supported")35 .add_ext_code(name.to_str().unwrap(), value.to_str().unwrap())36 .unwrap()37}3839#[no_mangle]40pub unsafe extern "C" fn jsonnet_tla_var(vm: &State, name: *const c_char, value: *const c_char) {41 let name = CStr::from_ptr(name);42 let value = CStr::from_ptr(value);43 vm.add_tla_str(44 name.to_str().unwrap().into(),45 value.to_str().unwrap().into(),46 )47}4849#[no_mangle]50pub unsafe extern "C" fn jsonnet_tla_code(vm: &State, name: *const c_char, value: *const c_char) {51 let name = CStr::from_ptr(name);52 let value = CStr::from_ptr(value);53 vm.add_tla_code(name.to_str().unwrap().into(), value.to_str().unwrap())54 .unwrap()55}