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
impl Table
Sourcepub fn set<K: IntoLua, V: IntoLua>(&self, key: K, value: V) -> Result<()>
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.
Sourcepub fn get<V: FromLua>(&self, key: impl IntoLua) -> Result<V>
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).
Sourcepub fn contains_key<K: IntoLua>(&self, key: K) -> Result<bool>
pub fn contains_key<K: IntoLua>(&self, key: K) -> Result<bool>
Whether table[key] is non-nil.
Mirrors mlua::Table::contains_key.
Sourcepub fn raw_len(&self) -> usize
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.
Sourcepub fn len(&self) -> Result<usize>
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.
Sourcepub fn is_empty(&self) -> bool
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.
Sourcepub fn pairs<K: FromLua, V: FromLua>(&self) -> TablePairs<K, V> ⓘ
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.
Sourcepub fn pairs_vec<K: FromLua, V: FromLua>(&self) -> Result<Vec<(K, V)>>
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.
Sourcepub fn sequence_values<V: FromLua>(&self) -> TableSequence<V> ⓘ
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.
Sourcepub fn for_each<K: FromLua, V: FromLua>(
&self,
f: impl FnMut(K, V) -> Result<()>,
) -> Result<()>
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).
Sourcepub fn for_each_value<V: FromLua>(
&self,
f: impl FnMut(V) -> Result<()>,
) -> Result<()>
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.
Sourcepub fn raw_set<K: IntoLua, V: IntoLua>(&self, key: K, value: V) -> Result<()>
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.
Sourcepub fn raw_get<V: FromLua>(&self, key: impl IntoLua) -> Result<V>
pub fn raw_get<V: FromLua>(&self, key: impl IntoLua) -> Result<V>
Get table[key] without invoking __index.
Mirrors mlua::Table::raw_get.
Sourcepub fn raw_push<V: IntoLua>(&self, value: V) -> Result<()>
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.
Sourcepub fn raw_pop<V: FromLua>(&self) -> Result<V>
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.
Sourcepub fn raw_insert<V: IntoLua>(&self, idx: i64, value: V) -> Result<()>
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.
Sourcepub fn raw_remove(&self, idx: i64) -> Result<Value>
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.
Sourcepub fn push<V: IntoLua>(&self, value: V) -> Result<()>
pub fn push<V: IntoLua>(&self, value: V) -> Result<()>
Append value honoring __len/__newindex (uses #self + 1).
Mirrors mlua::Table::push.
Sourcepub fn pop<V: FromLua>(&self) -> Result<V>
pub fn pop<V: FromLua>(&self) -> Result<V>
Pop the last element honoring __len/__index/__newindex.
Mirrors mlua::Table::pop.
Sourcepub fn clear(&self) -> Result<()>
pub fn clear(&self) -> Result<()>
Remove all keys from the table (raw). Errors if readonly.
Mirrors mlua::Table::clear.
Sourcepub fn to_pointer(&self) -> *const c_void
pub fn to_pointer(&self) -> *const c_void
A raw pointer identifying this table (for identity comparison).
Mirrors mlua::Table::to_pointer.
Sourcepub fn equals(&self, other: &Table) -> Result<bool>
pub fn equals(&self, other: &Table) -> Result<bool>
Compare for equality honoring an __eq metamethod.
Mirrors mlua::Table::equals.
Sourcepub fn metatable(&self) -> Option<Table>
pub fn metatable(&self) -> Option<Table>
The table’s metatable, if any. Mirrors mlua::Table::metatable.
Sourcepub fn set_metatable(&self, metatable: Option<Table>) -> Result<()>
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.
Sourcepub fn is_readonly(&self) -> bool
pub fn is_readonly(&self) -> bool
Whether the table is marked readonly (Luau). Mirrors
mlua::Table::is_readonly.
Sourcepub fn set_readonly(&self, enabled: bool)
pub fn set_readonly(&self, enabled: bool)
Mark the table readonly or writable (Luau). Mirrors
mlua::Table::set_readonly.
Trait Implementations§
Source§impl FromLua for Table
impl FromLua for Table
Source§fn from_lua_arg(
arg: Value,
_i: usize,
_to: Option<&str>,
lua: &Lua,
) -> Result<Self>
fn from_lua_arg( arg: Value, _i: usize, _to: Option<&str>, lua: &Lua, ) -> Result<Self>
i. The default forwards to
FromLua::from_lua; specific impls can produce nicer messages.
Mirrors mlua::FromLua::from_lua_arg.