Skip to content

I/O

I/O is not installed by default. Hosts opt into stdout and sandboxed filesystem helpers, then grant io_read and/or io_write capabilities. This keeps script execution deterministic by default and makes process effects explicit.

io::print(value) writes a formatted value to stdout. io::println(value) writes the value plus a newline. Both return Result.

fn main() {
let printed = io::println("hello from Vela");
return printed.is_ok();
}

Ordinary output failures become Result::Err(IoError). Type errors, missing functions, and denied capabilities remain VM diagnostics.

fs::read_to_string(path) reads a UTF-8 file inside the configured sandbox. fs::write_string(path, text) writes a UTF-8 file inside the sandbox. Both return Result.

fn main() {
let input = result::unwrap_or(fs::read_to_string("input.txt"), "missing");
fs::write_string("output.txt", "done");
return input.len();
}

Paths must be relative. Empty paths, absolute paths, drive prefixes, and parent-directory escapes are rejected with Result::Err(IoError).

The Rust host installs these helpers explicitly.

let engine = Engine::builder()
.with_standard_natives()
.capability(Capability::IoRead)
.capability(Capability::IoWrite)
.with_stdio()
.with_fs_io(root)
.build()?;

Use I/O helpers for tools, demos, and controlled scripts. Server gameplay scripts should usually communicate through host APIs, events, or explicit state adapters instead of direct filesystem access.