git.delta.rocks / jrsonnet / refs/commits / 695a2f8d51fa

difftreelog

source

bindings/jsonnet/src/val_modify.rs1.2 KiBsourcehistory
1//! Modify VM values2//! Only tested with variables, which haven't altered by code before appearing here3//! In jrsonnet every value is immutable, and this code is probally broken45use jrsonnet_evaluator::{EvaluationState, LazyBinding, LazyVal, ObjMember, ObjValue, Val};6use jrsonnet_parser::Visibility;7use std::{collections::HashMap, ffi::CStr, os::raw::c_char, rc::Rc};89/// # Safety10///11/// Received arr value should be correct pointer to array allocated by make_array12#[no_mangle]13pub unsafe extern "C" fn jsonnet_json_array_append(14	_vm: &EvaluationState,15	_arr: *mut Val,16	_val: &Val,17) {18	todo!()19}2021/// # Safety22///23/// This function is safe if passed name is ok24#[no_mangle]25pub unsafe extern "C" fn jsonnet_json_object_append(26	_vm: &EvaluationState,27	obj: &mut Val,28	name: *const c_char,29	val: &Val,30) {31	match obj {32		Val::Obj(old) => {33			let mut new = HashMap::new();34			new.insert(35				CStr::from_ptr(name).to_str().unwrap().into(),36				ObjMember {37					add: false,38					visibility: Visibility::Normal,39					invoke: LazyBinding::Bound(LazyVal::new_resolved(val.clone())),40					location: None,41				},42			);43			let new_obj = ObjValue::new(Some(old.clone()), Rc::new(new));44			*obj = Val::Obj(new_obj);45		}46		_ => panic!("should receive object"),47	}48}