title: Error while trying to call a class method: attempt to index local 'self' (a nil value) - Lua
body: <p>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 <code>Attempt to index local 'self' (a nil value)</code> when the <code>button:activate()</code> method is called. The parser says the error is in the 8th line in the code below. The problematic code is as follows:</p>
  
  <pre><code>button = class(view)
  
  function button:init()
      self.selected = false
  end
  
  function button:activate()
      self.selected = true
  end
  </code></pre>
  
  <p>I call the activate function like this:</p>
  
  <pre><code>item = button()
  local action = "activate"
  local arguments = {}
  item[action](unpack(arguments))
  </code></pre>
  
  <p>I am aware the <code>class()</code> 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 <a href="http://wiki.inspired-lua.org/class%28%29" rel="nofollow">here</a>.</p>