luau 0.732.0

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

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

    host.set(
        "sum",
        luau::function!(|_lua, values: Variadic<i32>| { Ok(values.into_iter().sum::<i32>()) }),
    )?;
    host.set(
        "describe",
        luau::function!(|_lua| { Ok("host library from Rust") }),
    )?;
    lua.globals()?.set("host", host)?;

    let (total, description): (i32, String) = lua
        .load(
            r#"
            local total = host.sum(6, 7, 29)
            local description = host.describe()
            return total, description
            "#,
        )
        .set_name("rust_library")
        .call(())?;

    println!("{total}: {description}");
    Ok(())
}