A safe-Rust Lua runtime
Lua 5.4.7, reimplemented in safe Rust. A from-scratch port of the reference PUC-Rio interpreter that passes 44/44 of the upstream Lua test suite — with no C runtime.
$ cargo install lua-cli
Crate lua-cli installs the lua-rs binary. cargo install lua-cli is the install; lua-rs is what you run.
lua-rs is a complete reimplementation of PUC-Rio Lua 5.4.7 in Rust — lexer, parser, bytecode compiler, register VM, garbage collector, coroutines, and standard library. It runs ordinary .lua programs as a standalone Rust binary, validated against the exact test files the C implementation uses.
# from crates.io (preview release) $ cargo install lua-cli # crate lua-cli → binary lua-rs $ lua-rs -e 'print(("safe rust"):upper())' SAFE RUST $ lua-rs script.lua # run a source file $ echo 'print("hi")' | lua-rs - # read a program from stdin $ lua-rs # start the interactive REPL
lua-rs mirrors the standard lua CLI: a bare argument is a script filename, -e runs a chunk, - reads from stdin, and no arguments on a terminal starts the REPL.
The same interpreter core is published as lua-rs-wasm for browser and Node embeddings. The package ships a prebuilt wasm32-unknown-unknown artifact plus JS host hooks for stdout, stdin, environment values, time, and controlled file access.
# from npm $ npm install lua-rs-wasm # or try it without installing anything https://ianm199.github.io/lua-rs/examples/wasm-browser/
The strongest claim this project makes. The unmodified upstream Lua 5.4.7 test suite runs against the lua-rs binary through a behavioral oracle — same input, diffed against reference C — and passes 44/44.
$ TEST_TIMEOUT_S=90 ./harness/run_official_all.sh
→ 44/44 PASS
This is strong evidence for Lua source/runtime compatibility. It does not imply C API or ABI compatibility.
Every benchmarked commit is recorded and plotted on a live, auto-built dashboard. Each point is the ratio of lua-rs wall time to reference PUC-Rio Lua on the same workload — lower is better, 1.00× is parity with C.
| Metric | Value | Reading |
|---|---|---|
| Wall-time geomean | 1.27× | ~27% slower than C on average |
| RSS geomean | 1.96× | ~2× the memory of C |
| Best workload | 0.38× | faster than C |
| Worst workload | 2.07× | slowest relative workload |
A safe public surface over a small, audited unsafe core. Most crates compile under #![forbid(unsafe_code)]. The remaining unsafe is budgeted with per-crate ceilings enforced by a gate, and lives only in the garbage collector (lua-gc) and the optional dynamic-library loader (lua-cli).
This is not "completely safe Rust," and it is not claimed to be — it is a safe surface over a contained, documented unsafe core.
The runtime is the artifact; the AI-agent porting harness is the method that produced it. ~28,000 lines of C became safe Rust under bounded, single-purpose agents gated by a non-negotiable oracle: a change is unverified until the upstream test suite says it matches reference C.
Build success is not signal. A change counts only when a behavioral or structural oracle says it matches the reference C binary.
Unsafe-budget ceilings, forbidden-pattern bans, required status trailers, and a verify-gate are enforced as hooks. The read-only verifier physically cannot mark a test passing — anti-sycophancy by construction.
Runs real Lua programs, passes 44/44 upstream tests, and is published to crates.io as lua-cli.
The lua-rs-wasm npm package runs Lua in the browser through the published WebAssembly build and JS host hooks.
lua-rs runs the real LuaRocks 3.11.1 package manager: search, install, show, and require pure-Lua rocks like inspect all work. Native C rocks are the remaining piece.