git.delta.rocks / jrsonnet / refs/commits / 0831da3ed8d9

difftreelog

source

bindings/jsonnet/src/vars_tlas.rs1.6 KiBsourcehistory
1//! Manipulate external variables and top level arguments23use std::{ffi::CStr, os::raw::c_char};45use jrsonnet_evaluator::State;67/// # Safety8#[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}2324/// # Safety25#[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}38/// # Safety39#[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}48/// # Safety49#[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}