pub struct LuaThread(/* private fields */);
Expand description
Handle to an internal Lua thread (coroutine).
Implementations§
Source§impl Thread
impl Thread
Sourcepub fn resume<R>(&self, args: impl IntoLuaMulti) -> Result<R, Error>where
R: FromLuaMulti,
pub fn resume<R>(&self, args: impl IntoLuaMulti) -> Result<R, Error>where
R: FromLuaMulti,
Resumes execution of this thread.
Equivalent to coroutine.resume
.
Passes args
as arguments to the thread. If the coroutine has called coroutine.yield
,
it will return these arguments. Otherwise, the coroutine wasn’t yet started, so the
arguments are passed to its main function.
If the thread is no longer resumable (meaning it has finished execution or encountered an
error), this will return Error::CoroutineUnresumable
, otherwise will return Ok
as
follows:
If the thread calls coroutine.yield
, returns the values passed to yield
. If the thread
return
s values from its main function, returns those.
§Examples
let thread: Thread = lua.load(r#"
coroutine.create(function(arg)
assert(arg == 42)
local yieldarg = coroutine.yield(123)
assert(yieldarg == 43)
return 987
end)
"#).eval()?;
assert_eq!(thread.resume::<u32>(42)?, 123);
assert_eq!(thread.resume::<u32>(43)?, 987);
// The coroutine has now returned, so `resume` will fail
match thread.resume::<u32>(()) {
Err(Error::CoroutineUnresumable) => {},
unexpected => panic!("unexpected result {:?}", unexpected),
}
Sourcepub fn status(&self) -> ThreadStatus
pub fn status(&self) -> ThreadStatus
Gets the status of the thread.
Sourcepub fn set_hook<F>(&self, triggers: HookTriggers, callback: F)
pub fn set_hook<F>(&self, triggers: HookTriggers, callback: F)
Sets a hook function that will periodically be called as Lua code executes.
This function is similar or Lua::set_hook
except that it sets for the thread.
To remove a hook call Lua::remove_hook
.
Sourcepub fn reset(&self, func: Function) -> Result<(), Error>
pub fn reset(&self, func: Function) -> Result<(), Error>
Resets a thread
In Lua 5.4: cleans its call stack and closes all pending to-be-closed variables. Returns a error in case of either the original error that stopped the thread or errors in closing methods.
In Luau: resets to the initial state of a newly created Lua thread. Lua threads in arbitrary states (like yielded or errored) can be reset properly.
Sets a Lua function for the thread afterwards.
Requires feature = "lua54"
OR feature = "luau"
.
Sourcepub fn to_pointer(&self) -> *const c_void
pub fn to_pointer(&self) -> *const c_void
Converts this thread to a generic C pointer.
There is no way to convert the pointer back to its original value.
Typically this function is used only for hashing and debug information.
Trait Implementations§
impl Send for Thread
impl Sync for Thread
Auto Trait Implementations§
impl Freeze for Thread
impl !RefUnwindSafe for Thread
impl Unpin for Thread
impl !UnwindSafe for Thread
Blanket Implementations§
Source§impl<T, U> AsBindGroupShaderType<U> for T
impl<T, U> AsBindGroupShaderType<U> for T
Source§fn as_bind_group_shader_type(&self, _images: &RenderAssets<GpuImage>) -> U
fn as_bind_group_shader_type(&self, _images: &RenderAssets<GpuImage>) -> U
T
ShaderType
for self
. When used in AsBindGroup
derives, it is safe to assume that all images in self
exist.Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> FromLuaMulti for Twhere
T: FromLua,
impl<T> FromLuaMulti for Twhere
T: FromLua,
Source§fn from_lua_multi(values: MultiValue, lua: &Lua) -> Result<T, Error>
fn from_lua_multi(values: MultiValue, lua: &Lua) -> Result<T, Error>
fn from_lua_args( args: MultiValue, i: usize, to: Option<&str>, lua: &Lua, ) -> Result<T, Error>
unsafe fn from_stack_multi(nvals: i32, lua: &RawLua) -> Result<T, Error>
unsafe fn from_stack_args( nargs: i32, i: usize, to: Option<&str>, lua: &RawLua, ) -> Result<T, Error>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoLuaMulti for Twhere
T: IntoLua,
impl<T> IntoLuaMulti for Twhere
T: IntoLua,
Source§fn into_lua_multi(self, lua: &Lua) -> Result<MultiValue, Error>
fn into_lua_multi(self, lua: &Lua) -> Result<MultiValue, Error>
unsafe fn push_into_stack_multi(self, lua: &RawLua) -> Result<i32, Error>
Source§impl<T> IntoNamespace for Twhere
T: 'static + ?Sized,
impl<T> IntoNamespace for Twhere
T: 'static + ?Sized,
Source§fn into_namespace() -> Namespace
fn into_namespace() -> Namespace
Namespace