Expand description
Derive macros for the lua-rs embedding API.
#[derive(LuaUserData)]on a struct generates theUserDataimpl. Rust visibility is the scriptability boundary: public named fields are auto-exposed to Lua (obj.fieldreads/writes); private fields stay encapsulated unless force-exposed with#[lua(field)]. Tuple/newtype and unit structs (struct Handle(App);) expose no fields and become opaque userdata handles — ready for#[lua(methods)]and metamethods. Field attributes:#[lua(skip)],#[lua(readonly)],#[lua(name = "...")],#[lua(field)](force-expose a private field).IntoLuacomes for free from the runtime’s blanketimpl<T: UserData> IntoLua for T.- Struct attribute
#[lua_impl(Display, PartialEq, PartialOrd)]wires the matching metamethods (__tostring,__eq,__lt/__le) from the type’s Rust trait impls. - Struct attribute
#[lua(methods)]makes the generatedUserDataalso register the methods declared by#[lua_methods]on animplblock. #[lua_methods]on animplblock exposes eachpub fn(&self/&mut self, ...)to Lua asobj:method(args).
Attribute Macros§
- lua_
methods - Expose an
implblock’s public methods to Lua asobj:method(args).
Derive Macros§
- LuaUser
Data - Derive
UserDatafor a struct: field access plus optional methods/metamethods.