MCPcopy Index your code
hub / github.com/aiscriptdev/aiscript / io_append_file

Function io_append_file

aiscript-vm/src/stdlib/io.rs:117–135  ·  view source on GitHub ↗
(
    _state: &mut State<'gc>,
    args: Vec<Value<'gc>>,
)

Source from the content-addressed store, hash-verified

115}
116
117fn io_append_file<'gc>(
118 _state: &mut State<'gc>,
119 args: Vec<Value<'gc>>,
120) -> Result<Value<'gc>, VmError> {
121 let path = string_arg!(args, 0, "append_file")?.to_string();
122 let content = string_arg!(args, 1, "append_file")?.to_string();
123
124 let mut file = OpenOptions::new()
125 .create(true)
126 .append(true)
127 .open(&path)
128 .map_err(|e| VmError::RuntimeError(format!("Failed to open file '{}': {}", path, e)))?;
129
130 file.write_all(content.as_bytes()).map_err(|e| {
131 VmError::RuntimeError(format!("Failed to append to file '{}': {}", path, e))
132 })?;
133
134 Ok(Value::Boolean(true))
135}
136
137fn io_input<'gc>(state: &mut State<'gc>, args: Vec<Value<'gc>>) -> Result<Value<'gc>, VmError> {
138 // Optional input

Callers

nothing calls this directly

Calls 3

RuntimeErrorClass · 0.85
createMethod · 0.80
as_bytesMethod · 0.80

Tested by

no test coverage detected