Embedding in Rust
The omnilua crate has an API close to mlua's. This page covers the basics; the full reference is on docs.rs.
Run code, call functions
rust
use omnilua::Lua; let lua = Lua::new(); lua.load("x = 1 + 2").exec()?; let x: i64 = lua.globals().get("x")?; // 3 let sum: i64 = lua.load("return 6 * 7").eval()?; // 42
Expose Rust to Lua
rust
let add = lua.create_function(|_, (a, b): (i64, i64)| Ok(a + b))?; lua.globals().set("add", add)?; lua.load("print(add(2, 3))").exec()?; // 5
Implement UserData to give a Rust type methods callable from Lua. To lend non-'static state for one call, use scope — see Game scripting.
More
- Conversions for primitives, strings,
Option,Vec,HashMap, tuples, and serde types (serdefeature). - Registry keys, bytecode dump/load, tracebacks, GC control, and host-driven coroutines.
- Async host functions with the
asyncfeature.
Reference
Every type and method is documented on docs.rs/omnilua.