Module restia.attributes
Implements OO-like “attributes” using metatables.
Info:
- License: Unlicense
- Author: DarkWiiPlayer
Functions
module.new (new) | Returns a pair of accessor tables and the object |
Functions
- module.new (new)
-
Returns a pair of accessor tables and the object
Parameters:
- new table The object to be proxied. If missing, a new table is created.
Returns:
- table get Table of getter methods
- table set Table of setter methods
- table new The new proxied object
Usage:
local get, set, obj = restia.attributes.new { foo = 1 } function set:bar(value) self.foo=value end function get:bar() return self.foo end obj.bar = 20 -- calls the setter method print(obj.bar) -- calls the getter method, prints 20 print(obj.foo) -- accesses the field directly, also prints 20 print(obj.baz) -- raises an unknown property error