Skip to main content

Module state

Module state 

Source
Expand description

The Lua handle and the shared inner state.

§Lifetime model (mirrors mlua’s Rc<inner> + registry-key design)

Lua owns the *mut lua_State. The state is wrapped in an [Rc] ([LuaInner]) so that long-lived handles (Table, Function, LuaString, the corresponding Value variants, userdata) can hold a clone of that Rc and keep the state alive for as long as they exist.

Each such handle additionally holds a registry reference obtained via lua_ref (luaur’s lua_ref/lua_unref). That keeps the underlying Lua value reachable by the GC, and lets the handle re-push the value onto the stack on demand. On Drop the handle releases its registry slot with lua_unref — but only if the state is still alive (the Rc keeps it so).

Lua is single-threaded (Rc, so !Send/!Sync), matching mlua’s non-Send default.

§The send feature

Under the send feature (mirroring mlua) the shared interior uses [XRc] = Arc instead of Rc, and [LuaInner] / [LuaRef] carry a documented unsafe impl Send. That makes Lua and every handle Send so the whole VM can be moved to another thread. It is not made Sync: the VM is still single-threaded, the user must serialize all access, and only the ownership transfer crosses threads (exactly mlua’s send contract).

Structs§

GcGenParams
Parameters for a generational GC, mirroring mlua::state::GcGenParams.
GcIncParams
Parameters for Luau’s incremental GC, mirroring mlua::state::GcIncParams.
Lua
A handle to a Lua interpreter.
WeakLua
A weak handle to a Lua instance. Mirrors mlua::WeakLua.

Enums§

GcMode
The GC operating mode, mirroring mlua::state::GcMode.