pub struct Lua(/* private fields */);Expand description
mlua-style front door for embedders. Wraps a Vm with JIT
installed by default (Vm::new_minimal_with_jit).
Implementations§
Source§impl Lua
impl Lua
Sourcepub fn with_version(v: LuaVersion) -> Lua
pub fn with_version(v: LuaVersion) -> Lua
Pick a specific dialect (5.1-5.5).
Sourcepub fn sandbox(v: LuaVersion) -> LuaSandboxBuilder
pub fn sandbox(v: LuaVersion) -> LuaSandboxBuilder
Sandbox-mode builder — same as Vm::sandbox but doesn’t
install JIT by default. .build_lua() finalizes to a Lua
wrapping the sandboxed Vm.
Sourcepub fn vm(&mut self) -> &mut Vm
pub fn vm(&mut self) -> &mut Vm
Borrow the underlying Vm for direct access (escape hatch
for cases the facade doesn’t cover).
Sourcepub fn open_string(&mut self)
pub fn open_string(&mut self)
Open the string library.
Sourcepub fn open_table(&mut self)
pub fn open_table(&mut self)
Open the table library.
Sourcepub fn open_coroutine(&mut self)
pub fn open_coroutine(&mut self)
Open the coroutine library.
Sourcepub fn eval<T: FromLuaValue>(&mut self, src: &str) -> Result<T, LuaError>
pub fn eval<T: FromLuaValue>(&mut self, src: &str) -> Result<T, LuaError>
Compile and run src; extract the first return value as T.
Use Lua::eval_multi to retrieve all returns.
Sourcepub fn eval_multi(&mut self, src: &str) -> Result<Vec<Value>, LuaError>
pub fn eval_multi(&mut self, src: &str) -> Result<Vec<Value>, LuaError>
Compile and run src; return all results.
Sourcepub async fn eval_async<T: FromLuaValue>(
&mut self,
src: &str,
) -> Result<T, LuaError>
pub async fn eval_async<T: FromLuaValue>( &mut self, src: &str, ) -> Result<T, LuaError>
Async variant of Lua::eval. Returns an !Send future that
drives the dispatcher with cooperative yields on instruction
budget exhaustion. Pin this to a current_thread Tokio
runtime (or a LocalSet inside multi-thread Tokio) — see
docs/threading.md and examples/async_host.rs.
Sourcepub async fn eval_async_multi(
&mut self,
src: &str,
) -> Result<Vec<Value>, LuaError>
pub async fn eval_async_multi( &mut self, src: &str, ) -> Result<Vec<Value>, LuaError>
Async variant of Lua::eval_multi.
Sourcepub fn set_async_native(
&mut self,
name: &str,
f: AsyncNativeFn,
) -> Result<(), LuaError>
pub fn set_async_native( &mut self, name: &str, f: AsyncNativeFn, ) -> Result<(), LuaError>
Register an async native function callable from Lua. The
raw fn pointer ABI takes (*mut Vm, func_slot, nargs) and
returns a boxed future — see luna_core::vm::AsyncNativeFn
for the safety contract.
Calling an async native from inside vm.eval() (sync mode)
errors with a typed LuaError; embedders must drive the call
through eval_async.
Sourcepub fn set_global<V: IntoValue>(
&mut self,
name: &str,
v: V,
) -> Result<(), LuaError>
pub fn set_global<V: IntoValue>( &mut self, name: &str, v: V, ) -> Result<(), LuaError>
Set a global by name. Accepts any IntoValue including
LuaFunction / LuaTable / LuaRoot (the handle types impl
IntoValue so they fan in alongside primitives + Value).
Sourcepub fn create_table(&mut self) -> LuaTable
pub fn create_table(&mut self) -> LuaTable
Allocate a fresh empty table; return a handle that keeps it alive.
Sourcepub fn create_function<F, Marker>(&mut self, f: F) -> LuaFunctionwhere
F: NativeTypedSig<Marker>,
pub fn create_function<F, Marker>(&mut self, f: F) -> LuaFunctionwhere
F: NativeTypedSig<Marker>,
Wrap a typed Rust function as a Lua callable. See
Vm::native_typed for the supported callable shapes.
Sourcepub fn pin<V: IntoValue>(&mut self, v: V) -> LuaRoot
pub fn pin<V: IntoValue>(&mut self, v: V) -> LuaRoot
Pin an arbitrary value as a host root; the returned LuaRoot
keeps it alive until Lua::unpin or Lua::unpin_all.
Sourcepub fn unpin<H: PinnedHandle>(&mut self, h: H) -> Result<(), HostRootStale>
pub fn unpin<H: PinnedHandle>(&mut self, h: H) -> Result<(), HostRootStale>
Release a single pinned handle (v1.3 Phase SR). The handle’s
slot is recycled; the supplied LuaFunction / LuaTable /
LuaRoot value (and any Copy-cloned aliases) becomes stale
and will panic on subsequent reads / calls.
Returns Err(HostRootStale) if the handle was already
released — pool is unchanged in that case, so embedders can
safely ignore the error if double-unpin is acceptable.
Sourcepub fn unpin_all(&mut self)
pub fn unpin_all(&mut self)
Drop every pinned handle. LuaFunction / LuaTable /
LuaRoot created before this call become invalid (panic on
use). Bumps every slot’s generation; underlying Vec capacity
is retained for amortized future allocations.
Sourcepub fn pinned_count(&self) -> usize
pub fn pinned_count(&self) -> usize
Number of currently-pinned handles (diagnostic). v1.3 Phase
SR: counts live (non-free) slots, so a steady pin → unpin
loop holds at 1 instead of growing monotonically.