Trait nvim_utils::prelude::LuaUserDataFields
source · pub trait LuaUserDataFields<'lua, T>where
T: UserData,{
// Required methods
fn add_field_method_get<S, R, M>(&mut self, name: &S, method: M)
where S: AsRef<[u8]> + ?Sized,
R: ToLua<'lua>,
M: 'static + MaybeSend + Fn(&'lua Lua, &T) -> Result<R, Error>;
fn add_field_method_set<S, A, M>(&mut self, name: &S, method: M)
where S: AsRef<[u8]> + ?Sized,
A: FromLua<'lua>,
M: 'static + MaybeSend + FnMut(&'lua Lua, &mut T, A) -> Result<(), Error>;
fn add_field_function_get<S, R, F>(&mut self, name: &S, function: F)
where S: AsRef<[u8]> + ?Sized,
R: ToLua<'lua>,
F: 'static + MaybeSend + Fn(&'lua Lua, AnyUserData<'lua>) -> Result<R, Error>;
fn add_field_function_set<S, A, F>(&mut self, name: &S, function: F)
where S: AsRef<[u8]> + ?Sized,
A: FromLua<'lua>,
F: 'static + MaybeSend + FnMut(&'lua Lua, AnyUserData<'lua>, A) -> Result<(), Error>;
fn add_meta_field_with<S, R, F>(&mut self, meta: S, f: F)
where S: Into<MetaMethod>,
F: 'static + MaybeSend + Fn(&'lua Lua) -> Result<R, Error>,
R: ToLua<'lua>;
}Expand description
Field registry for UserData implementors.
Required Methods§
sourcefn add_field_method_get<S, R, M>(&mut self, name: &S, method: M)where
S: AsRef<[u8]> + ?Sized,
R: ToLua<'lua>,
M: 'static + MaybeSend + Fn(&'lua Lua, &T) -> Result<R, Error>,
fn add_field_method_get<S, R, M>(&mut self, name: &S, method: M)where S: AsRef<[u8]> + ?Sized, R: ToLua<'lua>, M: 'static + MaybeSend + Fn(&'lua Lua, &T) -> Result<R, Error>,
Add a regular field getter as a method which accepts a &T as the parameter.
Regular field getters are implemented by overriding the __index metamethod and returning the
accessed field. This allows them to be used with the expected userdata.field 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 field or method are found.
sourcefn add_field_method_set<S, A, M>(&mut self, name: &S, method: M)where
S: AsRef<[u8]> + ?Sized,
A: FromLua<'lua>,
M: 'static + MaybeSend + FnMut(&'lua Lua, &mut T, A) -> Result<(), Error>,
fn add_field_method_set<S, A, M>(&mut self, name: &S, method: M)where S: AsRef<[u8]> + ?Sized, A: FromLua<'lua>, M: 'static + MaybeSend + FnMut(&'lua Lua, &mut T, A) -> Result<(), Error>,
Add a regular field setter as a method which accepts a &mut T as the first parameter.
Regular field setters are implemented by overriding the __newindex metamethod and setting the
accessed field. This allows them to be used with the expected userdata.field = value syntax.
If add_meta_method is used to set the __newindex metamethod, the __newindex metamethod will
be used as a fall-back if no regular field is found.
sourcefn add_field_function_get<S, R, F>(&mut self, name: &S, function: F)where
S: AsRef<[u8]> + ?Sized,
R: ToLua<'lua>,
F: 'static + MaybeSend + Fn(&'lua Lua, AnyUserData<'lua>) -> Result<R, Error>,
fn add_field_function_get<S, R, F>(&mut self, name: &S, function: F)where S: AsRef<[u8]> + ?Sized, R: ToLua<'lua>, F: 'static + MaybeSend + Fn(&'lua Lua, AnyUserData<'lua>) -> Result<R, Error>,
Add a regular field getter as a function which accepts a generic AnyUserData of type T
argument.
Prefer to use add_field_method_get as it is easier to use.
sourcefn add_field_function_set<S, A, F>(&mut self, name: &S, function: F)where
S: AsRef<[u8]> + ?Sized,
A: FromLua<'lua>,
F: 'static + MaybeSend + FnMut(&'lua Lua, AnyUserData<'lua>, A) -> Result<(), Error>,
fn add_field_function_set<S, A, F>(&mut self, name: &S, function: F)where S: AsRef<[u8]> + ?Sized, A: FromLua<'lua>, F: 'static + MaybeSend + FnMut(&'lua Lua, AnyUserData<'lua>, A) -> Result<(), Error>,
Add a regular field setter as a function which accepts a generic AnyUserData of type T
first argument.
Prefer to use add_field_method_set as it is easier to use.
sourcefn add_meta_field_with<S, R, F>(&mut self, meta: S, f: F)where
S: Into<MetaMethod>,
F: 'static + MaybeSend + Fn(&'lua Lua) -> Result<R, Error>,
R: ToLua<'lua>,
fn add_meta_field_with<S, R, F>(&mut self, meta: S, f: F)where S: Into<MetaMethod>, F: 'static + MaybeSend + Fn(&'lua Lua) -> Result<R, Error>, R: ToLua<'lua>,
Add a metamethod value computed from f.
This will initialize the metamethod value from f on UserData creation.
Note
mlua will trigger an error on an attempt to define a protected metamethod,
like __gc or __metatable.