Skip to main content

Crate rustia

Crate rustia 

Source
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 backChunk::exec runs it. Chunk::eval returns a Rust value.
Pass data from Rust to LuauRustia::insert_global sets a named value. Rustia::insert_serde passes a struct or collection.
Call a Luau function from RustChunk::install loads its module. Exports::function looks up the function for Function::call.
Change a script while the app runsKeep the old functions until the edit installs successfully. See the hot reload example.
Show where a script failedGive the script a name with Chunk::source_name and display Error::report.
Run Luau in a browserFollow 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, continue in 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.

ProjectEngineDesktopBrowser WasmHot reloadReplay
RustiaRustLinux macOS Windows [1]DemoRollback✓ Tested
luaurRustLinux macOS Windows [2]PlaygroundReplace module—
uluaRustLinux macOS Windows [3]PlaygroundReplace module—
ruauRustLinux [4]—Reload module◐ Controls
luau-rs/luauRustLinux [5]CI testsRun code—
mluaUpstream Luau (C++)Linux macOS Windows [6]BuildReplace module—
LuneUpstream Luau (C++)Linux macOS Windows [7]—Load script—

Desktop shows platforms listed in CI, release builds or recorded runs. Linux Linux · macOS macOS · Windows 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.

  1. 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
  2. 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
  3. 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
  4. 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
  5. 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
  6. 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
  7. 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.

Time per work unit in microseconds ci-bench · Linux x86-64 · 2026-10-22 UTC · 9b12a5a. Best observed steady-state times, lower is better. Workloads in order: Build, sum, and sort a 256-item array, Fill and read 128 hash entries, One closure call updating a captured value, Custom, keyed, and array iteration pass, Math library calls and buffered appends. Roto searches a list for sparse lookups and calls a regular function for the state update. Rustia, Interpreter: 51.657, 87.555, 0.197, 14.035, 1.421. luaur, Interpreter: 18.395, 20.192, 0.053, 3.162, 0.197. ruau, Interpreter: 72.827, 88.879, 0.307, 17.020, 1.320. Luau (C++) via mlua, Interpreter: 18.919, 22.485, 0.051, 4.170, 0.237. Luau (C++) via mlua, JIT: 18.924, 18.745, 0.022, 3.346, 0.237. Koto, Interpreter: 262.217, 146.082, 0.346, 7.391, 1.536. Rhai, Interpreter: 313.191, 348.085, 1.478, 9.566, 3.174. Roto, Native compiled: 3,329.076, 147.728, 0.009, 3.252, 0.280. Time per work unit Best observed steady-state time in microseconds (µs). Lower is better. Engine Mode Array sort 256 items Sparse lookup 128 keys State update one call Iteration custom + tables Math + table calls + appends Rustia Interpreter 51.657 87.555 0.197 14.035 1.421 luaur Interpreter 18.395 20.192 0.053 3.162 0.197 ruau Interpreter 72.827 88.879 0.307 17.020 1.320 Luau (C++) via mlua Interpreter 18.919 22.485 0.051 4.170 0.237 Luau (C++) via mlua JIT 18.924 18.745 0.022 3.346 0.237 Koto Interpreter 262.217 146.082 0.346 7.391 1.536 Rhai Interpreter 313.191 348.085 1.478 9.566 3.174 Roto Native compiled 3,329.076 147.728 0.009 3.252 0.280 Darker cells mark shorter times within each column. Roto searches a list for sparse lookups and calls a regular function for the state update. ci-bench · Linux x86-64 · 2026-10-22 UTC · 9b12a5a

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 ranWhat happens when an error reaches Rust
A script or function with Chunk::eval, Chunk::exec, or Function::callChanges the script already made stay in the interpreter, even if converting the result to Rust failed.
A replacement module with Chunk::installRustia restores the previous script state. You can keep calling the old functions.
A call with Rustia::invoke or Rustia::invoke_intoRust 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_intoRustia 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§

rustia_extension

Structs§

