Skip to main content

Table

Struct Table 

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

Implementations§

Source§

impl Table

Source

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

Source

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

Examples found in repository?
examples/scope_world.rs (line 71)
65fn main() -> Result<()> {
66    let lua = Lua::new();
67    let mut world = World::default();
68
69    let count: i64 = lua.scope(|s| {
70        let world_ud = s.create_userdata_ref_mut(&lua, &mut world)?;
71        lua.globals().set("world", &world_ud)?;
72
73        lua.load(
74            r#"
75            local a = world:spawn()
76            local b = world:spawn()
77
78            -- Direct mutation through a live sub-reference.
79            local pa = world:position(a)
80            pa.x, pa.y = 10, 20
81
82            local pb = world:position(b)
83            pb.x = pa.x + 5      -- reading pa here re-borrows; both are short-lived
84
85            -- Stash one to prove it dies with the scope.
86            escaped = world:position(a)
87
88            return world:count()
89        "#,
90        )
91        .eval()
92    })?;
93
94    println!("spawned {count} entities");
95    // The mutations are visible to Rust after the scope returns.
96    for (i, e) in world.entities.iter().enumerate() {
97        println!("entity {i} = ({}, {})", e.x, e.y);
98    }
99
100    // The handle the script stashed on `escaped` is now invalid. Reading a
101    // field raises a Lua error rather than touching the released `&mut World`.
102    // We surface the message through Lua's own `pcall` + `tostring`, since the
103    // error payload is a Lua value.
104    let (ok, msg): (bool, String) = lua
105        .load("local ok, e = pcall(function() return escaped.x end); return ok, tostring(e)")
106        .eval()?;
107    assert!(!ok, "stashed handle should be unusable after the scope");
108    println!("post-scope use of a stashed handle -> {msg}");
109
110    Ok(())
111}
Source

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

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>

Source§

impl IntoLua for &Table

Source§

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

Source§

impl IntoLua for Table

Source§

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

Auto Trait Implementations§

§

impl Freeze for Table

§

impl !RefUnwindSafe for Table

§

impl !Send for Table

§

impl !Sync for Table

§

impl Unpin for Table

§

impl UnsafeUnpin for Table

§

impl !UnwindSafe 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§

const NRESULTS: i32 = const NRESULTS: i32 = 1;

Source§

fn from_lua_multi(values: Vec<Value>, lua: &Lua) -> Result<T, LuaError>

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§

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.