RosettaCodeData/Task/Call-an-object-method/Lua/call-an-object-method-2.lua
Ingy döt Net 6f050a029e update
2013-06-05 21:47:54 +00:00

9 lines
290 B
Lua

local methods = { }
function methods:func () -- if a function is declared using :, it is given an implicit 'self' parameter
print(self.name)
end
local object = setmetatable({ name = "foo" }, { __index = methods })
object:func() -- with : sugar
methods.func(object) -- without : sugar