Skip to main content

Lua

Struct Lua 

Source
pub struct Lua { /* private fields */ }
Expand description

Safe, embedding-oriented Lua runtime.

This type sits on top of luars::LuaVM and exposes a narrower API that avoids raw LuaValue plumbing in the common host-facing surface.

Implementations§

Source§

impl Lua

Source

pub fn new(option: SafeOption) -> Self

Create a new Lua runtime.

Source

pub fn open_stdlib(&mut self, lib: Stdlib) -> LuaResult<()>

Open standard libraries.

Source

pub fn install_library<L: LuaLibrary>(&mut self, library: L) -> LuaResult<()>

Install a library provided by luars or an external crate.

Source

pub fn load_stdlibs(&mut self, lib: Stdlib) -> LuaResult<()>

Open standard libraries.

Source

pub fn collect_garbage(&mut self) -> LuaResult<()>

Run a full garbage-collection cycle immediately.

Source

pub fn execute(&mut self, source: &str) -> LuaResult<()>

Execute source code and discard raw return values.

Source

pub fn eval<R: FromLua>(&mut self, source: &str) -> LuaResult<R>

Execute source code and convert the first returned value.

Source

pub fn eval_multi<R: FromLuaMulti>(&mut self, source: &str) -> LuaResult<R>

Execute source code and convert all returned values.

Source

pub async fn exec_async(&mut self, source: &str) -> LuaResult<()>

Execute source code asynchronously and discard raw return values.

Source

pub async fn eval_async<R: FromLua>(&mut self, source: &str) -> LuaResult<R>

Execute source code asynchronously and convert the first returned value.

Source

pub async fn eval_multi_async<R: FromLuaMulti>( &mut self, source: &str, ) -> LuaResult<R>

Execute source code asynchronously and convert all returned values.

Source

pub fn set_global<T: IntoLua>(&mut self, name: &str, value: T) -> LuaResult<()>

Set a global from a Rust value that converts to a single Lua value.

Source

pub fn globals(&mut self) -> Table

Return a handle to the global environment table.

Source

pub fn get_global<T: FromLua>(&mut self, name: &str) -> LuaResult<Option<T>>

Get and convert a global variable.

Source

pub fn call_global<A: IntoLua, R: FromLuaMulti>( &mut self, name: &str, args: A, ) -> LuaResult<R>

Call a global function and convert all results.

Source

pub fn call_global1<A: IntoLua, R: FromLua>( &mut self, name: &str, args: A, ) -> LuaResult<R>

Call a global function and convert the first result.

Source

pub async fn call_async<A: IntoLua, R: FromLuaMulti>( &mut self, function: &Function, args: A, ) -> LuaResult<R>

Call a function handle asynchronously and convert all results.

Source

pub async fn call_async1<A: IntoLua, R: FromLua>( &mut self, function: &Function, args: A, ) -> LuaResult<R>

Call a function handle asynchronously and convert only the first result.

Source

pub async fn call_async_global<A: IntoLua, R: FromLuaMulti>( &mut self, name: &str, args: A, ) -> LuaResult<R>

Call a global function asynchronously and convert all results.

Source

pub async fn call_async_global1<A: IntoLua, R: FromLua>( &mut self, name: &str, args: A, ) -> LuaResult<R>

Call a global function asynchronously and convert only the first result.

Source

pub fn register_function<F, Args, R>( &mut self, name: &str, f: F, ) -> LuaResult<()>
where F: LuaTypedCallback<Args, R>,

Register a typed Rust callback as a Lua global.

Source

pub fn create_function<F, Args, R>(&mut self, f: F) -> LuaResult<Function>
where F: LuaTypedCallback<Args, R>,

Create a typed Rust callback as a standalone Lua function handle.

Source

pub fn register_async_function<F, Args, R>( &mut self, name: &str, f: F, ) -> LuaResult<()>
where F: LuaTypedAsyncCallback<Args, R>,

Register a typed async Rust callback as a Lua global.

Source

pub fn register_type_of<T: LuaRegistrable>( &mut self, name: &str, ) -> LuaResult<()>

Register a userdata type in the global environment.

Source

pub fn register_type<T: LuaRegistrable>( &mut self, name: &str, ) -> LuaResult<Table>

Register a userdata type and return the exported global type table.

Source

pub fn register_enum_of<T: LuaEnum>(&mut self, name: &str) -> LuaResult<()>

Source

pub fn load<'lua>(&'lua mut self, source: &str) -> Chunk<'lua>

Return a chunk builder that can be executed, evaluated, or compiled.

Source

