Skip to main content

Lua

Struct Lua 

Source
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

Source

pub fn new() -> Lua

Create a Lua VM with JIT installed + Lua 5.5 dialect.

Source

pub fn with_version(v: LuaVersion) -> Lua

Pick a specific dialect (5.1-5.5).

Source

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.

Source

pub fn vm(&mut self) -> &mut Vm

Borrow the underlying Vm for direct access (escape hatch for cases the facade doesn’t cover).

Source

pub fn open_base(&mut self)

Open the base library (print, type, pcall, etc.).

Source

pub fn open_math(&mut self)

Open the math library.

Source

pub fn open_string(&mut self)

Open the string library.

Source

pub fn open_table(&mut self)

Open the table library.

Source

pub fn open_coroutine(&mut self)

Open the coroutine library.

Source

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.

Source

pub fn eval_multi(&mut self, src: &str) -> Result<Vec<Value>, LuaError>

Compile and run src; return all results.

Source

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.

Source

pub async fn eval_async_multi( &mut self, src: &str, ) -> Result<Vec<Value>, LuaError>

Async variant of Lua::eval_multi.

Source

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.

Source

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).

Source

pub fn globals(&mut self) -> LuaTable

Borrow the globals table as a LuaTable handle.

Source

pub fn create_table(&mut self) -> LuaTable

Allocate a fresh empty table; return a handle that keeps it alive.

Source

pub fn create_function<F, Marker>(&mut self, f: F) -> LuaFunction
where F: NativeTypedSig<Marker>,

Wrap a typed Rust function as a Lua callable. See Vm::native_typed for the supported callable shapes.

Source

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.

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Default for Lua

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Lua

§

impl !Send for Lua

§

impl !Sync for Lua

§

impl !UnwindSafe for Lua

§

impl Freeze for Lua

§

impl Unpin for Lua

§

impl UnsafeUnpin for Lua

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.