Trait me3_framework::scripting::lua::prelude::LuaUserDataMethods
source · [−]pub trait LuaUserDataMethods<'lua, T>where
T: UserData,{
fn add_method<S, A, R, M>(&mut self, name: &S, method: M)
where
S: AsRef<[u8]> + ?Sized,
A: FromLuaMulti<'lua>,
R: ToLuaMulti<'lua>,
M: 'static + MaybeSend + Fn(&'lua Lua, &T, A) -> Result<R, Error>;
fn add_method_mut<S, A, R, M>(&mut self, name: &S, method: M)
where
S: AsRef<[u8]> + ?Sized,
A: FromLuaMulti<'lua>,
R: ToLuaMulti<'lua>,
M: 'static + MaybeSend + FnMut(&'lua Lua, &mut T, A) -> Result<R, Error>;
fn add_async_method<S, A, R, M, MR>(&mut self, name: &S, method: M)
where
T: Clone,
S: AsRef<[u8]> + ?Sized,
A: FromLuaMulti<'lua>,
R: ToLuaMulti<'lua>,
M: 'static + MaybeSend + Fn(&'lua Lua, T, A) -> MR,
MR: 'lua + Future<Output = Result<R, Error>>;
fn add_function<S, A, R, F>(&mut self, name: &S, function: F)
where
S: AsRef<[u8]> + ?Sized,
A: FromLuaMulti<'lua>,
R: ToLuaMulti<'lua>,
F: 'static + MaybeSend + Fn(&'lua Lua, A) -> Result<R, Error>;
fn add_function_mut<S, A, R, F>(&mut self, name: &S, function: F)
where
S: AsRef<[u8]> + ?Sized,
A: FromLuaMulti<'lua>,
R: ToLuaMulti<'lua>,
F: 'static + MaybeSend + FnMut(&'lua Lua, A) -> Result<R, Error>;
fn add_async_function<S, A, R, F, FR>(&mut self, name: &S, function: F)
where
S: AsRef<[u8]> + ?Sized,
A: FromLuaMulti<'lua>,
R: ToLuaMulti<'lua>,
F: 'static + MaybeSend + Fn(&'lua Lua, A) -> FR,
FR: 'lua + Future<Output = Result<R, Error>>;
fn add_meta_method<S, A, R, M>(&mut self, meta: S, method: M)
where
S: Into<MetaMethod>,
A: FromLuaMulti<'lua>,
R: ToLuaMulti<'lua>,
M: 'static + MaybeSend + Fn(&'lua Lua, &T, A) -> Result<R, Error>;
fn add_meta_method_mut<S, A, R, M>(&mut self, meta: S, method: M)
where
S: Into<MetaMethod>,
A: FromLuaMulti<'lua>,
R: ToLuaMulti<'lua>,
M: 'static + MaybeSend + FnMut(&'lua Lua, &mut T, A) -> Result<R, Error>;
fn add_meta_function<S, A, R, F>(&mut self, meta: S, function: F)
where
S: Into<MetaMethod>,
A: FromLuaMulti<'lua>,
R: ToLuaMulti<'lua>,
F: 'static + MaybeSend + Fn(&'lua Lua, A) -> Result<R, Error>;
fn add_meta_function_mut<S, A, R, F>(&mut self, meta: S, function: F)
where
S: Into<MetaMethod>,
A: FromLuaMulti<'lua>,
R: ToLuaMulti<'lua>,
F: 'static + MaybeSend + FnMut(&'lua Lua, A) -> Result<R, Error>;
}
Expand description
Method registry for UserData
implementors.
Required Methods
sourcefn add_method<S, A, R, M>(&mut self, name: &S, method: M)where
S: AsRef<[u8]> + ?Sized,
A: FromLuaMulti<'lua>,
R: ToLuaMulti<'lua>,
M: 'static + MaybeSend + Fn(&'lua Lua, &T, A) -> Result<R, Error>,
fn add_method<S, A, R, M>(&mut self, name: &S, method: M)where
S: AsRef<[u8]> + ?Sized,
A: FromLuaMulti<'lua>,
R: ToLuaMulti<'lua>,
M: 'static + MaybeSend + Fn(&'lua Lua, &T, A) -> Result<R, Error>,
Add a regular 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.
sourcefn add_method_mut<S, A, R, M>(&mut self, name: &S, method: M)where
S: AsRef<[u8]> + ?Sized,
A: FromLuaMulti<'lua>,
R: ToLuaMulti<'lua>,
M: 'static + MaybeSend + FnMut(&'lua Lua, &mut T, A) -> Result<R, Error>,
fn add_method_mut<S, A, R, M>(&mut self, name: &S, method: M)where
S: AsRef<[u8]> + ?Sized,
A: FromLuaMulti<'lua>,
R: ToLuaMulti<'lua>,
M: 'static + MaybeSend + FnMut(&'lua Lua, &mut T, A) -> Result<R, Error>,
Add a regular method which accepts a &mut T
as the first parameter.
Refer to add_method
for more information about the implementation.
sourcefn add_async_method<S, A, R, M, MR>(&mut self, name: &S, method: M)where
T: Clone,
S: AsRef<[u8]> + ?Sized,
A: FromLuaMulti<'lua>,
R: ToLuaMulti<'lua>,
M: 'static + MaybeSend + Fn(&'lua Lua, T, A) -> MR,
MR: 'lua + Future<Output = Result<R, Error>>,
fn add_async_method<S, A, R, M, MR>(&mut self, name: &S, method: M)where
T: Clone,
S: AsRef<[u8]> + ?Sized,
A: FromLuaMulti<'lua>,
R: ToLuaMulti<'lua>,
M: 'static + MaybeSend + Fn(&'lua Lua, T, A) -> MR,
MR: 'lua + Future<Output = Result<R, Error>>,
Add an async method which accepts a T
as the first parameter and returns Future.
The passed T
is cloned from the original value.
Refer to add_method
for more information about the implementation.
Requires feature = "async"
sourcefn add_function<S, A, R, F>(&mut self, name: &S, function: F)where
S: AsRef<[u8]> + ?Sized,
A: FromLuaMulti<'lua>,
R: ToLuaMulti<'lua>,
F: 'static + MaybeSend + Fn(&'lua Lua, A) -> Result<R, Error>,
fn add_function<S, A, R, F>(&mut self, name: &S, function: F)where
S: AsRef<[u8]> + ?Sized,
A: FromLuaMulti<'lua>,
R: ToLuaMulti<'lua>,
F: 'static + MaybeSend + Fn(&'lua Lua, A) -> Result<R, Error>,
Add a regular method as a function which accepts generic arguments, the first argument will
be a AnyUserData
of type T
if the method is called with Lua method syntax:
my_userdata:my_method(arg1, arg2)
, or it is passed in as the first argument:
my_userdata.my_method(my_userdata, arg1, arg2)
.
Prefer to use add_method
or add_method_mut
as they are easier to use.
sourcefn add_function_mut<S, A, R, F>(&mut self, name: &S, function: F)where
S: AsRef<[u8]> + ?Sized,
A: FromLuaMulti<'lua>,
R: ToLuaMulti<'lua>,
F: 'static + MaybeSend + FnMut(&'lua Lua, A) -> Result<R, Error>,
fn add_function_mut<S, A, R, F>(&mut self, name: &S, function: F)where
S: AsRef<[u8]> + ?Sized,
A: FromLuaMulti<'lua>,
R: ToLuaMulti<'lua>,
F: 'static + MaybeSend + FnMut(&'lua Lua, A) -> Result<R, Error>,
Add a regular method as a mutable function which accepts generic arguments.
This is a version of add_function
that accepts a FnMut argument.
sourcefn add_async_function<S, A, R, F, FR>(&mut self, name: &S, function: F)where
S: AsRef<[u8]> + ?Sized,
A: FromLuaMulti<'lua>,
R: ToLuaMulti<'lua>,
F: 'static + MaybeSend + Fn(&'lua Lua, A) -> FR,
FR: 'lua + Future<Output = Result<R, Error>>,
fn add_async_function<S, A, R, F, FR>(&mut self, name: &S, function: F)where
S: AsRef<[u8]> + ?Sized,
A: FromLuaMulti<'lua>,
R: ToLuaMulti<'lua>,
F: 'static + MaybeSend + Fn(&'lua Lua, A) -> FR,
FR: 'lua + Future<Output = Result<R, Error>>,
Add a regular method as an async function which accepts generic arguments and returns Future.
This is an async version of add_function
.
Requires feature = "async"
sourcefn add_meta_method<S, A, R, M>(&mut self, meta: S, method: M)where
S: Into<MetaMethod>,
A: FromLuaMulti<'lua>,
R: ToLuaMulti<'lua>,
M: 'static + MaybeSend + Fn(&'lua Lua, &T, A) -> Result<R, Error>,
fn add_meta_method<S, A, R, M>(&mut self, meta: S, method: M)where
S: Into<MetaMethod>,
A: FromLuaMulti<'lua>,
R: ToLuaMulti<'lua>,
M: 'static + MaybeSend + Fn(&'lua Lua, &T, A) -> Result<R, Error>,
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
.
sourcefn add_meta_method_mut<S, A, R, M>(&mut self, meta: S, method: M)where
S: Into<MetaMethod>,
A: FromLuaMulti<'lua>,
R: ToLuaMulti<'lua>,
M: 'static + MaybeSend + FnMut(&'lua Lua, &mut T, A) -> Result<R, Error>,
fn add_meta_method_mut<S, A, R, M>(&mut self, meta: S, method: M)where
S: Into<MetaMethod>,
A: FromLuaMulti<'lua>,
R: ToLuaMulti<'lua>,
M: 'static + MaybeSend + FnMut(&'lua Lua, &mut T, A) -> Result<R, Error>,
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
.
sourcefn add_meta_function<S, A, R, F>(&mut self, meta: S, function: F)where
S: Into<MetaMethod>,
A: FromLuaMulti<'lua>,
R: ToLuaMulti<'lua>,
F: 'static + MaybeSend + Fn(&'lua Lua, A) -> Result<R, Error>,
fn add_meta_function<S, A, R, F>(&mut self, meta: S, function: F)where
S: Into<MetaMethod>,
A: FromLuaMulti<'lua>,
R: ToLuaMulti<'lua>,
F: 'static + MaybeSend + Fn(&'lua Lua, A) -> Result<R, Error>,
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
.
sourcefn add_meta_function_mut<S, A, R, F>(&mut self, meta: S, function: F)where
S: Into<MetaMethod>,
A: FromLuaMulti<'lua>,
R: ToLuaMulti<'lua>,
F: 'static + MaybeSend + FnMut(&'lua Lua, A) -> Result<R, Error>,
fn add_meta_function_mut<S, A, R, F>(&mut self, meta: S, function: F)where
S: Into<MetaMethod>,
A: FromLuaMulti<'lua>,
R: ToLuaMulti<'lua>,
F: 'static + MaybeSend + FnMut(&'lua Lua, A) -> Result<R, Error>,
Add a metamethod as a mutable function which accepts generic arguments.
This is a version of add_meta_function
that accepts a FnMut argument.