local A = {}
A.__index = A
function A:new(o)
o = o or {}
setmetatable(o,A);
return o
end
function A:test()
print("test A")
end
local B = {}
setmetatable(B,A)
B.__index = B
function B:new(o)
local self = A:new(o)
setmetatable(self,B);
return self
end
-- 重写父类
--function B:test()
-- print("test B")
--end
local a = A:new()
a:test()
local b = B:new()
b:test()
lua setmetatable 实现继承
最新推荐文章于 2024-12-13 08:30:00 发布