pub struct Lua { /* private fields */ }
Implementations§
Source§impl Lua
impl Lua
Sourcepub fn load_core(&mut self)
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
Sourcepub fn total_memory(&self) -> usize
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
.
Sourcepub fn gc_collect(&mut self)
pub fn gc_collect(&mut self)
Finish the current collection cycle completely, calls gc_arena::Arena::collect_all()
.
pub fn gc_metrics(&self) -> &Metrics
Sourcepub fn enter<F, T>(&mut self, f: F) -> T
pub fn enter<F, T>(&mut self, f: F) -> 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.
Sourcepub fn try_enter<F, R>(&mut self, f: F) -> Result<R, StaticError>
pub fn try_enter<F, R>(&mut self, f: F) -> Result<R, StaticError>
A version of Lua::enter
that expects failure and also automatically converts Error
types
into StaticError
, allowing the error type to escape the arena.
Sourcepub fn finish(&mut self, executor: &StashedExecutor)
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.
Sourcepub fn execute<R: for<'gc> FromMultiValue<'gc>>(
&mut self,
executor: &StashedExecutor,
) -> Result<R, StaticError>
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.