rustia 0.2.0

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

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.

Try the garden

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.

Deterministic builder

One interpreter on desktop and web. Rustia’s runtime crates forbid unsafe Rust and build without a C++ toolchain.

Platform comparison

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.

Cargo features in Rustdoc

Let scripts work with your app. Expose the functions and objects they need, and use Serde to read Luau tables into Rust structs.

Embedding guide

Keep runaway scripts under control. Set instruction and VM memory budgets so your app can handle a script that exceeds them.

Budget example

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.

cargo new hello-rustia
cd hello-rustia
cargo add rustia --git https://github.com/slowchop/rustia --branch main

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::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(())
}

You should see The score is 42.

  • insert_global gives Luau the starting score, and add_fn lets it call the Rust function.
  • source_name gives the script a label that appears in error messages.
  • eval gives you a value back in Rust. Use exec when 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::Rustia;

fn main() -> rustia::Result<()> {
    let mut vm = Rustia::builder().build()?;
    let exports = vm
        .load("return { greet = function(name) return 'Hello, ' .. name end }")
        .source_name("greetings.luau")
        .install()?;

    let greet = exports.function(&mut vm, "greet")?;
    let message: String = greet.call(&mut vm, ("Ada",))?;
    println!("{message}");
    assert_eq!(message, "Hello, Ada");
    Ok(())
}

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.

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-adapters is on by default. It provides system randomness and connects browser builds to JavaScript clocks, randomness, and console output. For WebAssembly without JavaScript imports, set default-features = false and give live() your own clocks and seed provider. Example without JavaScript imports

  • send makes Rustia and its live handles Send, 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.

git clone https://github.com/slowchop/rustia.git
cd rustia
cargo run --locked -p rustia --example embedding
cargo doc --locked -p rustia --no-deps --open

Browse all Rust examples

Run Luau from the command line

Run this command from the checkout to try one line of Luau.

cargo run --locked --bin rustia -- --eval "print(40 + 2)"

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.

Benchmark methodology

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.