classModule
Minimal class helper for the OOP-style modules (e.g.
socket.inet, socket.unix). Calling the module on a table makes it an instantiable class: it gains a:new constructor that wires __index/__close and sets the
class as the metatable of new objects, serving both to build instances and to
derive specializations (subclasses that inherit the methods).
Usage
local class = require("class")
local Point = class{}
function Point:sum() return self.x + self.y end
local point <close> = Point:new{x = 1, y = 2} -- point:sum() == 3
Functions
| class ([class]) | Makes class an instantiable class by attaching the shared :new. |
Functions in detail
- class ([class])
-
Makes class an instantiable class by attaching the shared
:new.class:new(o)sets__indexand__closeon the class, the latter fromcloseas it is at that call, then makes the class the metatable ofo.Parameters
- class table the class table (defaults to a fresh table). (optional)
Returns
-
table
the same table, ready to receive methods and be instantiated.