Struct Lua

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

Implementations§

Source§

impl Lua

Source

pub fn empty() -> Self

Create a new Lua instance with no parts of the stdlib loaded.

Source

pub fn core() -> Self

Create a new Lua instance with the core stdlib loaded.

Source

pub fn full() -> Self

Create a new Lua instance with all of the stdlib loaded.

Source

pub fn load_core(&mut self)

Load the core parts of the stdlib that do not allow performing any I/O.

Calls:

  • load_base
  • load_coroutine
  • load_math
  • load_string
  • load_table
Source

pub fn load_io(&mut self)

Load the parts of the stdlib that allow I/O.

Source

pub fn total_memory(&self) -> usize

Size of all memory used by this Lua context.

This is equivalent to self.gc_metrics().total_allocation(). This counts all Gc allocated memory and also all data Lua datastructures held inside Gc, as they are tracked as “external allocations” in gc-arena.

Source

pub fn gc_collect(&mut self)

Finish the current collection cycle completely, calls gc_arena::Arena::collect_all().

Source

pub fn gc_metrics(&self) -> &Metrics

Source

pub fn enter<F, T>(&mut self, f: F) -> T
where F: for<'gc> FnOnce(Context<'gc>) -> T,

Enter the garbage collection arena and perform some operation.

In order to interact with Lua or do any useful work with Lua values, you must do so from within the garbage collection arena. All values branded with the 'gc branding lifetime must forever live inside the arena, and cannot escape it.

Garbage collection takes place in-between calls to Lua::enter, no garbage will be collected cocurrently with accessing the arena.

Automatically triggers garbage collection before returning if the allocation debt is larger than a small constant.

Source

pub fn try_enter<F, R>(&mut self, f: F) -> Result<R, StaticError>
where F: for<'gc> FnOnce(Context<'gc>) -> Result<R, Error<'gc>>,

A version of Lua::enter that expects failure and also automatically converts Error types into StaticError, allowing the error type to escape the arena.

Source

pub fn finish(&mut self, executor: &StashedExecutor)

Run the given executor to completion.

This will periodically exit the arena in order to collect garbage concurrently with running Lua code.

Source

pub fn execute<R: for<'gc> FromMultiValue<'gc>>( &mut self, executor: &StashedExecutor, ) -> Result<R, StaticError>

Run the given executor to completion and then take return values from the returning thread.

This is equivalent to calling Lua::finish on an executor and then calling Executor::take_result yourself.

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 !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<'gc, T> Singleton<'gc> for T
where T: Default,

Source§

fn create(_: Context<'gc>) -> T

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V