function Class(base , ctor)
local c = {}
if not _ctor and type(base) == 'function' then
_ctor = base
base = nil
elseif type(base) =='table' then
for i,v in pairs(base) do
c[i] = v
end
c._base = base
end
c._index =c
mt ={}
mt.__call = function(class_tb1,...)
local obj = {}
setmetatable(obj,c)
if _ctor then
_ctor(obj,...)
end
return obj
end
c._ctor = _ctor
c.is_a = function(self , klass)
local m = getmetatable(self)
local index = 0
while m do
if m == klass then return true end
m = m._base;
index = index + 1
end
return false
end
setmetatable(c,mt)
return c
end
用这个写个用例 求教