luaでの継承とマルチ継承

2199 ワード

--[[    
        lua         
]]
--
--setmetatable(a,b)
--[[
Account = {num = 10}
function Account:new( o )
    o = o or {} 
    setmetatable(o,self) --Account o   
    self.__index = self   --  
    return o
end
function Account:show(v) 
    print(self.num + v)
end
 a = Account:new{bb = 11}
 a:show(1.0)

 ]]

local function search(k, plist)
    for i=1, #plist do
        local v = plist[i][k]

        if  v then 
        return v
        end

    end
end
function createClass(...)
    local c = {}
    local parents = {}
    setmetatable(c, {__index = function(t, k)
                return search(k,parents)
            end})

    c.__index = c


    function c:new( o )
        o = o or {}
        setmetatable(o, c)
        return  o
    end


    return  c
end