RosettaCodeData/Task/Call-an-object-method/Lua/call-an-object-method-3.lua

17 lines
328 B
Lua

local count = 0
local box = { }
local boxmt = { __index = box }
function box:tellSecret ()
return self.secret
end
local M = { }
function M.new ()
count = count + 1
return setmetatable({ secret = count, contents = count % 2 == 0 and "rabbit" or "rock" }, boxmt)
end
function M.count ()
return count
end
return M