620 posts
Location
Holland
Posted 23 January 2015 - 05:52 PM
I am using the following code:
-snip-
Line: 9 newObject.__index = newObject
Line: 10 local function newObject:get(valueName)
Line: 11 return self[valueName]
Line: 12 end
-snip-
And I am getting the error:
[string "luaoop"]:10: '(' expected
Am I missing something obvious?
Full code can be found at:
https://github.com/superaxander/LuaOOP/raw/master/luaoop.lua
1023 posts
Posted 23 January 2015 - 05:57 PM
edit: was wrong
Edited on 23 January 2015 - 05:04 PM
227 posts
Location
Germany
Posted 23 January 2015 - 06:01 PM
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.
620 posts
Location
Holland
Posted 23 January 2015 - 06:04 PM
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: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 on 23 January 2015 - 05:04 PM