rustia 0.2.0

Rustia is a pure-Rust interpreter for embedding standalone Luau in games and tools. Edit scripts without a rebuild and let players write mods. Rustia grew out of a game by Slowchop Studios that needed to script character decisions and replay them on desktop and in a browser.
Documentation
//! Let a Luau script update a Rust counter. The update takes effect as soon
//! as the script calls the method, and it stays in place if the script later fails.
//!
//! From the repository root, run
//! `cargo run --locked -p rustia --example mutable_objects`. It reports that
//! the counter is 3 and shows the script error.

use rustia::{Error, ObjectType, Result, RustiaBuilder};

struct Counter {
    value: i64,
}

fn main() -> Result<()> {
    let mut lua = RustiaBuilder::standard().build()?;
    // Register the type's script methods before creating an instance.
    lua.register_object_type(
        ObjectType::<Counter>::new("Counter")
            .method("value", 1, |counter: &Counter| counter.value)
            .method_mut(
                "add",
                1,
                |counter: &mut Counter, amount: i64| -> Result<()> {
                    counter.value = counter
                        .value
                        .checked_add(amount)
                        .ok_or_else(|| Error::embed("counter is out of range"))?;
                    Ok(())
                },
            ),
    )?;
    let counter = lua.create_object(Counter { value: 0 })?;
    // Expose a live handle: Luau calls mutate this same Rust payload.
    lua.globals()?
        .set_live(&mut lua, "counter", &counter.as_value())?;

    let error = lua
        .exec("counter:add(3); error('later failure')")
        .unwrap_err();
    // An immediate application change survives a later script error.
    assert_eq!(counter.call_method::<_, i64>(&mut lua, "value", ())?, 3);
    println!("Counter is 3 after: {error}");
    Ok(())
}