function class(super)
local mt = {__call = function(_c, ...)
local function create(_c, _o, ...)
if _c.__super then create(_c.__super, _o, ...) end
if _c.__ctor then _c.__ctor(_o, ...) end
return _o
end
local _o = create(_c, {}, ...)
return setmetatable(_o, _c)
end}
mt.__index = super or mt
return setmetatable({__super = super}, mt)
end
----------------------------------------------------------------------
a = class()
function a:__ctor(s)
self.i = 123
self.j = 333
print('a ctor', s)
end
local a = a('a')
print(a.i, a.j)
-- b继承a
b = class(a)
function b:__ctor(s)
self.i = 444
print('b ctor', s)
end
local b = b('b')
print(b.i, b.j)
用户登录
还没有账号?立即注册
用户注册
投稿取消
| 文章分类: |
|
还能输入300字
上传中....
切克闹21628686