title: OOP in Lua From C
body: <p>I would like to implement Object Orientated Programming in my lua interpreter, I understand that I can return a lua table from a C Function. And I would like the table that is returned to be full of C functions.</p>
  
  <pre><code>player = getClosestPlayer();
  player.walkTo();
  </code></pre>
  
  <p>where both getClosestPlayer() and walkTo() are C functions.</p>
  
  <p>From the C function for walkTo(), how do I differentiate between object types?</p>
  
  <p>I would prefer every object to have a gid that I can use to identify it (player.gid) but how do I access that gid from the c function?</p>
  
  <p>In other words, what is the equivalent of self.gid from C code?</p>
  
  <pre><code>int l_playerWalkTo(lua_State* functionState){
      int gid = // self.gid?
      // do something with gid
  }
  </code></pre>
  
  <p>One way I could do this is to upvalue every single function in the table, but is there a more elegant way to do it?</p>