Expand description
Embed Luau in Rust games and tools. Edit scripts without a rebuild and let players write mods.
Rustia grew out of a game by Slowchop Studios that needed to script character decisions and replay them on desktop and in a browser.
Rustia is a pure-Rust interpreter for standalone Luau. Use
RustiaBuilder::deterministic when the same script, seed, and inputs need
to produce the same decisions.
§A first script
Rust gives Luau a score and a function called double. Luau calls the function
and returns the new score to Rust. In a new Cargo app, put this in src/main.rs.
use rustia::Rustia;
fn main() -> rustia::Result<()> {
let mut vm = Rustia::builder().build()?;
vm.insert_global("base_score", 21)?;
vm.add_fn("double", |value: f64| value * 2.0)?;
let score: f64 = vm
.load("return double(base_score)")
.source_name("score.luau")
.eval()?;
println!("The score is {score}");
assert_eq!(score, 42.0);
Ok(())
}Run cargo run. It prints The score is 42.
§Find what you need
| I want to… | Start here |
|---|---|
| Run a script or get a result back | Chunk::exec runs it. Chunk::eval returns a Rust value. |
| Pass data from Rust to Luau | Rustia::insert_global sets a named value. Rustia::insert_serde passes a struct or collection. |
| Call a Luau function from Rust | Chunk::install loads its module. Exports::function looks up the function for Function::call. |
| Change a script while the app runs | Keep the old functions until the edit installs successfully. See the hot reload example. |
| Show where a script failed | Give the script a name with Chunk::source_name and display Error::report. |
| Run Luau in a browser | Follow the browser setup or build the bare WebAssembly example. |
Start with Rustia::builder for everyday scripting. Use RustiaBuilder::live
when a script needs the current time or a fresh random seed. To limit a script’s
work or memory, set RustiaBuilder::fuel or RustiaBuilder::memory_limit_bytes.
§Keeping state across script edits
Keep the running app’s state in Rust, or save the Luau values you want to carry forward and pass them to the replacement script. The embedder decides which values to keep. A newly created script local starts with its initializer.
Use Chunk::install to try the replacement, then switch to the new exports
after it succeeds. If installation fails, Rustia rolls back guest changes and
the app can keep using the previous functions. See the hot reload example.
§Rustia and other Luau projects
§Lua and Luau
- Lua provides functions, tables for storing data, and coroutines that can pause and resume.
- Luau adds shortcuts like
score += 1,continuein loops, and optional type annotations. Rustia runs annotated scripts without a static type check.
Rustia targets standalone Luau 0.709, including its vector and buffer libraries. Roblox services are outside that scope. Tested language features
§What Rustia adds
- Replay on desktop and in a browser. In deterministic mode, the same script, seed, and inputs produce the same decisions. Watch the native and Wasm race
- Keep running through a bad edit. Try a new module while the app runs. If installation fails, Rustia restores the previous script state and your app can keep calling the old functions. Hot reload example
- Give each decision a budget. Limit the work a script can do and the memory Rustia tracks for it. A script can queue changes for Rust and deliver them only when the call succeeds. Runnable example
§Compare Luau projects
All seven compile Luau to bytecode. ulua, mlua and Lune also offer a native JIT. For source-to-source transpilation or bundling, see darklua.
| Project | Engine | Desktop | Browser Wasm | Hot reload | Replay |
|---|---|---|---|---|---|
| Rustia | Rust | Demo | Rollback | ✓ Tested | |
| luaur | Rust | Playground | Replace module | — | |
| ulua | Rust | Playground | Replace module | — | |
| ruau | Rust | — | Reload module | ◐ Controls | |
| luau-rs/luau | Rust | CI tests | Run code | — | |
| mlua | Upstream Luau (C++) | Build | Replace module | — | |
| Lune | Upstream Luau (C++) | — | Load script | — |
Desktop shows platforms listed in CI, release builds or recorded runs. Linux ·
macOS ·
Windows. Rustia also runs on ARM64 iOS and Android. [1]
Replay means the same script and inputs produce the same result across targets in a reproducible configuration. ✓ Tested means matching native and browser results. ◐ Controls means the host can fix the seeds and clock. A dash means the sources below did not establish that capability.
Sources and details · Checked 20 November 2026.
- Rustia restores the previous script state when a module install fails. Its deterministic mode reproduces the native run in a browser. ARM64 mobile tests passed on a physical iPad and an Android 15 emulator, with a browser run in iPad Safari. Compiler · Hot reload · Native/Wasm replay · Desktop · Mobile · Safari
- luaur 0.1.8 is a Rust port. The host can replace a registered module in the same VM. Native JIT execution is outside this version’s scope. Project · Code generation · Desktop CI · Module API
- ulua 0.1.7 forks luaur and adds an opt-in native JIT. The host can replace a registered module in the same VM. Project · JIT · Desktop CI · Module API
- ruau 0.3.0 lets the host unload modules and fix the clock, hash seed and random seed. Its docs describe a Wasm clock. Cross-target replay and browser execution are unverified. Project · Linux run · Wasm clock · Module API · Seed controls
- luau-rs/luau runs new chunks in the same VM and tests browser execution. Native code generation is in development. Project · Embedding API · Browser CI
- mlua binds Rust to upstream C++ Luau and also supports Lua. The host can replace a registered module. CI builds for Emscripten. Bare Wasm needs WASI imports and Wasm exceptions. Project · JIT · Emscripten · Bare Wasm · Module API
- Lune 0.11.1 uses mlua. It can load an edited script or bundle its VM and bytecode into a standalone executable. Project · Executable · Desktop releases · Script loading
§Performance
The chart compares five workloads on Linux x86-64. Each language has its own version. Roto’s array workload uses a handwritten quadratic sort. It uses a list for sparse lookups and an ordinary function for the closure test. Compare times within a column. Lower is better. The upstream C++ Luau interpreter ran all five faster than Rustia in this run.
These October 2026 measurements cover scripts already running. Small timing differences may vary between runs. Full results · Benchmark limitations
§More about embedding
Read a Luau table from Rust
Use Chunk::eval to copy a value into Rust, or Chunk::eval_serde to read a
table into a Rust struct. These copies stay usable after the interpreter is gone.
Copying strings into a Rust String requires UTF-8. Tables with cycles cannot
be copied, and copying the same table twice makes two independent values.
Use Chunk::eval_live to keep a table with shared references, cycles, or
binary strings in Luau. A live Value, Table, Function, or Exports
belongs to one interpreter. Resetting it with Rustia::reset_decision invalidates
those handles. See the live values example for a table that refers to itself.
Give scripts access to Rust functions and objects
Use Rustia::add_fn for a calculation such as double. Rustia trusts that
the function only uses its inputs. In the standard and live environments,
scripts can change a Rust object immediately. See the mutable object example.
If a callback needs data borrowed for just one request or frame, pass it in a
HostContext with Rustia::invoke. The typed invocation example shows how.
For deterministic replay, let scripts propose changes for Rust to apply
after a successful call. See the game object example. HostFunction documents callback permissions
and the rules for data captured by a closure.
Keep using the interpreter after a script fails
| What you ran | What happens when an error reaches Rust |
|---|---|
A script or function with Chunk::eval, Chunk::exec, or Function::call | Changes the script already made stay in the interpreter, even if converting the result to Rust failed. |
A replacement module with Chunk::install | Rustia restores the previous script state. You can keep calling the old functions. |
A call with Rustia::invoke or Rustia::invoke_into | Rust receives none of the changes the script queued for it. Changes made in Luau still survive, except those rolled back by Invocation::install. |
A stateless decision with Rustia::invoke_entry_into | Rustia discards the queued changes and resets the script state. It also resets after success. Rust can reuse the CompiledEntry for the next call. See the stateless decision example. |
A Luau pcall can catch a script error. If the outer invocation succeeds, it
can still deliver changes queued by earlier successful callbacks. Resetting
the interpreter clears its script state and releases the Rust objects it holds.
Files a callback wrote and changes it made to your application’s state persist.
An ordinary script error lets you keep using the interpreter. If Rustia catches
a panic in a Rust callback, call Rustia::reset_decision before running more
Luau. For exhausted limits, VmError::kind identifies the resource.
For more, browse the Rust examples or read about moving an idle interpreter to another thread.
Macros§
Structs§
- Chunk
- Luau source prepared for one execution or module installation.
- Compile
Error - Parsed source that cannot be compiled.
- Compiled
Entry - Precompiled top-level decision body for allocation-light repeated
invocation through
Invocation::call_entry. - Compiled
Module - A compiled script ready for
Rustia::install. - Diagnostic
- Source details and call frames that remain available after reset or drop.
- Diagnostic
Frame - A script call frame captured before execution state is discarded.
- Diagnostic
Limits - Host-side reporting budgets, separate from script fuel and memory limits.
- Diagnostic
Span - A half-open byte range in the exact input source.
- Effects
- Lets a callback stage actions or events for the application.
- Error
- A script, conversion, or host failure with optional source diagnostics.
- Error
Report - An error formatted with source context and a call trace when available.
- Exports
- The live value returned by a successfully installed script.
- Function
- A live script or Rust function kept alive by a Rust handle.
- Host
Function - A Rust callback and its declared capabilities and fuel cost.
- Host
Module - A group of Rust callbacks installed under one script name.
- HostMut
- Lets a callback change application state immediately.
- Input
- Read-only access to an invocation’s deterministic input.
- Invocation
- Runs scripts while borrowing the application’s current host context.
- Invocation
Chunk - A borrowed source chunk executed through a typed
Invocation. - Invocation
Limits - Fuel and output limits shared by calls within one invocation.
- Invocation
Outcome - The return value, output records, and resource usage of a successful invocation.
- Invocation
Receipt - The result and usage after an invocation appends its records to your vector.
- Invocation
Usage - Resources consumed by one successful invocation.
- LexError
- A failure while reading a source token.
- Module
Source - Host-supplied source returned by a
ServiceModuleResolver. - NewObject
- A fresh Rust payload returned by a synchronous callback.
- Object
- A live, type-checked handle to a Rust object in one VM and decision epoch.
- Object
Type - A Rust type and the methods scripts may call on it.
- Owned
Table - A Rust-owned table, split into sequence values and keyed entries.
- Parse
Error - A failure while parsing a script.
- Rustia
- Owns one Luau interpreter and the Rust functions installed in it.
- Rustia
Builder - Chooses a script environment, resource limits, and host services.
- Rustia
Execution Profile - Stable, typed description of the core profile and guest surface selected by a builder.
- Rustia
Extension - A group of Rust callbacks installed together, optionally in a named table.
- Rustia
Host Fuel Policy - Public host-function fuel policy for extension metadata.
- Rustia
Host Function Info - Public pre-install metadata for a registered host function.
- Serde
Value Error - A serialization or deserialization failure while converting script data.
- Service
Clock - A clock supplied to
RustiaBuilder::wall_clockorRustiaBuilder::monotonic_clock. - Service
Entropy - Host entropy used to select the VM’s initial
math.randomsequence. - Service
Module Resolver - Host-owned resolver for script-visible
require. - Settings
- An immutable description of a builder’s or interpreter’s configuration.
- Slot
Writes - Lets a callback stage changes to saved application state.
- Slots
- Read-only access to saved application state, or “slots”.
- Source
Location - The source label and one-based line number attached to an error.
- Source
Map - Keeps error locations aligned with input when a console adds wrapper text.
- Source
Snapshot - A retained copy of the exact source used for an error report.
- Source
Span - A half-open byte range in the source,
start..end. - Table
- A live table that Rust and Luau can both read and change.
- Unclosed
Block - A source construct missing its closing keyword.
- Value
- A script value kept alive in its original Rustia VM.
- VmError
- A script execution, resource-limit, or live-handle failure.
- VmError
Message - A runtime error’s original message, without a source-location prefix.
- VmMemory
Stats - A sample of VM-owned script memory, measured in bytes.
Enums§
- Diagnostic
Reason - Facts captured by a failing script operation.
- Error
Kind - The original failure category. Match this instead of parsing error text.
- Guest
Surface - The script environment selected by an execution preset.
- OpCapability
- A Rust callback’s declared access to application state and effects.
- Owned
Key - A key supported by an
OwnedTable. - Owned
Value - A Rust-owned copy of a script value.
- Profile
- Selects language compatibility and the allowed host capabilities.
- Service
Determinism - A host provider’s declared reproducibility contract.
- Source
Error - Source text that could not be tokenized or parsed.
- Value
Type - The Luau type of a live
Value. - VmError
Kind - The category of a runtime failure.
Constants§
- RUSTIA_
DECISION_ RESET_ ABI_ VERSION - Version of the decision-reset lifecycle contract.
- RUSTIA_
DEFAULT_ HOST_ FUNCTION_ FUEL - Default fuel cost assigned by capability-specific host-function helpers.
- RUSTIA_
HARDENED_ LEAF_ GUEST_ ABI_ VERSION - Version of the hardened-leaf guest environment contract.
- RUSTIA_
HOST_ FUEL_ ABI_ VERSION - Version for the public host-function fuel-cost schedule.
- RUSTIA_
HOST_ FUEL_ POLICY - The fuel policy used by extension registration helpers.
- RUSTIA_
INSTALL_ TRANSACTION_ ABI_ VERSION - Version of installation rollback and publication behavior.
- RUSTIA_
MIN_ HOST_ FUNCTION_ FUEL - Minimum accepted host-function fuel cost.
- RUSTIA_
MODULE_ RESOLUTION_ ABI_ VERSION - Version of module resolution, suspension, and cache behavior.
Traits§
- From
Host Argument - An owned or live argument accepted by Rustia’s built-in callback adapters.
- From
Rustia - Converts an owned script value to a Rust value.
- From
Rustia Multi - Converts a script’s return values to a Rust value or tuple.
- Host
Context - Supplies the actual host data used by one Rustia invocation.
- Host
Schema - Defines the kinds of data Rustia can exchange with your application.
- Into
Effect Function - A callback accepted by
crate::HostFunction::effect. - Into
Effect Object Method - An object method that stages effects in the invocation’s existing journal.
- Into
External Function - A callback accepted by
crate::HostFunction::externalorcrate::HostFunction::nondeterministic. - Into
External MutObject Method - A method that may change its payload and external application state immediately.
- Into
External Object Method - An object method with immediate access to external application state.
- Into
Host Function - A synchronous Rust callback accepted by
crate::HostFunction. - Into
Host Function Definition - A plain callback or configured
HostFunctionaccepted by Rustia. - Into
Host Return - A complete return value accepted by Rustia’s built-in callback adapters.
- Into
Host Value - One callback result supported by Rustia’s built-in callback adapters.
- Into
Input Function - A callback accepted by
crate::HostFunction::input. - Into
Input Object Method - A read-only object method that borrows the current invocation’s input.
- Into
MutObject Method - An immediately mutable Rust-object method accepted by
crate::ObjectType. - Into
Object Iterator - A typed generalized-iterator step accepted by
crate::ObjectType. - Into
Object Method - A read-only Rust-object method accepted by
crate::ObjectType. - Into
Rustia - Converts a Rust value to an owned script value.
- Into
Rustia Multi - Converts function arguments or results to a list of script values.
- Into
Slot Read Function - A callback accepted by
crate::HostFunction::slot_read. - Into
Slot Read Object Method - A read-only object method that borrows the invocation’s saved slot snapshot.
- Into
Slot Write Function - A callback accepted by
crate::HostFunction::slot_write. - Into
Slot Write Object Method - An object method that stages slot writes in the invocation’s existing journal.