Skip to main content

UserDataMethods

Trait UserDataMethods 

Source
pub trait UserDataMethods<T: UserData> {
    // Required methods
    fn add_method<A, R, F>(&mut self, name: &str, method: F)
       where A: FromLuaMulti + 'static,
             R: IntoLuaMulti + 'static,
             F: Fn(&Lua, &T, A) -> Result<R> + 'static;
    fn add_method_mut<A, R, F>(&mut self, name: &str, method: F)
       where A: FromLuaMulti + 'static,
             R: IntoLuaMulti + 'static,
             F: Fn(&Lua, &mut T, A) -> Result<R> + 'static;
    fn add_meta_method<A, R, F>(&mut self, metamethod: MetaMethod, method: F)
       where A: FromLuaMulti + 'static,
             R: IntoLuaMulti + 'static,
             F: Fn(&Lua, &T, A) -> Result<R> + 'static;
    fn add_meta_method_mut<A, R, F>(
        &mut self,
        metamethod: MetaMethod,
        method: F,
    )
       where A: FromLuaMulti + 'static,
             R: IntoLuaMulti + 'static,
             F: Fn(&Lua, &mut T, A) -> Result<R> + 'static;
    fn add_field_method_get<R, F>(&mut self, name: &str, getter: F)
       where R: IntoLuaMulti + 'static,
             F: Fn(&Lua, &T) -> Result<R> + 'static;
    fn add_field_method_set<A, F>(&mut self, name: &str, setter: F)
       where A: FromLuaMulti + 'static,
             F: Fn(&Lua, &mut T, A) -> Result<()> + 'static;
    fn add_function<A, R, F>(&mut self, name: &str, function: F)
       where A: FromLuaMulti + 'static,
             R: IntoLuaMulti + 'static,
             F: Fn(&Lua, A) -> Result<R> + 'static;
    fn add_function_mut<A, R, F>(&mut self, name: &str, function: F)
       where A: FromLuaMulti + 'static,
             R: IntoLuaMulti + 'static,
             F: FnMut(&Lua, A) -> Result<R> + 'static;
}

Required Methods§

Source

fn add_method<A, R, F>(&mut self, name: &str, method: F)
where A: FromLuaMulti + 'static, R: IntoLuaMulti + 'static, F: Fn(&Lua, &T, A) -> Result<R> + 'static,

Source

fn add_method_mut<A, R, F>(&mut self, name: &str, method: F)
where A: FromLuaMulti + 'static, R: IntoLuaMulti + 'static, F: Fn(&Lua, &mut T, A) -> Result<R> + 'static,

Source

fn add_meta_method<A, R, F>(&mut self, metamethod: MetaMethod, method: F)
where A: FromLuaMulti + 'static, R: IntoLuaMulti + 'static, F: Fn(&Lua, &T, A) -> Result<R> + 'static,

Source

fn add_meta_method_mut<A, R, F>(&mut self, metamethod: MetaMethod, method: F)
where A: FromLuaMulti + 'static, R: IntoLuaMulti + 'static, F: Fn(&Lua, &mut T, A) -> Result<R> + 'static,

Source

fn add_field_method_get<R, F>(&mut self, name: &str, getter: F)
where R: IntoLuaMulti + 'static, F: Fn(&Lua, &T) -> Result<R> + 'static,

Register a getter for obj.name. The runtime composes all field getters, the method table, and any raw __index into a single __index so fields and methods coexist (lookup order: field, then method, then raw __index).

Source

fn add_field_method_set<A, F>(&mut self, name: &str, setter: F)
where A: FromLuaMulti + 'static, F: Fn(&Lua, &mut T, A) -> Result<()> + 'static,

Register a setter for obj.name = value. Assigning a field with no setter (or an unknown field) errors unless a raw __newindex handles it.

Source

fn add_function<A, R, F>(&mut self, name: &str, function: F)
where A: FromLuaMulti + 'static, R: IntoLuaMulti + 'static, F: Fn(&Lua, A) -> Result<R> + 'static,

Register a “function-shape” method whose callback does not extract the typed &T automatically. The userdata handle (and any other args) is passed to the closure as a regular FromLuaMulti tuple, so A is usually (AnyUserData, X, Y, ...).

Equivalent to mlua’s UserDataMethods::add_function. The main reason to reach for this over Self::add_method is when the callback body needs the AnyUserData handle for the receiver — most commonly to build a sub-userdata via AnyUserData::delegate.

Source

fn add_function_mut<A, R, F>(&mut self, name: &str, function: F)
where A: FromLuaMulti + 'static, R: IntoLuaMulti + 'static, F: FnMut(&Lua, A) -> Result<R> + 'static,

FnMut variant of Self::add_function. Re-entrant calls into the same closure are rejected with an “already borrowed” runtime error.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§