[added] call metamethod for classes so eg vec2:new(...) can be written as vec2(...)

This commit is contained in:
Max Cahill 2020-05-12 09:26:11 +10:00
parent 6f0945a675
commit 12e48d72ac

View File

@ -7,11 +7,17 @@
local function class(inherits)
local c = {}
c.__mt = {__index = c}
--handle single inheritence
if type(inherits) == "table" and inherits.__mt then
setmetatable(c, inherits.__mt)
end
c.__mt = {
__index = c,
}
setmetatable(c, {
--wire up call as ctor
__call = function(self, ...)
return self:new(...)
end,
--handle single inheritence
__index = inherits,
})
--common class functions
--internal initialisation
@ -42,6 +48,7 @@ local function class(inherits)
return inherits
end
--done
return c
end