Struct Table

Source
pub struct Table<'l>(/* private fields */);
Expand description

Represents a lua table on the stack

Implementations§

Source§

impl<'l> Table<'l>

Source

pub fn getp<T>(&self, p: *const T) -> Result<ValRef<'_>>

Get value with a lightuserdata key, commonly is a function pointer

Source

pub fn setp<T, V: ToLua>(&self, k: *const T, v: V) -> Result<()>

Set value with a lightuserdata key

Source

pub fn reference<V: ToLua>(&self, v: V) -> Result<Reference>

Source

pub fn unreference(&self, r: Reference)

Source

pub fn entry_count(&self) -> usize

Count of the table entries

Source

pub fn iter<'t>(&'t self) -> Result<TableIter<'l, &'t Self>>

Iterator to the table entries

Source

pub fn into_iter(self) -> Result<TableIter<'l, Self>>

Like iter(), but take the ownership

Source

pub fn raw_geti(&self, i: impl Into<lua_Integer>) -> Result<ValRef<'l>>

Get value by number index without metamethod triggers

Source

pub fn raw_seti<V: ToLua>(&self, i: impl Into<lua_Integer>, v: V) -> Result<()>

Set value by number index without metamethod triggers

Source

pub fn take_reference(&self, r: Reference) -> Result<ValRef<'l>>

Source

pub fn raw_get<K: ToLua>(&self, key: K) -> Result<ValRef<'l>>

Get the value associated to key without metamethod triggers

Source

pub fn raw_set<K: ToLua, V: ToLua>(&self, k: K, v: V) -> Result<()>

Set value by any key without metamethod triggers

Source

pub fn raw_insert<V: ToLua>(&self, i: usize, val: V) -> Result<()>

Insert an element into the array table, equivalent to table.insert in lua

Source

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

Push an element to end of the array part of a table, alias to self.raw_seti((self.raw_len() + 1) as i64, val)

Source

pub fn pairs(&self) -> Result<impl Iterator<Item = (Value<'_>, Value<'_>)>>

Iterator to the table entries

Source

pub fn set_closure<'a, K: ToLua, A: 'a, R: 'a, F: LuaMethod<'a, (), A, R> + 'static>( &self, name: K, func: F, ) -> Result<&Self>

Alias to self.set(name, lua.new_closure(func))

Source

pub fn set_function<'a, K: ToLua, ARGS: FromLuaMulti<'l>, RET: ToLuaMulti + 'l, F: Fn(&'l State, ARGS) -> RET + 'static>( &self, name: K, func: F, ) -> Result<&Self>

Alias to self.set(name, lua.new_function(func))

Methods from Deref<Target = ValRef<'l>>§

Source

pub fn deserialize<T: Deserialize<'a>>(&'a self) -> Result<T, DesErr>

Deserialize a lua value

Source

pub fn transcode<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error>

Transcode a lua value to another serialize format

Source

pub fn state(&self) -> &'a State

Source

pub fn type_of(&self) -> Type

Type of this value

Source

pub fn is_nil(&self) -> bool

Source

pub fn is_integer(&self) -> bool

Source

pub fn is_table(&self) -> bool

Source

pub fn is_function(&self) -> bool

Source

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

Source

pub fn to_safe_bytes(&self) -> Result<&'a [u8]>

Source

pub fn to_safe_str(&self) -> Result<&'a str>

Source

pub fn to_bytes(&self) -> Option<&[u8]>

Source

pub fn to_str(&self) -> Option<&str>

Source

pub fn to_string_lossy(&self) -> Option<Cow<'_, str>>

Source

pub fn to_bool(&self) -> bool

Source

pub fn to_integer(&self) -> lua_Integer

Source

pub fn to_number(&self) -> lua_Number

Source

pub fn to_pointer(&self) -> *const c_void

Source

pub fn to_cstr_ptr(&self) -> *const c_char

Source

pub fn tostring(&self) -> Cow<'_, str>

Call tostring if this value is not a string

Source

pub fn index(&self) -> Index

Index number of this value on the lua stack

Source

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

Source

pub fn check_type2(&self, ty1: Type, ty2: Type) -> Result<()>

Source

pub fn cast<T: FromLua<'a> + 'static>(&self) -> Result<T>

Alias to cast_into(), not take the ownship, but only convert to static-lifetime types

Source

pub fn geti(&self, i: impl Into<lua_Integer>) -> Result<ValRef<'a>>

Get value associated to integer key, equivalent to return self[i] in lua

Source

pub fn seti<V: ToLua>(&self, i: impl Into<lua_Integer>, v: V) -> Result<()>

Set value with integer key, equivalent to self[i] = v in lua

Source

pub fn len(&self) -> Result<ValRef<'a>>

Get length of the value, equivalent to return #self in lua

Source

pub fn set<K: ToLua, V: ToLua>(&self, k: K, v: V) -> Result<()>

