Last active
January 11, 2023 22:09
-
-
Save pablomayobre/98cde5497110bbeea8b729a48780a241 to your computer and use it in GitHub Desktop.
Minimal class approach for Lua based on Tjakka5 code https://github.com/tjakka5/Babble/blob/master/babble/src/class.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local function new (self, ...) | |
local obj = setmetatable({}, self) | |
if self.initialize then self.initialize(obj, ...) end | |
return obj | |
end | |
local mt = { __call = function (self, ...) | |
return self:new(...) | |
end } | |
return function(name) | |
local class = {name = name, new = new} | |
class.class = class | |
class.__index = class | |
return setmetatable(class, mt) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage: