Note: This is an Lua 5.5 lib through AI-assisted programming.
luars is a pure Rust Lua 5.5 runtime and embedding toolkit. This repository contains the core library, derive macros, the interpreter, debugger integration, a WASM target, and several host-facing examples.
The repository-level documentation is intentionally focused on the high-level Lua API. Lower-level LuaVM APIs still exist, but the default examples and guides now use the high-level surface first.
[dependencies]
luars = "0.18"use luars::{Lua, SafeOption, Stdlib};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut lua = Lua::new(SafeOption::default());
lua.load_stdlibs(Stdlib::All)?;
lua.register_function("add", |a: i64, b: i64| a + b)?;
let sum: i64 = lua.load("return add(20, 22)").eval()?;
assert_eq!(sum, 42);
Ok(())
}- Execute chunks with
lua.load(...).exec(),eval(), andeval_multi() - Execute async chunks with
exec_async(),eval_async(), andeval_multi_async() - Call Lua globals with
call_global()/call_global1()and their async variants - Register Rust functions with
register_function()andregister_async_function() - Expose Rust types with
register_type()andLuaUserData - Work with globals and tables through
globals(),create_table(), andcreate_table_from() - Create scoped borrowed callbacks and userdata through
scope(...) - Run isolated chunks through
load_sandboxed()andexecute_sandboxed()when thesandboxfeature is enabled
| Path | Description |
|---|---|
crates/luars |
Core library with the compiler, VM, GC, and high-level Lua API |
crates/luars-derive |
LuaUserData and lua_methods macros |
crates/luars_interpreter |
CLI interpreter and bytecode tools |
crates/luars_debugger |
Debugger integration |
crates/luars_wasm |
WASM bindings |
docs/ |
High-level embedding guides |
examples/ |
Host examples built around the high-level API |
| Example | Description |
|---|---|
| examples/luars-example | Minimal high-level API example: globals, userdata, and scope |
| examples/rules-engine-demo | Business rules engine with Rust host functions and Lua policy |
| examples/http-server | Async HTTP example using high-level async calls and sandboxed Lua request handlers |
| examples/rust-bind-bench | High-level userdata registration benchmark |
| Document | Description |
|---|---|
| docs/Guide.md | High-level Lua API overview |
| docs/UserGuide.md | High-level userdata guide |
| docs/Async.md | High-level async and sandbox status |
| docs/Different.md | Known differences from C Lua |
| crates/luars/README.md | Crate-level documentation |
cargo testMIT. See LICENSE.