In the code shown on:
http://lua-users.org...ntationTutorial
local MyClass = {}
MyClass.__index = MyClass
setmetatable(MyClass, {
__call = function (cls, ...)
return cls.new(...)
end,
})
function MyClass.new(init)
local self = setmetatable({}, MyClass)
self.value = init
return self
end
-- the : syntax here causes a "self" arg to be implicitly added before any other args
function MyClass:set_value(newval)
self.value = newval
end
function MyClass:get_value()
return self.value
end
local instance = MyClass(5)
they are clearly using it when defining the function. I'll try and see if it can be used without the : when declaring and only using it while using the function.
EDIT:
wieselkatze, on 23 January 2015 - 06:01 PM, said:
Using ':' is perfectly fine. You just
can't make that function local as it is created inside your table. Using
function newObject:get( valueName )
should work.
Ah thanks for the quick response. Cheers!
Edited by superaxander, 23 January 2015 - 06:04 PM.