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:

  1. table get Table of getter methods
  2. table set Table of setter methods
  3. 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
generated by LDoc 1.4.6 Last updated 2021-01-03 16:45:09