Struct piccolo::thread::Executor

source ·
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>

source

pub fn new(ctx: Context<'gc>) -> Self

Creates a new Executor with a stopped main thread.

source

pub fn run(mc: &Mutation<'gc>, thread: Thread<'gc>) -> Self

Creates a new Executor that begins running the given thread.

source

pub fn from_inner(inner: Gc<'gc, ExecutorInner<'gc>>) -> Self

source

pub fn into_inner(self) -> Gc<'gc, ExecutorInner<'gc>>

source

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.

source

pub fn mode(self) -> ExecutorMode

source

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.

source

pub fn take_result<T: FromMultiValue<'gc>>( self, ctx: Context<'gc> ) -> Result<Result<T, Error<'gc>>, BadExecutorMode>

source

pub fn resume( self, ctx: Context<'gc>, args: impl IntoMultiValue<'gc> ) -> Result<(), BadExecutorMode>

source

pub fn resume_err( self, mc: &Mutation<'gc>, error: Error<'gc> ) -> Result<(), BadExecutorMode>

source

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.

source

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.

source

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> Clone for Executor<'gc>

source§

fn clone(&self) -> Executor<'gc>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<'gc> Collect for Executor<'gc>

source§

fn needs_trace() -> bool

As an optimization, if this type can never hold a 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)

Must call 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.
source§

impl<'gc> Debug for Executor<'gc>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'gc> Hash for Executor<'gc>

source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl<'gc> PartialEq for Executor<'gc>

source§

fn eq(&self, other: &Executor<'gc>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'gc> Stashable<'gc> for Executor<'gc>

§

type Stashed = StashedExecutor

source§

fn stash(self, roots: &DynamicRootSet<'gc>, mc: &Mutation<'gc>) -> Self::Stashed

source§

impl<'gc> Copy for Executor<'gc>

source§

impl<'gc> Eq for Executor<'gc>

Auto Trait Implementations§

§

impl<'gc> !RefUnwindSafe for Executor<'gc>

§

impl<'gc> !Send for Executor<'gc>

§

impl<'gc> !Sync for Executor<'gc>

§

impl<'gc> Unpin for Executor<'gc>

§

impl<'gc> !UnwindSafe for Executor<'gc>

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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. 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> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

§

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>,

§

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

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

§

fn vzip(self) -> V