点击运行
-- Meta class Shape = {area = 0} -- 基类方法 new function Shape:new (o,side) o = o or {} setmetatable(o, self) self.__index = self side = side or 0 self.area = side*side; return o end -- 基类方法 printArea function Shape:printArea () print("The area is ",self.area) end -- 创建一个对象 myshape = Shape:new(nil,10) myshape:printArea()
运行结果 :
正在执行...