MCPcopy Create free account
hub / github.com/aiscriptdev/aiscript / serde_from_file

Function serde_from_file

aiscript-vm/src/stdlib/serde.rs:86–108  ·  view source on GitHub ↗
(
    state: &mut State<'gc>,
    args: Vec<Value<'gc>>,
)

Source from the content-addressed store, hash-verified

84}
85
86fn serde_from_file<'gc>(
87 state: &mut State<'gc>,
88 args: Vec<Value<'gc>>,
89) -> Result<Value<'gc>, VmError> {
90 if args.len() != 1 {
91 return Err(VmError::RuntimeError(
92 "from_file() takes exactly 1 argument".into(),
93 ));
94 }
95
96 let path = string_arg!(&args, 0, "from_file")?;
97
98 // Read file content
99 let content = fs::read_to_string(path.to_str().unwrap())
100 .map_err(|e| VmError::RuntimeError(format!("Failed to read file: {}", e)))?;
101
102 // Parse JSON content
103 let parsed = serde_json::from_str(&content)
104 .map_err(|e| VmError::RuntimeError(format!("Failed to parse JSON from file: {}", e)))?;
105
106 // Convert to AIScript Value
107 Ok(Value::from_serde_value(state.get_context(), &parsed))
108}
109
110fn serde_to_file<'gc>(
111 _state: &mut State<'gc>,

Callers

nothing calls this directly

Calls 4

RuntimeErrorClass · 0.85
lenMethod · 0.80
to_strMethod · 0.80
get_contextMethod · 0.80

Tested by

no test coverage detected