A safe-Rust Lua runtime

lua-rs

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.

44 / 44
upstream Lua 5.4.7 tests passing
1.27×
wall-time geomean vs C (lower is better)
safe
Rust by default; audited unsafe core
0
C runtime dependencies to run a script

What it is

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.

Install & run

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

Browser WebAssembly

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/

Conformance

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.

Performance

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.

MetricValueReading
Wall-time geomean1.27×~27% slower than C on average
RSS geomean1.96×~2× the memory of C
Best workload0.38×faster than C
Worst workload2.07×slowest relative workload
This is not "faster than C." It is a memory-safe reimplementation that is competitive with C — within a small constant factor on average, ahead on some workloads — with the full per-workload trajectory published rather than reduced to one number.
Open the live performance dashboard →

Safety model

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.

How it was built

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.

Oracle-gated, not vibes-gated

Build success is not signal. A change counts only when a behavioral or structural oracle says it matches the reference C binary.

Mechanical guardrails

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.

Status & roadmap

shipping

Lua 5.4 runtime

Runs real Lua programs, passes 44/44 upstream tests, and is published to crates.io as lua-cli.

shipping

Browser WASM package

The lua-rs-wasm npm package runs Lua in the browser through the published WebAssembly build and JS host hooks.

working

LuaRocks (pure-Lua rocks)

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.