Skip to main content

LuaUserdata

Struct LuaUserdata 

Source
pub struct LuaUserdata { /* private fields */ }
Expand description

Userdata - arbitrary Rust data with optional metatable.

Uses Box<dyn UserDataTrait> for trait-based dispatch of field access, method calls, and metamethods. Falls back to metatable for Lua-level customization.

Implementations§

Source§

impl LuaUserdata

Source

pub fn new<T: UserDataTrait>(data: T) -> Self

Create a new userdata wrapping a value that implements UserDataTrait.

Source

pub fn from_boxed(data: Box<dyn UserDataTrait>) -> Self

Create a userdata from an already-boxed trait object.

Used by the VM to convert UdValue::UserdataOwned results from arithmetic trait methods into GC-managed userdata.

Source

pub unsafe fn from_ref<T: UserDataTrait>(reference: &mut T) -> Self

Create a borrowed userdata from a mutable reference.

The resulting userdata forwards all field/method/metamethod access through a raw pointer — zero overhead, no ownership transfer.

§Safety

The referenced object must outlive all Lua accesses to this userdata. Accessing the userdata after the Rust object is dropped is undefined behavior.

Source

pub unsafe fn from_raw_ptr<T: UserDataTrait>(ptr: *mut T) -> Self

Create a borrowed userdata from a raw pointer.

§Safety

The pointer must be valid and properly aligned for the entire duration that Lua can access this userdata.

Source

pub fn with_metatable<T: UserDataTrait>(data: T, metatable: TablePtr) -> Self

Create a new userdata with an initial metatable.

Source

pub fn get_trait(&self) -> &dyn UserDataTrait

Get the trait object for direct field/method/metamethod dispatch.

Source

pub fn get_trait_mut(&mut self) -> &mut dyn UserDataTrait

Get the mutable trait object.

Source

pub fn type_name(&self) -> &'static str

Get the type name from the trait.

Source

pub fn downcast_ref<T: 'static>(&self) -> Option<&T>

Downcast to a concrete type (immutable). Equivalent to old get_data().downcast_ref::<T>().

Source

pub fn downcast_mut<T: 'static>(&mut self) -> Option<&mut T>

Downcast to a concrete type (mutable). Equivalent to old get_data_mut().downcast_mut::<T>().

Source

pub fn get_data(&self) -> &dyn Any

Get raw &dyn Any reference (backward compatibility).

Source

pub fn get_data_mut(&mut self) -> &mut dyn Any

Get raw &mut dyn Any reference (backward compatibility).

Source

pub fn get_metatable(&self) -> Option<LuaValue>

Trait Implementations§

Source§

impl Debug for LuaUserdata

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<LuaUserdata> for AsyncReturnValue

Source§

fn from(ud: LuaUserdata) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

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> LuaMethodProvider for T

Source§

impl<T> LuaStaticMethodProvider for T

Source§

fn __lua_static_methods() -> &'static [(&'static str, CFunction)]

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.