pub fn scope<'lua, R>( &'lua mut self, f: impl for<'scope> FnOnce(&mut Scope<'scope, 'lua>) -> LuaResult<R>, ) -> LuaResult<R>

Run a lexical scope that can create non-'static Lua callbacks and borrowed userdata.

Source

pub fn load_function(&mut self, source: &str) -> LuaResult<Function>

Compile source and return a callable function handle.

Source

pub fn create_string(&mut self, value: &str) -> LuaResult<LuaString>

Create a safe Lua string handle.

Source

pub fn create_table(&mut self) -> LuaResult<Table>

Create a new empty table handle.

Source

pub fn create_table_with_capacity( &mut self, narr: usize, nrec: usize, ) -> LuaResult<Table>

Create a new table handle with explicit capacities.

Source

pub fn create_userdata<T: UserDataTrait + 'static>( &mut self, data: T, ) -> LuaResult<UserDataRef<T>>

Create a GC-managed userdata and return a typed handle to it.

Source

pub unsafe fn create_userdata_ref<T: UserDataTrait + 'static>( &mut self, reference: &mut T, ) -> LuaResult<UserDataRef<T>>

Create a GC-managed userdata that borrows a Rust value.

§Safety

The referenced Rust value must outlive all Lua accesses to the returned userdata.

Source

pub fn create_table_from<K, V, I>(&mut self, iter: I) -> LuaResult<Table>
where K: IntoLua, V: IntoLua, I: IntoIterator<Item = (K, V)>,

Create a table and populate it from key-value pairs.

Source

pub fn create_sequence_from<T, I>(&mut self, iter: I) -> LuaResult<Table>
where T: IntoLua, I: IntoIterator<Item = T>,

Create a table from a sequence of values using 1.. as keys.

Source

pub fn get_function(&mut self, name: &str) -> LuaResult<Option<Function>>

Get a global function handle.

Source

pub fn get_table(&mut self, name: &str) -> LuaResult<Option<Table>>

Get a global table handle.

Source

pub fn set_global_table(&mut self, name: &str, table: &Table) -> LuaResult<()>

Bind a safe table handle into the global environment.

Source

pub fn set_global_function( &mut self, name: &str, function: &Function, ) -> LuaResult<()>

Bind a safe function handle into the global environment.

Source

pub fn table_set<T: IntoLua>( &mut self, table: &Table, key: &str, value: T, ) -> LuaResult<()>

Set a string-keyed table field from a Rust value.

Source

pub fn table_seti<T: IntoLua>( &mut self, table: &Table, key: i64, value: T, ) -> LuaResult<()>

Set an integer-keyed table field from a Rust value.

Source

pub fn table_get<T: FromLua>( &mut self, table: &Table, key: &str, ) -> LuaResult<T>

Get and convert a string-keyed table field.

Source

pub fn table_geti<T: FromLua>( &mut self, table: &Table, key: i64, ) -> LuaResult<T>

Get and convert an integer-keyed table field.

Source

pub fn table_push<T: IntoLua>( &mut self, table: &Table, value: T, ) -> LuaResult<()>

Append a Rust value to the array part of a table.

Source

pub fn table_pairs<K: FromLua, V: FromLua>( &mut self, table: &Table, ) -> LuaResult<Vec<(K, V)>>

Convert a table snapshot into typed key-value pairs.

Source

pub fn table_array<T: FromLua>(&mut self, table: &Table) -> LuaResult<Vec<T>>

Read the array portion of a table in order from 1..=#t.

Source

pub fn pack<T: IntoLua>(&mut self, value: T) -> LuaResult<Value>

Pack a Rust value into a safe registry-backed Lua value handle.

Source

pub fn unpack<T: FromLua>(&mut self, value: Value) -> LuaResult<T>

Unpack a safe Lua value handle into a Rust value.

Source

pub fn convert<T: IntoLua, U: FromLua>(&mut self, value: T) -> LuaResult<U>

Convert one Rust/Lua-convertible value into another.

Source

pub unsafe fn vm_mut(&mut self) -> &mut LuaVM

Get a mutable reference to the underlying LuaVM for advanced use cases.

Trait Implementations§

Source§

impl Default for Lua

Source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl Freeze for Lua

§

impl !RefUnwindSafe for Lua

§

impl !Send for Lua

§

impl !Sync for Lua

§

impl Unpin for Lua

§

impl UnsafeUnpin for Lua

§

impl !UnwindSafe 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> LuaMethodProvider for T

Source§

impl<T> LuaStaticMethodProvider for T

Source§

fn __lua_static_methods() -> &'static [(&'static str, CFunction)]

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.