title: Wrapping c++ class to use it in Lua using SWIG - need simple example
body: <p>I'm an absolute beginner when it comes to using both SWIG and lua, and a mediocre C++ developer, and I just don't seem to understand how I can bind C++ classes with Lua.</p>
  
  <p>My end goal is to have an instance of a class, pass it to my lua script which manipulates that object in a certain way, then I retrieve that object in c++ and do whatever else I want to do with it.</p>
  
  <p>So... I've downloaded Lua and C++, compiled a few examples, I am able to run some lua script in my c++ program. So far so good.</p>
  
  <p>Now, I've downloaded SWIG. I'm using VC2010 on Windows 7. From what I understand I'm suppose to create an interface file. So I've created one, example.i:</p>
  
  <pre><code>%module creature
  class Creature
  {
  public:
      Creature(void);
      Creature(int id);
      ~Creature(void);
  
  (...) the rest of my class here
  </code></pre>
  
  <p>(Just added %module creature to my Creature.h and saved it as creature.i). I ran SWIG using</p>
  
  <pre><code> swig -c++ -lua creature.i
  </code></pre>
  
  <p>and got my creature.cxx file.</p>
  
  <p>Now, I'll probably embarrass myself now but... I don't know what to do next. Am I suppose to build the output file somehow? How can I use it now? I've read here <a href="http://www.swig.org/Doc1.3/Lua.html" rel="nofollow">http://www.swig.org/Doc1.3/Lua.html</a> that I need to link the generated file (*.cxx) with the rest of my code (so I do that by simply including the file in my project and adding the line #include "Creature.h"). But when I compile I get errors like</p>
  
  <pre><code>error C2065: 'LUA_GLOBALSINDEX' : undeclared identifier
  error C2036: 'const luaL_reg *' : unknown size
  </code></pre>
  
  <p>I have also tried compiling it using MinGW but I get the same problem. It would be great if someone could show me an example or a step-by-step tutorial of how I can use these tools together, as I have a hard time grasping the whole idea. This is definitely due to my lack of understanding of the basics of how this should be used so please be gentle to a noob.</p>
  
  <p>Any help will be much appreciated. </p>