function class(name, super)
local cls = nil
local stype = type(super)
if stype ~= "function" and stype ~= "table" then
stype = nil
super = nil
end
if super then
cls = i3k_clone(super)
cls.__super = super
else
cls = { ctor = function() end }
end
cls.__cname = name
cls.__index = cls
function cls.get_name()
return cls.__cname
end
function cls.get_super()
return cls.__super
end
function cls.new(...)
local inst = setmetatable({ }, cls)
inst.__class = cls
local bases = { }
local __super = cls.__super
while __super ~= nil do
table.insert(bases, __super)
__super = __super.__super
end
for k = #bases, 1, -1 do
local __super = bases[k]
if __super.ctor then
__super.ctor(inst, ...)
end
end
inst:ctor(...)
return inst
end
return cls
end
eg:
local cls_animals = class("animals")
local cls_dog = class("dog", cls_animals)