luau 0.732.0

Safe lifetime-bound Rust embedding API for the Luau runtime
use luau::{Function, Lua};

fn main() -> luau::Result<()> {
    let lua = Lua::new()?;

    let callback_key = {
        let callback: Function<'_> = lua
            .load(
                r#"
                return function(left, right)
                    return left * right
                end
                "#,
            )
            .set_name("registry_reference")
            .call(())?;

        lua.create_registry_value(callback)?
    };

    // Registry keys retain a Luau value without retaining a lifetime-bound
    // handle to that value in application state.
    let callback: Function<'_> = lua.registry_value(&callback_key)?;
    let result: i32 = callback.call((6, 7))?;

    lua.remove_registry_value(callback_key)?;

    println!("{result}");
    Ok(())
}