pub struct MetatableBuilder<'vm, T> { /* private fields */ }Expand description
Concrete builder that emits a Gc<Table> metatable for T.
Created internally by Vm::register_userdata; embedders never
name this type.
Trait Implementations§
Source§impl<'vm, T: LuaUserdata> UserdataMethods<T> for MetatableBuilder<'vm, T>
impl<'vm, T: LuaUserdata> UserdataMethods<T> for MetatableBuilder<'vm, T>
Source§fn add_method<F, A, R>(&mut self, name: &str, f: F)where
F: Fn(&mut Vm, &T, A) -> Result<R, LuaError> + Copy + 'static,
A: FromLuaArgs + 'static,
R: IntoLuaReturn + 'static,
fn add_method<F, A, R>(&mut self, name: &str, f: F)where
F: Fn(&mut Vm, &T, A) -> Result<R, LuaError> + Copy + 'static,
A: FromLuaArgs + 'static,
R: IntoLuaReturn + 'static,
Register a regular method bound to
__index[name] on the
generated metatable; method lookup u:name(args) resolves
through Lua’s normal __index table dispatch.Source§fn add_method_mut<F, A, R>(&mut self, name: &str, f: F)where
F: Fn(&mut Vm, &mut T, A) -> Result<R, LuaError> + Copy + 'static,
A: FromLuaArgs + 'static,
R: IntoLuaReturn + 'static,
fn add_method_mut<F, A, R>(&mut self, name: &str, f: F)where
F: Fn(&mut Vm, &mut T, A) -> Result<R, LuaError> + Copy + 'static,
A: FromLuaArgs + 'static,
R: IntoLuaReturn + 'static,
Mutable variant of
add_method. The
&mut T borrow is exclusive within the call window; an
embedder must not concurrently userdata_borrow_mut the same
payload through another path during the method body.Source§fn add_function<F, A, R>(&mut self, name: &str, f: F)where
F: Fn(&mut Vm, A) -> Result<R, LuaError> + Copy + 'static,
A: FromLuaArgs + 'static,
R: IntoLuaReturn + 'static,
fn add_function<F, A, R>(&mut self, name: &str, f: F)where
F: Fn(&mut Vm, A) -> Result<R, LuaError> + Copy + 'static,
A: FromLuaArgs + 'static,
R: IntoLuaReturn + 'static,
Register a static-style function (no implicit receiver). Bound
directly on the metatable, not under
__index, so it is
reachable as Vec3.new(...) after vm.set_global("Vec3", mt).Source§fn add_meta_method<F, A, R>(&mut self, meta: MetaMethod, f: F)where
F: Fn(&mut Vm, &T, A) -> Result<R, LuaError> + Copy + 'static,
A: FromLuaArgs + 'static,
R: IntoLuaReturn + 'static,
fn add_meta_method<F, A, R>(&mut self, meta: MetaMethod, f: F)where
F: Fn(&mut Vm, &T, A) -> Result<R, LuaError> + Copy + 'static,
A: FromLuaArgs + 'static,
R: IntoLuaReturn + 'static,
Register a metamethod (
__add / __tostring / …). Stored
directly on the metatable; the dispatcher’s existing
get_mm path resolves it.Source§fn add_meta_method_mut<F, A, R>(&mut self, meta: MetaMethod, f: F)where
F: Fn(&mut Vm, &mut T, A) -> Result<R, LuaError> + Copy + 'static,
A: FromLuaArgs + 'static,
R: IntoLuaReturn + 'static,
fn add_meta_method_mut<F, A, R>(&mut self, meta: MetaMethod, f: F)where
F: Fn(&mut Vm, &mut T, A) -> Result<R, LuaError> + Copy + 'static,
A: FromLuaArgs + 'static,
R: IntoLuaReturn + 'static,
Mutable variant of
add_meta_method.Source§fn add_field_method_get<F, R>(&mut self, name: &str, f: F)
fn add_field_method_get<F, R>(&mut self, name: &str, f: F)
Field-getter sugar: equivalent to
add_method
with no args and a single-value return. Read moreSource§fn add_field_method_set<F, A>(&mut self, name: &str, f: F)
fn add_field_method_set<F, A>(&mut self, name: &str, f: F)
Field-setter sugar: registers a setter for
obj.name = value
(v1.3 UD1). When any add_field_method_set is registered,
MetatableBuilder installs a __newindex trampoline that
dispatches (self, value) to the registered setter. Unknown
fields raise a runtime error rather than silently dropping the
write (matches code/no-unsolicited-fallback).Auto Trait Implementations§
impl<'vm, T> !RefUnwindSafe for MetatableBuilder<'vm, T>
impl<'vm, T> !Send for MetatableBuilder<'vm, T>
impl<'vm, T> !Sync for MetatableBuilder<'vm, T>
impl<'vm, T> !UnwindSafe for MetatableBuilder<'vm, T>
impl<'vm, T> Freeze for MetatableBuilder<'vm, T>
impl<'vm, T> Unpin for MetatableBuilder<'vm, T>
impl<'vm, T> UnsafeUnpin for MetatableBuilder<'vm, T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more