pub trait ObjectLike: Sealed {
// Required methods
fn get<V: FromLua>(&self, key: impl IntoLua) -> Result<V>;
fn set(&self, key: impl IntoLua, value: impl IntoLua) -> Result<()>;
fn call<R>(&self, args: impl IntoLuaMulti) -> Result<R>
where R: FromLuaMulti;
fn call_async<R>(&self, args: impl IntoLuaMulti) -> AsyncCallFuture<R>
where R: FromLuaMulti;
fn call_method<R>(&self, name: &str, args: impl IntoLuaMulti) -> Result<R>
where R: FromLuaMulti;
fn call_async_method<R>(
&self,
name: &str,
args: impl IntoLuaMulti,
) -> AsyncCallFuture<R>
where R: FromLuaMulti;
fn call_function<R>(&self, name: &str, args: impl IntoLuaMulti) -> Result<R>
where R: FromLuaMulti;
fn call_async_function<R>(
&self,
name: &str,
args: impl IntoLuaMulti,
) -> AsyncCallFuture<R>
where R: FromLuaMulti;
fn to_string(&self) -> Result<StdString>;
fn to_value(&self) -> Value;
// Provided method
fn get_path<V: FromLua>(&self, path: &str) -> Result<V> { ... }
}Expand description
A trait for types that can be used as Lua objects (usually table and userdata).
Required Methods§
Sourcefn get<V: FromLua>(&self, key: impl IntoLua) -> Result<V>
fn get<V: FromLua>(&self, key: impl IntoLua) -> Result<V>
Gets the value associated to key from the object, assuming it has __index metamethod.
Sourcefn set(&self, key: impl IntoLua, value: impl IntoLua) -> Result<()>
fn set(&self, key: impl IntoLua, value: impl IntoLua) -> Result<()>
Sets the value associated to key in the object, assuming it has __newindex metamethod.
Sourcefn call<R>(&self, args: impl IntoLuaMulti) -> Result<R>where
R: FromLuaMulti,
fn call<R>(&self, args: impl IntoLuaMulti) -> Result<R>where
R: FromLuaMulti,
Calls the object as a function assuming it has __call metamethod.
The metamethod is called with the object as its first argument, followed by the passed arguments.
Sourcefn call_async<R>(&self, args: impl IntoLuaMulti) -> AsyncCallFuture<R>where
R: FromLuaMulti,
Available on crate feature async only.
fn call_async<R>(&self, args: impl IntoLuaMulti) -> AsyncCallFuture<R>where
R: FromLuaMulti,
async only.Asynchronously calls the object as a function assuming it has __call metamethod.
The metamethod is called with the object as its first argument, followed by the passed arguments.
Sourcefn call_method<R>(&self, name: &str, args: impl IntoLuaMulti) -> Result<R>where
R: FromLuaMulti,
fn call_method<R>(&self, name: &str, args: impl IntoLuaMulti) -> Result<R>where
R: FromLuaMulti,
Gets the function associated to key name from the object and calls it,
passing the object itself along with args as function arguments.
Sourcefn call_async_method<R>(
&self,
name: &str,
args: impl IntoLuaMulti,
) -> AsyncCallFuture<R>where
R: FromLuaMulti,
Available on crate feature async only.
fn call_async_method<R>(
&self,
name: &str,
args: impl IntoLuaMulti,
) -> AsyncCallFuture<R>where
R: FromLuaMulti,
async only.Gets the function associated to key name from the object and asynchronously calls it,
passing the object itself along with args as function arguments.
This might invoke the __index metamethod.
Sourcefn call_function<R>(&self, name: &str, args: impl IntoLuaMulti) -> Result<R>where
R: FromLuaMulti,
fn call_function<R>(&self, name: &str, args: impl IntoLuaMulti) -> Result<R>where
R: FromLuaMulti,
Gets the function associated to key name from the object and calls it,
passing args as function arguments.
This might invoke the __index metamethod.
Sourcefn call_async_function<R>(
&self,
name: &str,
args: impl IntoLuaMulti,
) -> AsyncCallFuture<R>where
R: FromLuaMulti,
Available on crate feature async only.
fn call_async_function<R>(
&self,
name: &str,
args: impl IntoLuaMulti,
) -> AsyncCallFuture<R>where
R: FromLuaMulti,
async only.Gets the function associated to key name from the object and asynchronously calls it,
passing args as function arguments.
This might invoke the __index metamethod.
Provided Methods§
Sourcefn get_path<V: FromLua>(&self, path: &str) -> Result<V>
fn get_path<V: FromLua>(&self, path: &str) -> Result<V>
Look up a value by a path of keys.
The syntax is similar to accessing nested tables in Lua, with additional support for
? operator to perform safe navigation.
For example, the path a[1].c is equivalent to table.a[1].c in Lua.
With ? operator, a[1]?.c is equivalent to table.a[1] and table.a[1].c or nil in Lua.
Bracket notation rules:
[123]- integer keys["string key"]or['string key']- string keys (must be quoted)- String keys support escape sequences:
\",\',\\
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.