Skip to main content

Crate luaur_rt

Crate luaur_rt 

Source
Expand description

§luaur-rt

A safe, ergonomic, mlua-style high-level API for luaur — a pure-Rust translation of Roblox’s Luau.

The public surface deliberately mirrors mlua’s interface — the same type names (Lua, Value, Table, Function, LuaString, MultiValue, Variadic, Error), the same method names and call shapes (Lua::new, lua.globals(), lua.create_function, lua.load(src).eval::<T>(), table.set/get, function.call::<R>(args)), and the same conversion traits (FromLua, IntoLua, FromLuaMulti, IntoLuaMulti) and userdata traits (UserData, UserDataMethods). The implementation, however, is entirely original: it is written directly over luaur’s pure-Rust C API (lua_*), not over a C FFI.

use luaur_rt::prelude::*;

let lua = Lua::new();
let add = lua
    .create_function(|_, (a, b): (i64, i64)| Ok(a + b))
    .unwrap();
lua.globals().set("add", add).unwrap();
let sum: i64 = lua.load("return add(2, 3)").eval().unwrap();
assert_eq!(sum, 5);

§Single-threaded

Like mlua’s default, Lua is single-threaded: it is built on Rc, so it is neither Send nor Sync. Clone a Lua to get another handle to the same VM.

§Deferred (not yet implemented)

The following parts of mlua’s surface are intentionally out of scope and are noted here rather than implemented:

  • Multi-VM Send/Sync (WeakLua, send-able handles) (P4).
  • Thread event callbacks (ThreadEvent/ThreadTriggers/ set_thread_event_callback) and per-thread hooks.
  • The chunk! proc-macro.
  • Async userdata methods (add_async_method*) and the ObjectLike call_async_method surface (depend on the deferred userdata registry).

Implemented in Phase 1: Thread/coroutine wrappers, public RegistryKey storage, UserDataFields, typed AnyUserData::borrow/borrow_mut/take/ is, the MetaMethod enum, and Function::info/environment.

Implemented in Phase 2: the Luau-specific runtime types Buffer (the buffer type) and Vector (the vector type), with their Value::Buffer/Value::Vector variants and FromLua/IntoLua impls.

Implemented in Phase 4a (behind the serde cargo feature): serde (de)serialization between Rust types and Lua Values — the LuaSerdeExt trait on Lua, a serde Serializer/Deserializer over Value/ Table, SerializeOptions/DeserializeOptions, and Serialize impls for Value/Table with the Value::to_serializable wrapper.

Implemented in Phase 4c (behind the async cargo feature): Rust async/ await support — the Rust-Future ⟷ Lua-coroutine bridge. Lua::create_async_function / Lua::yield_with, Function::call_async / Function::wrap_async / Function::wrap_raw_async, Chunk::call_async / Chunk::exec_async / Chunk::eval_async, and Thread::into_async producing an AsyncThread that implements Future + Stream. Executor-agnostic, like mlua: the caller drives the returned futures on their own runtime.

Re-exports§

pub use state::Lua;
pub use state::WeakLua;
pub use value::Value::Nil;

Modules§

ffi
The public, mlua-style ffi surface (mounted from ffi_public.rs). The public, mlua-style raw C API surface (re-exported at luaur_rt::ffi).
prelude
Idiomatic glob-import prelude. Mirrors mlua::prelude, additionally re-exporting the short names so use luaur_rt::prelude::*; brings the whole ergonomic surface into scope.
state
The Lua handle and the shared inner state.

Structs§

