Skip to main content

LuaUserData

Derive Macro LuaUserData 

Source
#[derive(LuaUserData)]
{
    // Attributes available to this derive:
    #[lua]
    #[lua_impl]
}
Expand description

Derive UserDataTrait for a struct, exposing public fields to Lua.

§Supported field types (auto-converted to/from UdValue)

  • i8..i64, isizeUdValue::Integer
  • u8..u64, usizeUdValue::Integer
  • f32, f64UdValue::Number
  • boolUdValue::Boolean
  • StringUdValue::Str

§Field attributes

  • #[lua(skip)] — exclude from Lua
  • #[lua(readonly)] — get only, no set
  • #[lua(name = "...")] — custom Lua name

§Struct attributes

  • #[lua_impl(Display, PartialEq, PartialOrd)] — metamethods from Rust traits

§Example

#[derive(LuaUserData, PartialEq, PartialOrd)]
#[lua_impl(Display, PartialEq, PartialOrd)]
struct Point {
    pub x: f64,
    pub y: f64,
    #[lua(skip)]
    internal_id: u32,
}