我在 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")
我运行它时不断收到此错误:
lua: test.lua:12: '=' 预期在 'name' 附近
我不确定发生了什么或为什么会发生这种情况,任何帮助将不胜感激。