Reputation: 33
I have a simple class implementation in Lua.
test = {}
test.__index = test
function test:new()
local o = {}
setmetatable(o, self)
return o
end
function test:setName(name)
self.name = name
print name
end
local name = test:new()
name:setName("hello")
I keep getting this error when I run it:
lua: test.lua:12: '=' expected near 'name'
I not sure what or why this happening, any help would be greatly appreciated.
Upvotes: 3
Views: 287
Reputation: 1852
Change print name
to print(name)
. print
is just a regular function and function calls need parentheses unless they are called with a single argument that is either a string literal or a table literal.
Upvotes: 5