RoClass

Property

Property is a utility module in RoClass that allows you to define and manage class properties with custom behaviors.
It provides getter/setter functionality, default values, and property definitions for objects.


Table of Contents


Overview

The Property module provides tools to:


API

Property.add(target: table, name: string, definition: table | any): nil

Adds a property to a class or instance.


Examples

Adding a simple property

local Player = RoClass.new("Player")
    :constructor(function(self)
        self.Health = 100
    end)
    :build()

-- Add a property to an instance
RoClass.AddProp(Player, "Mana", 50)

local p1 = Player.new()
print(p1.Mana) -- 50

Adding a property with getter and setter

RoClass.AddProp(Player, "Health", {
    default = 100,
    get = function(self)
        return self._health
    end,
    set = function(self, value)
        self._health = math.clamp(value, 0, 100)
    end
})

local p1 = Player.new()
p1.Health = 150
print(p1.Health) -- 100, clamped


This documentation is part of RoClass. For more examples and detailed guides, see RoClass Docs.