123use std::{4 ffi::CString,5 os::raw::{c_char, c_double, c_int},6};78use jrsonnet_evaluator::Val;910use crate::VM;111213#[no_mangle]14pub extern "C" fn jsonnet_json_extract_string(_vm: &VM, v: &Val) -> *mut c_char {15 match v {16 Val::Str(s) => CString::new(s as &str).unwrap().into_raw(),17 _ => std::ptr::null_mut(),18 }19}202122#[no_mangle]23pub extern "C" fn jsonnet_json_extract_number(_vm: &VM, v: &Val, out: &mut c_double) -> c_int {24 match v {25 Val::Num(n) => {26 *out = *n;27 128 }29 _ => 0,30 }31}323334#[no_mangle]35pub extern "C" fn jsonnet_json_extract_bool(_vm: &VM, v: &Val) -> c_int {36 match v {37 Val::Bool(false) => 0,38 Val::Bool(true) => 1,39 _ => 2,40 }41}424344#[no_mangle]45pub extern "C" fn jsonnet_json_extract_null(_vm: &VM, v: &Val) -> c_int {46 match v {47 Val::Null => 1,48 _ => 0,49 }50}