local function search(k, plist) for i, v in pairs(plist) do local temp_v = v[k] if temp_v then return temp_v end endendfunction 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 cendNamed = {}function Named:getname() return self.nameendfunction Named:setname(n) self.name = nendlocal NamedAccount = createClass(Account, Named)account = NamedAccount:new({name = "Paul"})print(account:getname())
新闻热点
疑难解答