编辑代码

Object={}
Object.i=1
function Object:new()
    local object={}
    self.__index=self
    setmetatable(object,self)
    return object
end

function Object:subClass(subClassName)
    _G[subClassName]={}
    local sub=_G[subClassName]
    self.__index=self
    setmetatable(sub,self)
end


-- local o1=Object:new()
-- print(o1.i)
-- o1.i=2
-- print(o1.i)
Object:subClass("GameObject")
local go=GameObject:new()
print(go.i)
go.i=2
print(go.i)
local o1=Object:new()
print(o1.i)