Skip to content

ianm199/lua-rs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

800 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

lua-rs

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).

CI crates.io docs.rs license

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 REPL

It 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.

Embed it in Rust

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).

Browser / WebAssembly

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.

LuaRocks

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.

More

License

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.

About

A Lua 5.4.7 interpreter written in Rust. Passes the upstream test suite (44/44); runs LuaRocks.

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Packages

 
 
 

Contributors