【发布时间】:2012-12-13 16:27:02
【问题描述】:
我的课程有问题。我收到以下错误: 尝试索引本地“自我”(零值) 当我调用下面类的getter方法时。 item.lua 文件:
require "classlib"
Item = class("Item")
function Item:__init()
self.interval = 1
end
function Item:getInterval()
return self.interval
end
我这样调用这个getter函数:
dofile("../src/item.lua")
item = Item()
function test_item()
assert_equal(1, item.getInterval())
end
这里有什么问题?
亲切的问候...
【问题讨论】:
-
在
test_item()中调用item:getInterval()而不是item.getInterval()。 -
可能有助于判断这个“类库”是什么。请注意,
class()调用中有不匹配的引号(单引号和双引号)。 @OmriBarel 可能应该发布答案,而不是评论... :-) -
谢谢!它们有什么区别?
标签: lua