下面是内存溢出 jb51.cc 通过网络收集整理的代码片段。
内存溢出小编现在分享给大家,也给大家做个参考。
--[[author:[email protected]date:2014/7/18purpose:lua的继承演示--]]--- base class "Object"local Object = {_t = "Object"}function Object:new(ID) local o = { _ID = ID } setMetatable(o,self) self.__index = self return oendfunction Object:type() return self._tendfunction Object:ID() return self._IDend--- class "Widget" driver from "Object"local Widget = {_t = "Widget"}setMetatable(Widget,Object)function Widget:new(ID) local o = { _ID = ID,} setMetatable(o,self) self.__index = self -- function (tb,key) -- return self[key] -- end return oend -- function Widget:ID()-- return self._ID-- end--- class "Drawor" driver from "Object"local Drawor = {_t = "Drawor"}setMetatable(Drawor,Object)function Drawor:new(ID,@R_301_6889@) local o = { _ID = ID,_@R_301_6889@ = @R_301_6889@,self) self.__index = self return oendfunction Drawor:@R_301_6889@() return self._@R_301_6889@end--- class "DrawPlane" driver from "Widget" and "Drawor"local DrawPlane = {_t = "DrawPlane",_father = {Widget,Drawor}}function DrawPlane:new(ID) local o = { _ID = ID,} setMetatable(o,self) self.__index = function (tb,key) if self[key] then return self[key] end for _,v in pairs(self._father) do if v._t == key then return v end if v[key] then return v[key] end end end return oendlocal vara = Object:new()local varB = Widget:new(10)local varC = Drawor:new(30,"DWr")local varD = DrawPlane:new(51)print("vara type:",vara:type())print("varB type:",varB:type())print("varB._ID: ",varB._ID,varB:ID())print("varC @R_301_6889@: ",varC:@R_301_6889@())print("varD type: ",varD:type())print("varD ID: ",varD:ID())print("varD father Widget--",varD.Widget:type())
以上是内存溢出(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
总结以上是内存溢出为你收集整理的Lua实现类继承的一种写法全部内容,希望文章能够帮你解决Lua实现类继承的一种写法所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)