Skip to main content

Module lua_facade

Module lua_facade 

Source
Expand description

mlua-style Lua facade (B12, Phase 2 P2-D).

A thin wrapper around luna_core::vm::Vm that exposes the same API in a shape familiar to embedders coming from rlua / mlua:

use luna_jit::Lua;

let mut lua = Lua::new();
lua.open_base();
lua.open_math();
let r: i64 = lua.eval("return 1 + 2").unwrap();
assert_eq!(r, 3);

let add = lua.create_function(|a: i64, b: i64| -> i64 { a + b });
lua.set_global("add", add).unwrap();
let r: i64 = lua.eval("return add(40, 2)").unwrap();
assert_eq!(r, 42);

§Handles

LuaFunction / LuaTable / LuaRoot are Copy wrappers around a HostRootTicket returned by Vm::pin_host. They keep their referenced Gc<T> alive across calls (so a LuaTable survives a GC cycle even when no Lua-side reference exists).

v1.3 Phase SR added slot recycling — a single handle can be released via Lua::unpin; the whole batch via Lua::unpin_all. Both operations bump the slot’s generation, invalidating any further use of LuaFunction / LuaTable / LuaRoot Copy values that referenced the released slot (subsequent reads / calls panic on the stale ticket).

§Threading

Lua inherits Vm’s !Send + !Sync contract. See docs/threading.md for canonical embedding patterns.

Structs§

Lua
mlua-style front door for embedders. Wraps a Vm with JIT installed by default (Vm::new_minimal_with_jit).
LuaFunction
Handle to a Lua-callable value (Value::Closure or Value::Native) pinned in the host root pool. Copy-able — clones share the same HostRootTicket.
LuaRoot
Generic pinned root. Use for arbitrary Values the embedder wants to keep alive without wrapping in LuaFunction / LuaTable.
LuaSandboxBuilder
Sandbox builder that finalizes to a Lua (instead of a bare Vm).
LuaTable
Handle to a Value::Table pinned in the host root pool.

Traits§

IntoLuaArgs
Convert a tuple of typed values into the &[Value] shape Vm::call_value expects. Implemented for () + tuples of IntoValue up to arity 6.
PinnedHandle
v1.3 Phase SR — common trait for handle types that wrap a HostRootTicket. Lets Lua::unpin accept LuaFunction / LuaTable / LuaRoot uniformly.