luaur-rt 0.1.2

Safe, ergonomic, mlua-style API for luaur (pure-Rust Luau).
Documentation

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 [Value]s — 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.