Coroutine

Struct Coroutine 

Source
pub struct Coroutine { /* private fields */ }

Implementations§

Source§

impl Coroutine

Source

pub fn empty(s: &State) -> Self

Source

pub fn new(fun: ValRef<'_>) -> Result<Self>

Source

pub fn func(&self) -> Result<Function<'_>>

Get the function associated to this coroutine

Methods from Deref<Target = State>§

Source

pub unsafe fn new_iter<'l, R: ToLuaMulti + 'l, I: Iterator<Item = R> + 'l, REF: ToLuaMulti>( &self, iter: I, refs: REF, ) -> Result<LuaUserData<'_>>

Create an iterator with non-static reference, you should ensure that these references is valid via the refs argument, which is be referenced by the iter closure’s upvalues

Source

pub unsafe fn new_iter_map<'l, R: 'l, I: Iterator<Item = R> + 'l, MR: ToLuaMulti + 'l, M: Fn(&'l State, R) -> MR + 'l, REF: ToLuaMulti>( &self, iter: I, map: M, refs: REF, ) -> Result<LuaUserData<'_>>

Like State::new_iter, and you can specify a map function.

Source

pub fn new_function<'l, ARGS: FromLuaMulti<'l>, RET: ToLuaMulti + 'l, F: Fn(&'l State, ARGS) -> RET + 'static>( &'l self, fun: F, ) -> Result<Function<'_>>

Bind a rust function(closure) with uniform argument types

Source

pub fn new_closure<'l, A: 'l, R: 'l, F: LuaMethod<'l, (), A, R> + 'static>( &self, fun: F, ) -> Result<Function<'_>>

Bind a rust function(closure) with flexible argument types

Source

pub fn new_closure0<'l, RET: ToLuaMulti + 'l, FN: Fn(&'l State) -> RET + 'static>( &'l self, f: FN, ) -> Result<Function<'l>>

Source

pub fn new_closure1<'l, RET: ToLuaMulti + 'l, A: FromLua<'l>, FN: Fn(&'l State, A) -> RET + 'static>( &'l self, f: FN, ) -> Result<Function<'l>>

Source

pub fn new_closure2<'l, RET: ToLuaMulti + 'l, A: FromLua<'l>, B: FromLua<'l>, FN: Fn(&'l State, A, B) -> RET + 'static>( &'l self, f: FN, ) -> Result<Function<'l>>

Source

pub fn new_closure3<'l, RET: ToLuaMulti + 'l, A: FromLua<'l>, B: FromLua<'l>, C: FromLua<'l>, FN: Fn(&'l State, A, B, C) -> RET + 'static>( &'l self, f: FN, ) -> Result<Function<'l>>

Source

pub fn new_closure4<'l, RET: ToLuaMulti + 'l, A: FromLua<'l>, B: FromLua<'l>, C: FromLua<'l>, D: FromLua<'l>, FN: Fn(&'l State, A, B, C, D) -> RET + 'static>( &'l self, f: FN, ) -> Result<Function<'l>>

Source

pub fn new_closure5<'l, RET: ToLuaMulti + 'l, A: FromLua<'l>, B: FromLua<'l>, C: FromLua<'l>, D: FromLua<'l>, E: FromLua<'l>, FN: Fn(&'l State, A, B, C, D, E) -> RET + 'static>( &'l self, f: FN, ) -> Result<Function<'l>>

Source

pub fn new_closure6<'l, RET: ToLuaMulti + 'l, A: FromLua<'l>, B: FromLua<'l>, C: FromLua<'l>, D: FromLua<'l>, E: FromLua<'l>, F: FromLua<'l>, FN: Fn(&'l State, A, B, C, D, E, F) -> RET + 'static>( &'l self, f: FN, ) -> Result<Function<'l>>

Source

pub fn new_closure7<'l, RET: ToLuaMulti + 'l, A: FromLua<'l>, B: FromLua<'l>, C: FromLua<'l>, D: FromLua<'l>, E: FromLua<'l>, F: FromLua<'l>, G: FromLua<'l>, FN: Fn(&'l State, A, B, C, D, E, F, G) -> RET + 'static>( &'l self, f: FN, ) -> Result<Function<'l>>

