I have a problem with classes. I got below error: Attempt to index local \'self\' (a nil value) When I call the getter method of below class. Item.lua file:
Change:
assert_equal(1, item.getInterval())
to:
assert_equal(1, item:getInterval())
In Lua, it was some ridiculous for error reporting. From class point of view, the .getInterval()
method should called with a self
parameter, while the :getInterval()
method is implicitly included the self
parameter. And the syntax error should labeled in the called point, not the definition-body of getInterval()
.
In traditional, while you miscalled a method, it was not the method's fault, but the caller.