A Lua 5.4.7 interpreter written in Rust. Runs as a standalone binary with no C dependency, embeds in Rust programs and in the browser, and passes the full upstream PUC-Rio test suite (44/44).
cargo install lua-cli # crate `lua-cli`; the binary it installs is `lua-rs`
lua-rs -e 'print("hello")'
lua-rs script.lua # run a file; `lua-rs` for the REPLIt is competitive with reference C (~1.3× geomean wall time, benchmarked per
commit), not faster,
and is not LuaJIT. Most crates build under #![forbid(unsafe_code)]; the
trusted unsafe is budgeted in the GC, the dynamic-library loader, and the WASM
pointer ABI.
lua-rs-runtime is an embedding API
shaped after mlua. Being pure Rust, it builds for wasm32-unknown-unknown
and needs no C toolchain or liblua. It's young and it isn't LuaJIT, so if you
need either, use mlua.
let lua = Lua::new();
let f = lua.create_function(|_, name: String| Ok(format!("hello, {name}")))?;
lua.globals().set("greet", f)?;
lua.load(r#"print(greet("lua-rs"))"#).exec()?;Lua::scope lends Lua a non-'static borrow (e.g. a game engine's &mut World) for one call; a handle that escapes the scope errors cleanly instead of
dangling. AnyUserData::delegate returns live sub-references into it.
lua.scope(|s| {
let world = s.create_userdata_ref_mut(&lua, &mut my_world)?;
lua.globals().set("world", &world)?;
lua.load("world:spawn('player')").exec()
})?;Full API on docs.rs. Worked Bevy 0.18 integration: bevy-lua-rs-starter (live demo).
Ships as lua-rs-wasm (npm) for
running Lua in the browser or Node without bundling the C interpreter. Try it in
the playground; see
harness/wasm/README.md for the host-hook API.
Runs the stock LuaRocks 3.11.1 client and installs pure-Lua rocks (inspect,
dkjson, argparse, middleclass, say, luassert). Native C rocks are not
supported yet.
- Conformance:
TEST_TIMEOUT_S=90 ./harness/run_official_all.shruns the unmodified upstream suite againstlua-rs(44/44). This is Lua source/runtime compatibility, not C API/ABI compatibility. - Building, testing, and contributing: CONTRIBUTING.md.
- Embedding internals and roadmap: docs/EMBEDDING_API_IMPLEMENTATION.md, docs/FUTURE_GOALS.md.
A port of Lua (Roberto Ierusalimschy, Luiz Henrique de Figueiredo, and Waldemar Celes, PUC-Rio). Lua and this port are both MIT-licensed. See LICENSE.