Chunk
Luau source prepared for one execution or module installation.
CompileError
Parsed source that cannot be compiled.
CompiledEntry
Precompiled top-level decision body for allocation-light repeated invocation through Invocation::call_entry.
CompiledModule
A compiled script ready for Rustia::install.
Diagnostic
Source details and call frames that remain available after reset or drop.
DiagnosticFrame
A script call frame captured before execution state is discarded.
DiagnosticLimits
Host-side reporting budgets, separate from script fuel and memory limits.
DiagnosticSpan
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.
ErrorReport
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.
HostFunction
A Rust callback and its declared capabilities and fuel cost.
HostModule
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.
InvocationChunk
A borrowed source chunk executed through a typed Invocation.
InvocationLimits
Fuel and output limits shared by calls within one invocation.
InvocationOutcome
The return value, output records, and resource usage of a successful invocation.
InvocationReceipt
The result and usage after an invocation appends its records to your vector.
InvocationUsage
Resources consumed by one successful invocation.
LexError
A failure while reading a source token.
ModuleSource
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.
ObjectType
A Rust type and the methods scripts may call on it.
OwnedTable
A Rust-owned table, split into sequence values and keyed entries.
ParseError
A failure while parsing a script.
Rustia
Owns one Luau interpreter and the Rust functions installed in it.
RustiaBuilder
Chooses a script environment, resource limits, and host services.
RustiaExecutionProfile
Stable, typed description of the core profile and guest surface selected by a builder.
RustiaExtension
A group of Rust callbacks installed together, optionally in a named table.
RustiaHostFuelPolicy
Public host-function fuel policy for extension metadata.
RustiaHostFunctionInfo
Public pre-install metadata for a registered host function.
SerdeValueError
A serialization or deserialization failure while converting script data.
ServiceClock
A clock supplied to RustiaBuilder::wall_clock or RustiaBuilder::monotonic_clock.
ServiceEntropy
Host entropy used to select the VM’s initial math.random sequence.
ServiceModuleResolver
Host-owned resolver for script-visible require.
Settings
An immutable description of a builder’s or interpreter’s configuration.
SlotWrites
Lets a callback stage changes to saved application state.
Slots
Read-only access to saved application state, or “slots”.
SourceLocation
The source label and one-based line number attached to an error.
SourceMap
Keeps error locations aligned with input when a console adds wrapper text.
SourceSnapshot
A retained copy of the exact source used for an error report.
SourceSpan
A half-open byte range in the source, start..end.
Table
A live table that Rust and Luau can both read and change.
UnclosedBlock
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.
VmErrorMessage
A runtime error’s original message, without a source-location prefix.
VmMemoryStats
A sample of VM-owned script memory, measured in bytes.

Enums§

DiagnosticReason
Facts captured by a failing script operation.
ErrorKind
The original failure category. Match this instead of parsing error text.
GuestSurface
The script environment selected by an execution preset.
OpCapability
A Rust callback’s declared access to application state and effects.
OwnedKey
A key supported by an OwnedTable.
OwnedValue
A Rust-owned copy of a script value.
Profile
Selects language compatibility and the allowed host capabilities.
ServiceDeterminism
A host provider’s declared reproducibility contract.
SourceError
Source text that could not be tokenized or parsed.
ValueType
The Luau type of a live Value.
VmErrorKind
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§

FromHostArgument
An owned or live argument accepted by Rustia’s built-in callback adapters.
FromRustia
Converts an owned script value to a Rust value.
FromRustiaMulti
Converts a script’s return values to a Rust value or tuple.
HostContext
Supplies the actual host data used by one Rustia invocation.
HostSchema
Defines the kinds of data Rustia can exchange with your application.
IntoEffectFunction
A callback accepted by crate::HostFunction::effect.
IntoEffectObjectMethod
An object method that stages effects in the invocation’s existing journal.
IntoExternalFunction
A callback accepted by crate::HostFunction::external or crate::HostFunction::nondeterministic.
IntoExternalMutObjectMethod
A method that may change its payload and external application state immediately.
IntoExternalObjectMethod
An object method with immediate access to external application state.
IntoHostFunction
A synchronous Rust callback accepted by crate::HostFunction.
IntoHostFunctionDefinition
A plain callback or configured HostFunction accepted by Rustia.
IntoHostReturn
A complete return value accepted by Rustia’s built-in callback adapters.
IntoHostValue
One callback result supported by Rustia’s built-in callback adapters.
IntoInputFunction
A callback accepted by crate::HostFunction::input.
IntoInputObjectMethod
A read-only object method that borrows the current invocation’s input.
IntoMutObjectMethod
An immediately mutable Rust-object method accepted by crate::ObjectType.
IntoObjectIterator
A typed generalized-iterator step accepted by crate::ObjectType.
IntoObjectMethod
A read-only Rust-object method accepted by crate::ObjectType.
IntoRustia
Converts a Rust value to an owned script value.
IntoRustiaMulti
Converts function arguments or results to a list of script values.
IntoSlotReadFunction
A callback accepted by crate::HostFunction::slot_read.
IntoSlotReadObjectMethod
A read-only object method that borrows the invocation’s saved slot snapshot.
IntoSlotWriteFunction
A callback accepted by crate::HostFunction::slot_write.
IntoSlotWriteObjectMethod
An object method that stages slot writes in the invocation’s existing journal.

Type Aliases§

Result
A value returned by Rustia, or a script, conversion, or embedding Error.