Rustia
Rustia is a pure-Rust interpreter for embedding standalone Luau in 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.
Version note. 0.1.0 was an earlier
game-engine project I set aside. 0.2.0 is planned as the first release of this
Luau interpreter.
Run your first script or try the browser playground.
Features
Edit Luau without a rebuild. Your app keeps running and can carry state across edits, like the flowers’ positions in the garden. If a reload fails, Rustia can restore the previous script state.
Replay a run. In deterministic mode, the same script, starting state, seed, and ordered inputs produce matching results on native and WebAssembly. That helps reproduce bugs and keep lockstep multiplayer clients in sync.
One interpreter on desktop and web. Rustia’s runtime crates forbid unsafe Rust and build without a C++ toolchain.
Embed Luau without relying on built-in platform services. Your app can supply clocks and randomness, decide where print output goes, and choose how to load scripts.
Let scripts work with your app. Expose the functions and objects they need, and use Serde to read Luau tables into Rust structs.
Keep runaway scripts under control. Set instruction and VM memory budgets so your app can handle a script that exceeds them.
In development
Step back through a recorded Luau run, inspect earlier values, and find the line that last changed a variable. Follow the debugger work.
We’re building a Luau layer on top of Bevy so you can change gameplay while the game runs, without rebuilding the Rust app.
We’re exploring just-in-time (JIT) compilation in the background during development and ahead-of-time (AOT) compilation for bundled scripts. Today Rustia interprets Luau bytecode. Follow the compilation work.
We’re also having fun with a Luau synth in the browser. Write and tweak sounds live, record MIDI performances, and record audio from instruments.
Try it
You’ll need Rust 1.95 or newer. Create a small Cargo app and add Rustia from Git. If you already have an app, run the last command from its directory.
Expect API changes on main until Rustia reaches 1.0.0.
A first script
Start with a score of 21 and a Rust function called double. The Luau script calls double(base_score) and sends 42 back to Rust.
In the Cargo project you set up with Rustia, replace src/main.rs with this code and run cargo run.
use Rustia;
You should see The score is 42.
insert_globalgives Luau the starting score, andadd_fnlets it call the Rust function.source_namegives the script a label that appears in error messages.evalgives you a value back in Rust. Useexecwhen you only want to run the script.
The example keeps the script in a string so it fits in one file. Read a .luau file at runtime if you want to edit it without rebuilding the Rust app.
From a Rustia checkout, run the example with cargo run --locked -p rustia --example first_script.
Call script functions from Rust
The first script calls Rust from Luau. Here’s the other direction. Use
install
to load a script that returns a table of exports. Look up greet with
Exports::function
and call it from Rust.
Replace src/main.rs with this example and run cargo run again. The program prints Hello, Ada.
use Rustia;
If you’re reloading a script while your app runs, keep calling the old functions until the edited version installs successfully. The hot reload example shows a failed edit followed by a successful one.
Choose an environment
Start with Rustia::builder()
for everyday scripting. It starts with a fixed random seed and repeatable clocks.
- Use
RustiaBuilder::deterministic()to replay a simulation with the same inputs. - Use
RustiaBuilder::live()when a script needs the current time or a fresh random seed.
You can limit the work a script does with
fuel(100_000)
and limit the memory Rustia tracks for it with
memory_limit_bytes(2 * 1024 * 1024).
Both limits are off by default. After a memory-limit error, you can run another
script in the same interpreter. See what happens when a script fails.
Cargo features
-
platform-adaptersis on by default. It provides system randomness and connects browser builds to JavaScript clocks, randomness, and console output. For WebAssembly without JavaScript imports, setdefault-features = falseand givelive()your own clocks and seed provider. Example without JavaScript imports -
sendmakesRustiaand its live handlesSend, so you can move them together to another thread. Calls still need&mut Rustia. See thread ownership and the runnable example.From a Rustia checkout, run
cargo run --locked -p rustia --features send --example transferable.
Examples and API reference
Read the API reference online, or run the embedding example and build Rustdoc from a checkout.
- Read a Luau table into a Rust struct with Serde
- Call methods on a Rust object from Luau
- Show the line that caused a script error
- Run Rustia in a browser
- Move an idle interpreter and a retained function to another thread
Run Luau from the command line
Run this command from the checkout to try one line of Luau.
The command prints 42. To run a file, pass its path after --. For an interactive prompt, pass --repl.
Type =40 + 2 to see the result and :quit to exit.
Rustia and other Luau projects
Compare Luau projects for platform support, hot reload, and replay. The comparison notes include the sources. See tested language features for Rustia’s Luau compatibility.
Project status and source access
See which platforms have been tested and what’s left before release.
Bug reports and focused pull requests are welcome. See the contribution guide and private security reporting instructions.
License
Licensed under either Apache-2.0 or MIT, at your option.