Skip to main content

LuaTableRef

Struct LuaTableRef 

Source
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 here

Implementations§

Source§

impl LuaTableRef

Source

pub fn get(&self, key: &str) -> LuaResult<LuaValue>

Get a value by string key (raw access, no metamethods).

Source

pub fn geti(&self, key: i64) -> LuaResult<LuaValue>

Get a value by integer key.

Source

pub fn get_value(&self, key: &LuaValue) -> LuaResult<LuaValue>

Get a value by arbitrary LuaValue key.

Source

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.

Source

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.

Source

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.

Source

pub fn set(&self, key: &str, value: LuaValue) -> LuaResult<()>

Set a string-keyed value.

Source

pub fn seti(&self, key: i64, value: LuaValue) -> LuaResult<()>

Set an integer-keyed value.

Source

pub fn set_value(&self, key: LuaValue, value: LuaValue) -> LuaResult<()>

Set an arbitrary key-value pair.

Source

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

Set an arbitrary key-value pair from Rust-convertible values.

Source

pub fn pairs(&self) -> LuaResult<Vec<(LuaValue, LuaValue)>>

Get all key-value pairs (snapshot, no metamethods).

Source

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

Get the array length (equivalent to Lua’s #t).

Source

pub fn is_empty(&self) -> LuaResult<bool>

Source

pub fn push(&self, value: LuaValue) -> LuaResult<()>

Append a value to the array part (equivalent to table.insert).

Source

pub fn push_typed<V: IntoLua>(&self, value: V) -> LuaResult<()>

Append a Rust value to the array part of the table.

Source

pub fn pairs_typed<K: FromLua, V: FromLua>(&self) -> LuaResult<Vec<(K, V)>>

Convert all table pairs to typed Rust key-value pairs.

Source

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

Read contiguous sequence values from 1.. until a nil is encountered.

Source

pub fn to_value(&self) -> LuaValue

Get the underlying LuaValue (retrieved from registry).

Source

pub fn ref_id(&self) -> i32

Get the registry reference ID.

Trait Implementations§

Source§

impl Clone for LuaTableRef

Source§

fn clone(&self) -> Self

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 LuaTableRef

Source§

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

Formats the value using the given formatter. Read more

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> 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, 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> LuaMethodProvider for T

Source§

impl<T> LuaStaticMethodProvider for T

Source§

fn __lua_static_methods() -> &'static [(&'static str, CFunction)]

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.