Trait LuaObjectLike

Source
pub trait LuaObjectLike: Sealed {
    // Required methods
    fn get<V>(&self, key: impl IntoLua) -> Result<V, Error>
       where V: FromLua;
    fn set(&self, key: impl IntoLua, value: impl IntoLua) -> Result<(), Error>;
    fn call<R>(&self, args: impl IntoLuaMulti) -> Result<R, Error>
       where R: FromLuaMulti;
    fn call_method<R>(
        &self,
        name: &str,
        args: impl IntoLuaMulti,
    ) -> Result<R, Error>
       where R: FromLuaMulti;
    fn call_function<R>(
        &self,
        name: &str,
        args: impl IntoLuaMulti,
    ) -> Result<R, Error>
       where R: FromLuaMulti;
    fn to_string(&self) -> Result<String, Error>;
}
Expand description

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

Required Methods§

Source

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

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<(), Error>

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

Source

fn call<R>(&self, args: impl IntoLuaMulti) -> Result<R, Error>
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_method<R>( &self, name: &str, args: impl IntoLuaMulti, ) -> Result<R, Error>
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_function<R>( &self, name: &str, args: impl IntoLuaMulti, ) -> Result<R, Error>
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 to_string(&self) -> Result<String, Error>

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§