AnyUserData
A handle to an arbitrary Lua userdata value.
AppDataRef
An immutable borrow of an application-data value of type T. Mirrors mlua::AppDataRef.
AppDataRefMut
A mutable borrow of an application-data value of type T. Mirrors mlua::AppDataRefMut.
Buffer
A Luau buffer type.
Chunk
A not-yet-executed piece of Lua source.
Compiler
Luau bytecode compiler options, mirroring mlua::Compiler.
Debug
A snapshot of one activation record, resolved from a stack level via lua_getinfo. Mirrors the informational subset of mlua::debug::Debug.
Function
A handle to a callable Lua value (a Lua closure or a Rust function).
FunctionInfo
Debug information about a Function. Mirrors mlua::debug::FunctionInfo (the subset Luau reports).
LightUserData
A Lua light userdata: an opaque raw pointer value. Mirrors mlua::LightUserData.
LuaOptions
Per-VM behavioral options. Mirrors mlua::LuaOptions.
LuaString
A garbage-collected Lua string.
MultiValue
An ordered, growable sequence of Lua values, used to represent the multiple arguments / multiple return values that Lua functions can take and produce.
RegistryKey
An owned reference to a value stored in the Lua registry.
Scope
A scope for creating lifetime-bounded Lua callbacks and userdata.
StdLib
A bit-set selecting which standard libraries to open. Mirrors mlua::StdLib.
Table
A handle to a Lua table.
TablePairs
Iterator over a table’s key/value pairs (see Table::pairs).
TableSequence
Iterator over a table’s sequence part (see Table::sequence_values).
Thread
A handle to a Lua thread (coroutine). Mirrors mlua::Thread.
UserDataRef
A RAII guard for an immutable userdata borrow (AnyUserData::borrow). Mirrors mlua::UserDataRef.
UserDataRefMut
A RAII guard for a mutable userdata borrow (AnyUserData::borrow_mut). Mirrors mlua::UserDataRefMut.
Variadic
A wrapper collecting “the rest of” a Lua argument list (or producing a variable number of return values).
Vector
A Luau vector type.

Enums§

ChunkMode
How a chunk’s bytes are interpreted. Mirrors mlua::ChunkMode. luaur-rt always loads text source, so this exists for signature parity with Chunk::set_mode.
DebugWhat
What kind of function an activation record refers to. Mirrors the relevant part of mlua::debug::DebugSource::what.
Error
Errors that can occur when interacting with the Lua engine.
MetaMethod
Kinds of metamethods that can be overridden on userdata.
ThreadStatus
Status of a Lua thread (coroutine). Mirrors mlua::ThreadStatus.
Value
A dynamically typed Lua value.
VmState
The action an interrupt callback asks the VM to take. Mirrors mlua::VmState.

Traits§

ExternalError
Convenience for turning an arbitrary error/displayable into an Error.
ExternalResult
Result extension mirroring mlua::ExternalResult: lift any Result<T, E> into a luaur Result by converting the error.
FromLua
Convert a single Lua Value into a Rust value.
FromLuaMulti
Convert a sequence of Lua values into a Rust value.
IntoLua
Convert a Rust value into a single Lua Value.
IntoLuaMulti
Convert a Rust value into a sequence of Lua values (multiple returns / args).
LuaNativeFn
A function/closure callable with a tuple of FromLuaMulti arguments, abstracting over arity. Mirrors mlua::LuaNativeFn. Lets Function::wrap accept ||, |a|, |a, b|, … closures uniformly (the closure receives the converted args directly, not the Lua).
MaybeSend
See the send-gated variant above.
MaybeSync
See the send-gated variant above.
TypeMetatable
Luau built-in types that have a shared, per-type metatable settable via Lua::set_type_metatable. Mirrors mlua’s sealed LuauType trait.
UserData
A Rust type that can be exposed to Lua as userdata.
UserDataFields
Registrar passed to UserData::add_fields.
UserDataMethods
Registrar passed to UserData::add_methods.

Type Aliases§

Integer
The integer type exposed by the API. Mirrors mlua::Integer (i64).
Number
The float type exposed by the API. Mirrors mlua::Number (f64).
Result
The result type used throughout luaur-rt, mirroring [mlua::Result].
lua_State
A raw lua_State pointer type alias, re-exported at the crate root for signature parity with mlua::lua_State.