Skip to main content

low_luajit/lua/type/
thread.rs

1use crate::{LuaState, ffi};
2
3/*
4#[repr(i32)]
5#[derive(Debug)]
6pub enum ThreadStatus {
7	/// This thread is operational.
8	Ok = ffi::LUA_OK,
9
10	/// This thread is suspended.
11	Yielded = ffi::LUA_YIELD,
12
13	/// This thread encountered an error while running.
14	RuntimeError = ffi::LUA_ERRRUN,
15
16
17}*/
18
19/// Thread related functions.
20impl LuaState {
21	/// Returns `true` if the value at the given acceptable `index` is a thread, `false` otherwise.
22	#[inline]
23	#[must_use]
24	pub fn is_thread(&self, index: i32) -> bool {
25		// SAFETY: self.0 is always valid.
26		unsafe { ffi::lua_isthread(self.0, index) != 0 }
27	}
28
29	/// Pushes the thread represented by this `LuaState` onto the stack.
30	///
31	/// Returns `true` if this thread is the main thread of its state, `false` otherwise.
32	#[inline]
33	pub fn push_thread(&mut self) -> bool {
34		// SAFETY: self.0 is always valid.
35		unsafe { ffi::lua_pushthread(self.0) != 0 }
36	}
37}