pub struct LuaTableRef { /* private fields */ }Expand description
A user-facing reference to a Lua table.
Holds the table in the VM registry so it won’t be garbage-collected. The registry entry is automatically released when this value is dropped.
!Send + !Sync — cannot be transferred across threads.
§Example
let tbl = vm.create_table_ref(0, 4)?;
tbl.set("name", LuaValue::from("Alice"))?;
let name: String = tbl.get_as("name")?;
// tbl is automatically released hereImplementations§
Source§impl LuaTableRef
impl LuaTableRef
Sourcepub fn get(&self, key: &str) -> LuaResult<LuaValue>
pub fn get(&self, key: &str) -> LuaResult<LuaValue>
Get a value by string key (raw access, no metamethods).
Sourcepub fn get_value(&self, key: &LuaValue) -> LuaResult<LuaValue>
pub fn get_value(&self, key: &LuaValue) -> LuaResult<LuaValue>
Get a value by arbitrary LuaValue key.
Sourcepub fn get_as<T: FromLua>(&self, key: &str) -> LuaResult<T>
pub fn get_as<T: FromLua>(&self, key: &str) -> LuaResult<T>
Get a value by string key and convert to a Rust type via FromLua.
Sourcepub fn get_typed<K: IntoLua, T: FromLua>(&self, key: K) -> LuaResult<T>
pub fn get_typed<K: IntoLua, T: FromLua>(&self, key: K) -> LuaResult<T>
Get a value by arbitrary Rust-convertible key and convert it to T.
Sourcepub fn contains_key<K: IntoLua>(&self, key: K) -> LuaResult<bool>
pub fn contains_key<K: IntoLua>(&self, key: K) -> LuaResult<bool>
Returns true if the table contains a non-nil value for the given key.
Sourcepub fn set_value(&self, key: LuaValue, value: LuaValue) -> LuaResult<()>
pub fn set_value(&self, key: LuaValue, value: LuaValue) -> LuaResult<()>
Set an arbitrary key-value pair.
Sourcepub fn set_typed<K: IntoLua, V: IntoLua>(
&self,
key: K,
value: V,
) -> LuaResult<()>
pub fn set_typed<K: IntoLua, V: IntoLua>( &self, key: K, value: V, ) -> LuaResult<()>
Set an arbitrary key-value pair from Rust-convertible values.
Sourcepub fn pairs(&self) -> LuaResult<Vec<(LuaValue, LuaValue)>>
pub fn pairs(&self) -> LuaResult<Vec<(LuaValue, LuaValue)>>
Get all key-value pairs (snapshot, no metamethods).
pub fn is_empty(&self) -> LuaResult<bool>
Sourcepub fn push(&self, value: LuaValue) -> LuaResult<()>
pub fn push(&self, value: LuaValue) -> LuaResult<()>
Append a value to the array part (equivalent to table.insert).
Sourcepub fn push_typed<V: IntoLua>(&self, value: V) -> LuaResult<()>
pub fn push_typed<V: IntoLua>(&self, value: V) -> LuaResult<()>
Append a Rust value to the array part of the table.
Sourcepub fn pairs_typed<K: FromLua, V: FromLua>(&self) -> LuaResult<Vec<(K, V)>>
pub fn pairs_typed<K: FromLua, V: FromLua>(&self) -> LuaResult<Vec<(K, V)>>
Convert all table pairs to typed Rust key-value pairs.
Sourcepub fn sequence_values<V: FromLua>(&self) -> LuaResult<Vec<V>>
pub fn sequence_values<V: FromLua>(&self) -> LuaResult<Vec<V>>
Read contiguous sequence values from 1.. until a nil is encountered.