ThinkChat🤖让你学习和工作更高效,注册即送10W Token,即刻开启你的AI之旅 广告
[TOC] ## 面向对象 LUA中最基本的结构是table,所以需要用table来描述对象的属性 示例 ``` 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("面积为 ",self.area) end -- 创建对象 myshape = Shape:new(nil,10) myshape:printArea() ```