1.类 再Lua中可以使用表和函数实现面向对象,将函数和相关的数据放置放置于同一个表中就形成了对象.例如: Measure = {width = 0, height = 0} function Measure:setWifth(v) self.width = self.width + v end function Measure:setHeight(v) self.height = self.height + v end function Measure:getMeasure() print(s…
多重继承: module(...,package.seeall) local function search(k,plist) ,#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,par…
类和对象: account.lua module(...,package.seeall) Account={balance=} Account.new=function(self,o) local o=o or {} setmetatable(o,self) self.__index=self return o end Account.getBalance=function(self) return self.balance end Account.setBalance=function(s…