抵制使用 module() 定义模块
-- square.lua 长方形模块
local _M = {} -- 局部的变量
_M._VERSION = '1.0' -- 模块版本
local mt = { __index = _M }
function _M.new(self, width, height)
return setmetatable({ width=width, height=height }, mt)
end
function _M.get_square(self)
return self.width * self.height
end
function _M.get_circumference(self)
return (self.width + self.height) * 2
end
return _MLast updated