Trait rlua::UserDataMethods [−][src]
pub trait UserDataMethods<'lua, T: UserData> { fn add_method<A, R, M>(&mut self, name: &str, method: M)
where
A: FromLuaMulti<'lua>,
R: ToLuaMulti<'lua>,
M: 'static + Send + Fn(&'lua Lua, &T, A) -> Result<R>; fn add_method_mut<A, R, M>(&mut self, name: &str, method: M)
where
A: FromLuaMulti<'lua>,
R: ToLuaMulti<'lua>,
M: 'static + Send + FnMut(&'lua Lua, &mut T, A) -> Result<R>; fn add_function<A, R, F>(&mut self, name: &str, function: F)
where
A: FromLuaMulti<'lua>,
R: ToLuaMulti<'lua>,
F: 'static + Send + Fn(&'lua Lua, A) -> Result<R>; fn add_function_mut<A, R, F>(&mut self, name: &str, function: F)
where
A: FromLuaMulti<'lua>,
R: ToLuaMulti<'lua>,
F: 'static + Send + FnMut(&'lua Lua, A) -> Result<R>; fn add_meta_method<A, R, M>(&mut self, meta: MetaMethod, method: M)
where
A: FromLuaMulti<'lua>,
R: ToLuaMulti<'lua>,
M: 'static + Send + Fn(&'lua Lua, &T, A) -> Result<R>; fn add_meta_method_mut<A, R, M>(&mut self, meta: MetaMethod, method: M)
where
A: FromLuaMulti<'lua>,
R: ToLuaMulti<'lua>,
M: 'static + Send + FnMut(&'lua Lua, &mut T, A) -> Result<R>; fn add_meta_function<A, R, F>(&mut self, meta: MetaMethod, function: F)
where
A: FromLuaMulti<'lua>,
R: ToLuaMulti<'lua>,
F: 'static + Send + Fn(&'lua Lua, A) -> Result<R>; fn add_meta_function_mut<A, R, F>(&mut self, meta: MetaMethod, function: F)
where
A: FromLuaMulti<'lua>,
R: ToLuaMulti<'lua>,
F: 'static + Send + FnMut(&'lua Lua, A) -> Result<R>; }
Method registry for UserData
implementors.
Required Methods
fn add_method<A, R, M>(&mut self, name: &str, method: M) where
A: FromLuaMulti<'lua>,
R: ToLuaMulti<'lua>,
M: 'static + Send + Fn(&'lua Lua, &T, A) -> Result<R>,
A: FromLuaMulti<'lua>,
R: ToLuaMulti<'lua>,
M: 'static + Send + Fn(&'lua Lua, &T, A) -> Result<R>,
Add a method which accepts a &T
as the first parameter.
Regular methods are implemented by overriding the __index
metamethod and returning the
accessed method. This allows them to be used with the expected userdata:method()
syntax.
If add_meta_method
is used to set the __index
metamethod, the __index
metamethod will
be used as a fall-back if no regular method is found.
fn add_method_mut<A, R, M>(&mut self, name: &str, method: M) where
A: FromLuaMulti<'lua>,
R: ToLuaMulti<'lua>,
M: 'static + Send + FnMut(&'lua Lua, &mut T, A) -> Result<R>,
A: FromLuaMulti<'lua>,
R: ToLuaMulti<'lua>,
M: 'static + Send + FnMut(&'lua Lua, &mut T, A) -> Result<R>,
Add a regular method which accepts a &mut T
as the first parameter.
Refer to add_method
for more information about the implementation.
fn add_function<A, R, F>(&mut self, name: &str, function: F) where
A: FromLuaMulti<'lua>,
R: ToLuaMulti<'lua>,
F: 'static + Send + Fn(&'lua Lua, A) -> Result<R>,
A: FromLuaMulti<'lua>,
R: ToLuaMulti<'lua>,
F: 'static + Send + Fn(&'lua Lua, A) -> Result<R>,
Add a regular method as a function which accepts generic arguments, the first argument will
always be a UserData
of type T.
Prefer to use add_method
or add_method_mut
as they are easier to use.
fn add_function_mut<A, R, F>(&mut self, name: &str, function: F) where
A: FromLuaMulti<'lua>,
R: ToLuaMulti<'lua>,
F: 'static + Send + FnMut(&'lua Lua, A) -> Result<R>,
A: FromLuaMulti<'lua>,
R: ToLuaMulti<'lua>,
F: 'static + Send + FnMut(&'lua Lua, A) -> Result<R>,
Add a regular method as a mutable function which accepts generic arguments, the first
argument will always be a UserData
of type T.
This is a version of add_function
that accepts a FnMut argument.
fn add_meta_method<A, R, M>(&mut self, meta: MetaMethod, method: M) where
A: FromLuaMulti<'lua>,
R: ToLuaMulti<'lua>,
M: 'static + Send + Fn(&'lua Lua, &T, A) -> Result<R>,
A: FromLuaMulti<'lua>,
R: ToLuaMulti<'lua>,
M: 'static + Send + Fn(&'lua Lua, &T, A) -> Result<R>,
Add a metamethod which accepts a &T
as the first parameter.
Note
This can cause an error with certain binary metamethods that can trigger if only the right
side has a metatable. To prevent this, use add_meta_function
.
fn add_meta_method_mut<A, R, M>(&mut self, meta: MetaMethod, method: M) where
A: FromLuaMulti<'lua>,
R: ToLuaMulti<'lua>,
M: 'static + Send + FnMut(&'lua Lua, &mut T, A) -> Result<R>,
A: FromLuaMulti<'lua>,
R: ToLuaMulti<'lua>,
M: 'static + Send + FnMut(&'lua Lua, &mut T, A) -> Result<R>,
Add a metamethod as a function which accepts a &mut T
as the first parameter.
Note
This can cause an error with certain binary metamethods that can trigger if only the right
side has a metatable. To prevent this, use add_meta_function
.
fn add_meta_function<A, R, F>(&mut self, meta: MetaMethod, function: F) where
A: FromLuaMulti<'lua>,
R: ToLuaMulti<'lua>,
F: 'static + Send + Fn(&'lua Lua, A) -> Result<R>,
A: FromLuaMulti<'lua>,
R: ToLuaMulti<'lua>,
F: 'static + Send + Fn(&'lua Lua, A) -> Result<R>,
Add a metamethod which accepts generic arguments.
Metamethods for binary operators can be triggered if either the left or right argument to
the binary operator has a metatable, so the first argument here is not necessarily a
userdata of type T
.
fn add_meta_function_mut<A, R, F>(&mut self, meta: MetaMethod, function: F) where
A: FromLuaMulti<'lua>,
R: ToLuaMulti<'lua>,
F: 'static + Send + FnMut(&'lua Lua, A) -> Result<R>,
A: FromLuaMulti<'lua>,
R: ToLuaMulti<'lua>,
F: 'static + Send + FnMut(&'lua Lua, A) -> Result<R>,
Add a metamethod as a mutable function which accepts generic arguments.
This is a version of add_meta_function
that accepts a FnMut argument.