mirror of
https://github.com/1bardesign/batteries.git
synced 2024-11-10 02:31:48 +00:00
[added] call metamethod for classes so eg vec2:new(...) can be written as vec2(...)
This commit is contained in:
parent
6f0945a675
commit
12e48d72ac
17
class.lua
17
class.lua
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user