Source

pub fn new_closure8<'l, RET: ToLuaMulti + 'l, A: FromLua<'l>, B: FromLua<'l>, C: FromLua<'l>, D: FromLua<'l>, E: FromLua<'l>, F: FromLua<'l>, G: FromLua<'l>, H: FromLua<'l>, FN: Fn(&'l State, A, B, C, D, E, F, G, H) -> RET + 'static>( &'l self, f: FN, ) -> Result<Function<'l>>

Source

pub fn new_closure9<'l, RET: ToLuaMulti + 'l, A: FromLua<'l>, B: FromLua<'l>, C: FromLua<'l>, D: FromLua<'l>, E: FromLua<'l>, F: FromLua<'l>, G: FromLua<'l>, H: FromLua<'l>, I: FromLua<'l>, FN: Fn(&'l State, A, B, C, D, E, F, G, H, I) -> RET + 'static>( &'l self, f: FN, ) -> Result<Function<'l>>

Source

pub fn new_closure10<'l, RET: ToLuaMulti + 'l, A: FromLua<'l>, B: FromLua<'l>, C: FromLua<'l>, D: FromLua<'l>, E: FromLua<'l>, F: FromLua<'l>, G: FromLua<'l>, H: FromLua<'l>, I: FromLua<'l>, J: FromLua<'l>, FN: Fn(&'l State, A, B, C, D, E, F, G, H, I, J) -> RET + 'static>( &'l self, f: FN, ) -> Result<Function<'l>>

Source

pub fn pushed<T: ToLuaMulti>(&self, results: T) -> Result<Pushed>

Push results to stack

Source

pub fn serialize_to_val<V: Serialize>(&self, v: V) -> LuaResult<ValRef<'_>>

convert a serializable value into a lua value

Source

pub fn load_from_deserializer<'l: 'de, 'de, D: Deserializer<'de>>( &'l self, deserializer: D, ) -> Result<ValRef<'l>, LuaError>

transcode a serializable value from deserializer into a lua value

Source

pub fn array_metatable(&self) -> LuaResult<LuaTable<'_>>

A metatable attachable to a Lua table to systematically encode it as Array (instead of Map). As result, encoded Array will contain only sequence part of the table, with the same length as the # operator on that table.

Source

pub fn null_value(&self) -> LuaValue<'_>

A special value to encode/decode optional (none) values.

Source

pub fn register_usertype<U: UserData>(&self) -> Result<Table<'_>>

Register a metatable of UserData into the C registry and return it

Source

pub fn new_userdata<T: UserData>(&self, data: T) -> Result<LuaUserData<'_>>

Create userdata

Source

pub fn scope_userdata<T: UserData>(&self, data: T) -> Result<ScopeUserdata<'_>>

Source

pub fn new_userdata_with_values<T: UserData, R: ToLuaMulti>( &self, data: T, refs: R, ) -> Result<LuaUserData<'_>>

Source

pub fn new_userdata_untyped( &self, size: usize, uv_count: usize, ) -> Result<LuaUserData<'_>>

Create userdata with custom size

Source

pub fn raw_state(&self) -> *mut lua_State

Source

pub fn stack_top(&self) -> i32

Source

pub fn check_stack(&self, n: i32) -> Result<()>

Source

pub fn check_type(&self, i: Index, ty: Type) -> Result<()>

Source

pub fn up_value(&self, i: Index) -> ValRef<'_>

Source

pub fn clear_slots(&self) -> Result<()>

Clear the free slots, assign nil, and shrink the lua stack as much as possible

Source

pub fn arg_val(&self, i: Index) -> Option<ValRef<'_>>

Source

pub fn to_safe_bytes(&self, i: Index) -> Option<&[u8]>

Source

pub fn registry(&self) -> Table<'_>

Get the C registry table

Source

pub fn new_val<V: ToLua>(&self, val: V) -> Result<ValRef<'_>>

Create a new lua value

Source

pub fn new_value<V: ToLua>(&self, val: V) -> Result<Value<'_>>

Create a new lua value, return as Value rather than ValRef

Source

pub fn new_table_with_size(&self, narr: c_int, nrec: c_int) -> Result<Table<'_>>

Create a lua table and specify the size

Source

pub fn new_array_table(&self, narr: usize) -> Result<Table<'_>>

Create an array table

Source

pub fn new_table(&self) -> Result<Table<'_>>

Create a lua table

Source

pub fn new_string<S: AsRef<[u8]>>(&self, s: S) -> Result<LuaString<'_>>

Create a lua string

Source

pub fn load<S: AsRef<[u8]>>( &self, s: S, name: Option<&str>, ) -> Result<Function<'_>>

Load script string or bytecode

Source

pub fn load_file<P: AsRef<Path>>(&self, path: P) -> Result<Function<'_>>

Create function from script file

Source

pub fn register_module<'a, F: Fn(&'a State) -> Result<Table<'a>> + 'static>( &self, name: &str, init: F, global: bool, ) -> Result<()>

Register your own lua module, which can be load by require function in lua

Source

pub fn global(&self) -> Table<'_>

Get the lua global table

Source

pub fn main_state(&self) -> LuaThread<'_>

Source

pub fn used_memory(&self) -> usize

Returns the amount of memory (in bytes) currently used inside this Lua state

Source

pub fn gc_collect(&self) -> Result<()>

Do a full GC for lua

Source

pub fn gc_is_running(&self) -> bool

Returns true if the garbage collector is currently running automatically

Source

pub fn gc_stop(&self)

Stop the Lua GC from running

Source

pub fn gc_restart(&self)

Restarts the Lua GC if it is not running

Source

pub fn gc_step(&self) -> Result<bool>

Steps the garbage collector one indivisible step.

Returns true if this has finished a collection cycle.

Source

pub fn gc_step_kbytes(&self, kbytes: c_int) -> Result<bool>

Steps the garbage collector as though memory had been allocated.

if kbytes is 0, then this is the same as calling gc_step. Returns true if this step has finished a collection cycle.

Source

pub fn gc_set_pause(&self, pause: c_int) -> c_int

Sets the ‘pause’ value of the collector.

Returns the previous value of ‘pause’. More information can be found in the Lua documentation

Source

pub fn gc_set_step_multiplier(&self, step_multiplier: c_int) -> c_int

Sets the ‘step multiplier’ value of the collector.

Returns the previous value of the ‘step multiplier’. More information can be found in the Lua documentation

Source

pub fn gc_inc( &self, pause: c_int, step_multiplier: c_int, step_size: c_int, ) -> GCMode

Changes the collector to incremental mode with the given parameters.

Returns the previous mode (always GCMode::Incremental in Lua < 5.4). More information can be found in the Lua documentation

Source

pub fn gc_gen(&self, minor_multiplier: c_int, major_multiplier: c_int) -> GCMode

Changes the collector to generational mode with the given parameters.

Returns the previous mode. More information about the generational GC can be found in the Lua 5.4 documentation

Source

pub fn backtrace( &self, co: Option<&State>, msg: &str, level: i32, ) -> Result<String>

Stack backtrace info

Source

pub unsafe fn test_userdata_meta<T>( &self, i: Index, meta: MetatableKey, ) -> Option<&mut T>

Source

pub fn stack(&self, n: i32) -> Option<lua_Debug>

Source

pub fn do_string<S: AsRef<[u8]>>( &self, script: S, name: Option<&str>, ) -> Result<()>

Load lua script and execute it

Source

pub fn registry_value<V: ToLua>(&self, val: V) -> Result<RegVal>

Source

pub fn safe_index(&self, i: Index) -> bool

Source

pub fn free_slots(&self) -> Ref<'_, Slots<i32>>

Trait Implementations§

Source§

impl Deref for Coroutine

Source§

type Target = State

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl Drop for Coroutine

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl FromLua<'_> for Coroutine

Source§

fn from_lua(s: &State, val: ValRef<'_>) -> Result<Self>

Source§

const TYPE_NAME: &'static str = _

Source§

impl Send for Coroutine

Auto Trait Implementations§

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<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<'a, T> FromLuaMulti<'a> for T
where T: FromLua<'a>,

Source§

const COUNT: usize = 1usize

Source§

fn from_lua_multi(s: &'a State, begin: i32) -> Result<T, Error>

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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

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

Source§

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

Source§

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.