Set value with any key, equivalent to self[k] = v in lua

Source

pub fn get<K: ToLua>(&self, key: K) -> Result<ValRef<'a>>

Get value associated to key, equivalent to return self[k] in lua

Source

pub fn getopt<K: ToLua, V: FromLua<'a> + 'a>(&self, k: K) -> Result<Option<V>>

Source

pub fn pcall<T: ToLuaMulti, R: FromLuaMulti<'a>>(&self, args: T) -> Result<R>

Call this value as a function

Source

pub fn pcall_void<T: ToLuaMulti>(&self, args: T) -> Result<()>

Invoke pcall() without return value

Source

pub fn has_metatable(&self) -> bool

Source

pub fn metatable(&self) -> Result<Option<Table<'a>>>

Get metatable of lua table or userdata

Source

pub fn set_metatable(&self, t: Table<'_>) -> Result<()>

Set metatable for lua table or userdata

Source

pub fn remove_metatable(&self)

Remove metatable for lua table or userdata

Source

pub fn call_metamethod<T: ToLuaMulti, R: FromLuaMulti<'a>>( &self, m: &str, args: T, ) -> Result<R>

Call a metamethod

Source

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

Source

pub fn raw_equal(&self, other: &Self) -> bool

Tests whether two lua values are equal without metamethod triggers

Source

pub fn raw_len(&self) -> usize

Get length of the string/userdata/table without metamethod triggers

Source

pub fn as_table(&self) -> Option<&Table<'a>>

Source

pub fn as_function(&self) -> Option<&Function<'a>>

Source

pub fn as_string(&self) -> Option<&LuaString<'a>>

Source

pub fn as_thread(&self) -> Option<&LuaThread<'a>>

Source

pub fn as_userdata(&self) -> Option<&LuaUserData<'a>>

Source

pub fn airth_add(&self, rhs: impl ToLua) -> Result<Self>

Source

pub fn airth_sub(&self, rhs: impl ToLua) -> Result<Self>

Source

pub fn airth_mul(&self, rhs: impl ToLua) -> Result<Self>

Source

pub fn airth_div(&self, rhs: impl ToLua) -> Result<Self>

Source

pub fn airth_rem(&self, rhs: impl ToLua) -> Result<Self>

Source

pub fn airth_bitand(&self, rhs: impl ToLua) -> Result<Self>

Source

pub fn airth_bitor(&self, rhs: impl ToLua) -> Result<Self>

Source

pub fn airth_bitxor(&self, rhs: impl ToLua) -> Result<Self>

Source

pub fn airth_shl(&self, rhs: impl ToLua) -> Result<Self>

Source

pub fn airth_shr(&self, rhs: impl ToLua) -> Result<Self>

Source

pub fn arith_neg(&self) -> Result<Self>

Source

pub fn arith_not(&self) -> Result<Self>

Source

pub fn idiv(&self, rhs: impl ToLua) -> Result<Self>

Source

pub fn pow(&self, rhs: impl ToLua) -> Result<Self>

Trait Implementations§

Source§

impl<'a> AsRef<Table<'a>> for Table<'a>

Source§

fn as_ref(&self) -> &Table<'a>

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<'l> Clone for Table<'l>

Source§

fn clone(&self) -> Table<'l>

Returns a duplicate 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<'l> Debug for Table<'l>

Source§

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

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

impl<'l> Deref for Table<'l>

Source§

type Target = ValRef<'l>

The resulting type after dereferencing.
Source§

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

Dereferences the value.
Source§

impl<'a> FromLua<'a> for Table<'a>

Source§

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

Source§

const TYPE_NAME: &'static str = _

Source§

impl<'a> Into<ValRef<'a>> for Table<'a>

Source§

fn into(self) -> ValRef<'a>

Converts this type into the (usually inferred) input type.
Source§

impl<'a> ToLua for Table<'a>

Source§

fn to_lua<'a>(self, lua: &'a State) -> Result<ValRef<'a>>

Source§

impl<'a> TryFrom<ValRef<'a>> for Table<'a>

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(val: ValRef<'a>) -> Result<Self>

Performs the conversion.

Auto Trait Implementations§

§

impl<'l> Freeze for Table<'l>

§

impl<'l> !RefUnwindSafe for Table<'l>

§

impl<'l> !Send for Table<'l>

§

impl<'l> !Sync for Table<'l>

§

impl<'l> Unpin for Table<'l>

§

impl<'l> !UnwindSafe for Table<'l>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToLuaMulti for T
where T: ToLua,

Source§

const VALUE_COUNT: Option<usize> = const VALUE_COUNT: Option<usize> = Some(1);

Count of values to be pushed to lua stack
Source§

fn push_multi(self, s: &State) -> Result<usize, Error>

Define how to push values onto lua stack
Source§

fn value_count(&self) -> Option<usize>

Get the count of values to be pushed to lua stack, with self instance
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

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

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.