Trait ObjectLike

Source
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,
    ) -> impl Future<Output = Result<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,
    ) -> impl Future<Output = Result<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,
    ) -> impl Future<Output = Result<R>>
       where R: FromLuaMulti;
    fn to_string(&self) -> Result<StdString>;
}
Expand description

A trait for types that can be used as Lua objects (usually table and userdata).

Required Methods§

Source

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

Gets the value associated to key from the object, assuming it has __index metamethod.

Source

fn set(&self, key: impl IntoLua, value: impl IntoLua) -> Result<()>

Sets the value associated to key in the object, assuming it has __newindex metamethod.

Source

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.

Source

fn call_async<R>( &self, args: impl IntoLuaMulti, ) -> impl Future<Output = Result<R>>
where R: FromLuaMulti,

Available on crate feature 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.

Source

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.

Source

fn call_async_method<R>( &self, name: &str, args: impl IntoLuaMulti, ) -> impl Future<Output = Result<R>>
where R: FromLuaMulti,

Available on crate feature 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.

Requires feature = "async"

This might invoke the __index metamethod.

Source

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.

Source

fn call_async_function<R>( &self, name: &str, args: impl IntoLuaMulti, ) -> impl Future<Output = Result<R>>
where R: FromLuaMulti,

Available on crate feature async only.

Gets the function associated to key name from the object and asynchronously calls it, passing args as function arguments.

Requires feature = "async"

This might invoke the __index metamethod.

Source

fn to_string(&self) -> Result<StdString>

Converts the object to a string in a human-readable format.

This might invoke the __tostring metamethod.

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.

Implementors§