title: Adding member function to a C++ class bound to Lua
body: <p>I have been working on how to bind C++ classes to Lua for use in a game engine, and I have run into an interesting problem. I have been following the tutorial on this website: <a href="http://tinyurl.com/d8wdmea" rel="nofollow">http://tinyurl.com/d8wdmea</a>. After the tutorial, I realized that the following code he suggested:</p>
  
  <pre><code>local badguy = Monster.create();
  badguy.pounce = function(self, howhigh, bonus)
      self.jumpbonus = bonus or 2;
      self:jump(howhigh);
      self:rawr();
  end
  badguy:pounce(5, 1);
  </code></pre>
  
  <p>Would only add the pounce function to that specific instance of a Monster. So I changed the script that he suggested to the following:</p>
  
  <pre><code>function Monster:pounce(howhigh, bonus)
      print("in pounce function");
      print(bonus);
      self.jumpbonus = bonus or 2
      self:jump(howhigh);
      self:rawr();
  end
  local badguy = Monster.create();
  badguy:pounce(5,1);
  </code></pre>
  
  <p>However, when I call the pounce function, the script breaks.  After further testing, the only way I was able to successfully call the pounce function was by calling the function as a static member of the Monster class (the code for the function stays the same):</p>
  
  <pre><code>Monster.pounce(badguy,5,1);
  </code></pre>
  
  <p>Syntactically, badguy:pounce(5,1) is correct, but isnt correctly calling the function. Am I just doing something wrong, or is this a limitation of the binding between lua and c++/how I am binding the two languages?</p>