12345use std::{ffi::CStr, os::raw::c_char};67use jrsonnet_evaluator::{val::ArrValue, Thunk, Val};8use jrsonnet_gcmodule::Cc;910use crate::VM;1112131415161718#[no_mangle]19pub unsafe extern "C" fn jsonnet_json_array_append(_vm: &VM, arr: &mut Val, val: &Val) {20 match arr {21 Val::Arr(old) => {22 let mut new = Vec::new();23 for item in old.iter_lazy() {24 new.push(item);25 }2627 new.push(Thunk::evaluated(val.clone()));28 *arr = Val::Arr(ArrValue::lazy(Cc::new(new)));29 }30 _ => panic!("should receive array"),31 }32}33343536373839404142#[no_mangle]43pub unsafe extern "C" fn jsonnet_json_object_append(44 _vm: &VM,45 obj: &mut Val,46 name: *const c_char,47 val: &Val,48) {49 match obj {50 Val::Obj(old) => old51 .extend_field(CStr::from_ptr(name).to_str().unwrap().into())52 .value(val.clone()),53 _ => panic!("should receive object"),54 }55}