Skip to main content

Table

Struct Table 

Source
pub struct Table { /* private fields */ }
Expand description

A handle to a Lua table.

Mirrors mlua::Table. Holds a registry reference keeping the table alive.

Under the send feature this handle is Send (the VM can be moved across threads) but never Sync — see [crate::sync::NotSync].

Implementations§

Source§

impl Table

Source

pub fn lua(&self) -> Lua

The owning Lua.

Source

pub fn set<K: IntoLua, V: IntoLua>(&self, key: K, value: V) -> Result<()>

Set table[key] = value, honoring metamethods (__newindex).

Mirrors mlua::Table::set. Errors (RuntimeError) propagate from a __newindex metamethod that raises.

Source

pub fn get<V: FromLua>(&self, key: impl IntoLua) -> Result<V>

Get table[key], honoring metamethods (__index), converting the result to V.

Mirrors mlua::Table::get. The value type is the sole explicit type parameter (key type is inferred), matching mlua’s get::<V>(key).

Source

pub fn contains_key<K: IntoLua>(&self, key: K) -> Result<bool>

Whether table[key] is non-nil.

Mirrors mlua::Table::contains_key.

Source

pub fn raw_len(&self) -> usize

The border length (#table).

Mirrors mlua::Table::raw_len (returns usize). luaur’s lua_objlen gives the same border-length semantics as lua_rawlen.

Source

pub fn len(&self) -> Result<usize>

The length (#table), honoring a __len metamethod.

Mirrors mlua::Table::len. Returns Err if a __len metamethod raises. Without a __len metamethod this is the raw border length.

Source

pub fn is_empty(&self) -> bool

Whether the table is empty, without invoking metamethods.

Mirrors mlua::Table::is_empty: checks both the array part and the hash part (a table with only string keys is not empty). Uses a single lua_next probe — present iff the table has at least one key.

Source

pub fn pairs<K: FromLua, V: FromLua>(&self) -> TablePairs<K, V>

Iterate over (key, value) pairs.

Mirrors mlua::Table::pairs. Returns an iterator yielding Result<(K, V)> items. Uses lua_next under the hood.

Source

pub fn pairs_vec<K: FromLua, V: FromLua>(&self) -> Result<Vec<(K, V)>>

Collect all (key, value) pairs into a Vec. Convenience over Table::pairs.

Source

pub fn sequence_values<V: FromLua>(&self) -> TableSequence<V>

Iterate over the sequence part [1..], stopping at the first nil (raw access — ignores __index). Mirrors mlua::Table::sequence_values.

Source

pub fn for_each<K: FromLua, V: FromLua>( &self, f: impl FnMut(K, V) -> Result<()>, ) -> Result<()>

Call f for each (key, value) pair (raw lua_next traversal). Stops early on the first Err. Mirrors mlua::Table::for_each.

The key/value types are the only explicit type parameters (the closure type is inferred), matching mlua’s for_each::<K, V>(f).

Source

pub fn for_each_value<V: FromLua>( &self, f: impl FnMut(V) -> Result<()>, ) -> Result<()>

Call f for each value in the sequence part. Mirrors mlua::Table::for_each_value.

Source

pub fn raw_set<K: IntoLua, V: IntoLua>(&self, key: K, value: V) -> Result<()>

Set table[key] = value without invoking __newindex.

Mirrors mlua::Table::raw_set. Errors if the table is readonly.

Source

pub fn raw_get<V: FromLua>(&self, key: impl IntoLua) -> Result<V>

Get table[key] without invoking __index.

Mirrors mlua::Table::raw_get.

Source

pub fn raw_push<V: IntoLua>(&self, value: V) -> Result<()>

Append value at position #table + 1 using raw access.

Mirrors mlua::Table::raw_push. Errors if readonly.

Source

pub fn raw_pop<V: FromLua>(&self) -> Result<V>

Remove and return the last sequence element via raw access.

Mirrors mlua::Table::raw_pop. Errors if readonly.

Source

pub fn raw_insert<V: IntoLua>(&self, idx: i64, value: V) -> Result<()>

Insert value at 1-based idx, shifting later elements up (raw).

Mirrors mlua::Table::raw_insert. Errors on bad index or readonly.

Source

pub fn raw_remove(&self, idx: i64) -> Result<Value>

Remove and return the element at 1-based idx, shifting later elements down (raw). Mirrors mlua::Table::raw_remove.

Source

pub fn push<V: IntoLua>(&self, value: V) -> Result<()>

Append value honoring __len/__newindex (uses #self + 1). Mirrors mlua::Table::push.

Source

pub fn pop<V: FromLua>(&self) -> Result<V>

Pop the last element honoring __len/__index/__newindex. Mirrors mlua::Table::pop.

Source

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

Remove all keys from the table (raw). Errors if readonly. Mirrors mlua::Table::clear.

Source

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

A raw pointer identifying this table (for identity comparison). Mirrors mlua::Table::to_pointer.

Source

pub fn equals(&self, other: &Table) -> Result<bool>

Compare for equality honoring an __eq metamethod. Mirrors mlua::Table::equals.

Source

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

The table’s metatable, if any. Mirrors mlua::Table::metatable.

Source

pub fn set_metatable(&self, metatable: Option<Table>) -> Result<()>

Set (or clear, with None) the table’s metatable. Mirrors mlua::Table::set_metatable. Errors if the table is readonly.

Source

pub fn is_readonly(&self) -> bool

Whether the table is marked readonly (Luau). Mirrors mlua::Table::is_readonly.

Source

pub fn set_readonly(&self, enabled: bool)

Mark the table readonly or writable (Luau). Mirrors mlua::Table::set_readonly.

Trait Implementations§

Source§

impl Clone for Table

Source§

fn clone(&self) -> Table

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Table

Source§

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

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

impl FromLua for Table

Source§

fn from_lua(value: Value, _lua: &Lua) -> Result<Self>

Perform the conversion.
Source§

fn from_lua_arg( arg: Value, _i: usize, _to: Option<&str>, lua: &Lua, ) -> Result<Self>

Convert an argument at 1-based position i. The default forwards to FromLua::from_lua; specific impls can produce nicer messages. Mirrors mlua::FromLua::from_lua_arg.
Source§

impl IntoLua for Table

Source§

fn into_lua(self, _lua: &Lua) -> Result<Value>

Perform the conversion.
Source§

impl IntoLua for &Table

Source§

fn into_lua(self, _lua: &Lua) -> Result<Value>

Perform the conversion.
Source§

impl PartialEq for Table

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T> PartialEq<&[T]> for Table
where T: FromLua + PartialEq + Clone,

Source§

fn eq(&self, other: &&[T]) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T, const N: usize> PartialEq<[T; N]> for Table
where T: FromLua + PartialEq + Clone,

Source§

fn eq(&self, other: &[T; N]) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T> PartialEq<[T]> for Table
where T: FromLua + PartialEq + Clone,

Compare a Table’s sequence part to a Rust slice of values.

Mirrors mlua’s impl PartialEq<[T]> for Table: equal when the table’s 1..=len sequence (read raw) matches other element-wise and has the same length.

Source§

fn eq(&self, other: &[T]) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

§

impl !RefUnwindSafe for Table

§

impl !Send for Table

§

impl !Sync for Table

§

impl !UnwindSafe for Table

§

impl Freeze for Table

§

impl Unpin for Table

§

impl UnsafeUnpin for Table

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<T> FromLuaMulti for T
where T: FromLua,

Source§

fn from_lua_multi(values: MultiValue, lua: &Lua) -> Result<T, Error>

Perform the conversion.
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> IntoLuaMulti for T
where T: IntoLua,

Source§

fn into_lua_multi(self, lua: &Lua) -> Result<MultiValue, Error>

Perform the conversion.
Source§

impl<T> MaybeSend for T

Source§

impl<T> MaybeSync for T

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.