Skip to main content

Crate lua_rs_derive

Crate lua_rs_derive 

Source
Expand description

Derive macros for the lua-rs embedding API.

  • #[derive(LuaUserData)] on a struct generates the UserData impl. Rust visibility is the scriptability boundary: public named fields are auto-exposed to Lua (obj.field reads/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). IntoLua comes for free from the runtime’s blanket impl<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 generated UserData also register the methods declared by #[lua_methods] on an impl block.
  • #[lua_methods] on an impl block exposes each pub fn(&self/&mut self, ...) to Lua as obj:method(args).

Attribute Macros§

lua_methods
Expose an impl block’s public methods to Lua as obj:method(args).

Derive Macros§

LuaUserData
Derive UserData for a struct: field access plus optional methods/metamethods.