Skip to main content

MetatableBuilder

Struct MetatableBuilder 

Source
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>

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,

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,

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,

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,

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,

Mutable variant of add_meta_method.
Source§

fn add_field_method_get<F, R>(&mut self, name: &str, f: F)
where F: Fn(&mut Vm, &T) -> Result<R, LuaError> + Copy + 'static, R: IntoLuaReturn + 'static,

Field-getter sugar: equivalent to add_method with no args and a single-value return. Read more
Source§

fn add_field_method_set<F, A>(&mut self, name: &str, f: F)
where F: Fn(&mut Vm, &mut T, A) -> Result<(), LuaError> + Copy + 'static, A: FromLuaArgs + 'static,

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.