title: Integrating Lua to build my GameEntities in my Game Engine?
body: <p>I really want to add Lua Scripting to my Game Engine. I am working with Lua and bound it to C++ using luabind, but I need help to design the way I will construct my Game Entities using Lua.</p>
  
  <p>Engine Information:</p>
  
  <p>Component Oriented, basically each <code>GameEntity</code> is a list of <code>components</code> that are updated in a delta T interval. Basically <code>Game Scenes</code> are composed by collections of Game Entities.</p>
  
  <p>So, here's the dilemma:</p>
  
  <p>Let's say I have this Lua file to define a GameEntity and it's components:</p>
  
  <pre><code>GameEntity = 
  {
   -- Entity Name
   "ZombieFighter",
  
   -- All the components that make the entity.
   Components = 
   {
    -- Component to define the health of the entity
    health = 
    {
     "compHealth",  -- Component In-Engine Name
     100,    -- total health
     0.1,    -- regeneration rate
    },
  
    -- Component to define the Animations of the entity
    compAnimation =
    {
     "compAnimatedSprite",
  
     spritesheet = 
     {
      "spritesheet.gif", -- Spritesheet file name.
      80,     -- Spritesheet frame width.
      80,     -- Spritesheet frame height.
     },
  
     animations =
     {
      -- Animation name, Animation spritesheet coords, Animation frame duration.
      {"stand", {0,0,1,0,2,0,3,0}, 0.10},
      {"walk", {4,0,5,0,6,0,7,0}, 0.10},
      {"attack",{8,0,9,0,10,0}, 0.08},
     },
    },
   },
  }
  </code></pre>
  
  <p>As you can see, this GameEntity is defined by 2 components, "<code>compHealth</code>" and "<code>compAnimatedSprite</code>". Those two totally different components require totally different initialization parameters. Health requiring an integer and a float ( total and regeneration ), and on the other side, animations requiring a sprite sheet name , and to define all of the animations ( the frames, durations, etc ).</p>
  
  <p>I would love to make some kind of abstract class with some virtual initializer method that could be used by all my components that require Lua binding in order to facilitate initialization from Lua, but it seems difficult, because the virtual class is not going to have one virtual init method. This is because all of the component initializers (or most of them) require different init parameters  (health component requires different init than Animated Sprite component, or AI component).</p>
  
  <p>What do you suggest to make the Lua bindings to the constructors of this components easier ? or how would you do it ? </p>
  
  <p>PS: I must use C++ for this project.</p>