I use a slightly different function for class inheritance which requires a little less typing but it is essentially equivalent to ZO_Object
Code:
local function class(base)
local c = {}
if type(base) == "table" then
for k,v in pairs(base) do
c[k]=v
end
c.base = base
end
c.__index = c
setmetatable(c,{ __call=function(self,...)
-- create instance
local obj = setmetatable({},c)
if self.init then
self.init(obj,...)
elseif base ~= nil and base.init ~= nil then
base.init(obj,...)
end
return obj
end
})
return c
end
Usage
Code:
-- class
local Animal = class()
function Animal:init()
end
-- subclass
local Dog = class(Animal)
function Dog:init()
self.base.init(self)
end
-- create new object instance
local dog1 = Dog()