I'm creating a lua script that should run on the TI-Nspire calculator. The problem is that while running my script I get the error Attempt to index local 'self' (a nil value)
when the button:activate()
method is called. The parser says the error is in the 8th line in the code below. The problematic code is as follows:
button = class(view)
function button:init()
self.selected = false
end
function button:activate()
self.selected = true
end
I call the activate function like this:
item = button()
local action = "activate"
local arguments = {}
item[action](unpack(arguments))
I am aware the class()
function doesn't exist in "stock" Lua, it's a function available in the TI-Nspire Lua implementation. You can find its definition and usage here.
obj:methodname(args)
is sugar forobj.methodname(obj,args)
. So, if you want to use the syntaxitem[action](unpack(arguments))
, you need to useitem[action](item,unpack(arguments))
. Otherwise, tryitem:activate(unpack(arguments))
if you can use method explicitly.