pub struct Executor<'gc>(/* private fields */);Expand description
The entry-point for the Lua VM.
Executor runs networks of Threads that may depend on each other and may pass control
back and forth. All Lua code that is run is done so directly or indirectly by calling
Executor::step.
Panics
Executor is dangerous to use from within any kind of Lua callback. It has no protection
against re-entrency, and calling Executor methods from within a callback that it is running
(other than Executor::mode) will panic. Additionally, even if an independent Executor is
used, cross-thread upvalues may cause a panic if one Executor is used within the other.
Executors are not meant to be used from callbacks at all, and Executors should not be
nested. Instead, use the normal mechanisms for callbacks to call Lua code so that it is run on
the same executor calling the callback.
Implementations§
source§impl<'gc> Executor<'gc>
impl<'gc> Executor<'gc>
sourcepub fn run(mc: &Mutation<'gc>, thread: Thread<'gc>) -> Self
pub fn run(mc: &Mutation<'gc>, thread: Thread<'gc>) -> Self
Creates a new Executor that begins running the given thread.
pub fn from_inner(inner: Gc<'gc, ExecutorInner<'gc>>) -> Self
pub fn into_inner(self) -> Gc<'gc, ExecutorInner<'gc>>
sourcepub fn start(
ctx: Context<'gc>,
function: Function<'gc>,
args: impl IntoMultiValue<'gc>
) -> Self
pub fn start( ctx: Context<'gc>, function: Function<'gc>, args: impl IntoMultiValue<'gc> ) -> Self
Creates a new Executor with a new Thread running the given function.
pub fn mode(self) -> ExecutorMode
sourcepub fn step(self, ctx: Context<'gc>, fuel: &mut Fuel) -> bool
pub fn step(self, ctx: Context<'gc>, fuel: &mut Fuel) -> bool
Runs the VM for a period of time controlled by the fuel parameter.
The VM and callbacks will consume fuel as they run, and Executor::step will return as soon
as Fuel::can_continue() returns false and some minimal positive progress has been made.
Returns false if the method has exhausted its fuel, but there is more work to
do, and returns true if no more progress can be made. If true is returned, then
Executor::mode() will no longer be ExecutorMode::Normal.
pub fn take_result<T: FromMultiValue<'gc>>( self, ctx: Context<'gc> ) -> Result<Result<T, Error<'gc>>, BadExecutorMode>
pub fn resume( self, ctx: Context<'gc>, args: impl IntoMultiValue<'gc> ) -> Result<(), BadExecutorMode>
pub fn resume_err( self, mc: &Mutation<'gc>, error: Error<'gc> ) -> Result<(), BadExecutorMode>
sourcepub fn stop(self, mc: &Mutation<'gc>)
pub fn stop(self, mc: &Mutation<'gc>)
Reset this Executor entirely, leaving it with a stopped main thread. Equivalent to
creating a new executor with Executor::new.
sourcepub fn reset(self, mc: &Mutation<'gc>, thread: Thread<'gc>)
pub fn reset(self, mc: &Mutation<'gc>, thread: Thread<'gc>)
Reset this Executor entirely and begins running the given thread. Equivalent to
creating a new executor with Executor::run.
sourcepub fn restart(
self,
ctx: Context<'gc>,
function: Function<'gc>,
args: impl IntoMultiValue<'gc>
)
pub fn restart( self, ctx: Context<'gc>, function: Function<'gc>, args: impl IntoMultiValue<'gc> )
Reset this Executor entirely and begins running the given function, equivalent to
creating a new executor with Executor::start.
Trait Implementations§
source§impl<'gc> Collect for Executor<'gc>
impl<'gc> Collect for Executor<'gc>
source§fn needs_trace() -> bool
fn needs_trace() -> bool
Gc pointer and trace is unnecessary
to call, you may implement this method and return false. The default implementation returns
true, signaling that Collect::trace must be called.source§fn trace(&self, cc: &Collection)
fn trace(&self, cc: &Collection)
Collect::trace on all held Gc pointers. If this type holds inner types that
implement Collect, a valid implementation would simply call Collect::trace on all the
held values to ensure this.