lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hi!
  Such things I had doned. it means:
  1. bind——call c++ from lua 
  2. extend——call lua from c++ 
  and they all can be found at  http://lua-users.org/wiki/BindingCodeToLua
  So many ways ! you will be confused , the same as I first do. I try a lot of : luaplus, luabind, tolua++ in different games... at later I have a suggestion:

  Don't use these addon! ——  Write all by lua's API 
  
  you will found it is very simple use lua's API. but if you are want totally expose your Object to lua, it will a painful way. So there is another suggestion:
  Just expose to lua what lua really want, and design more carefully let c++ do c++'s way and lua do lua's way. just pass lightuserdata to lua never userdata.
  and extend c++ is like:

  int extend_ai(Lua_status* L)
  {
     object = lua_tolightuserdata(L,1)
     object->set_extend_ai(L,lua_tostringL,2))
  }
  object::ai()
  {
     if (m_LAI)
     {

  }


2011/9/7 Guy J <desfenfe@gmail.com>
Hey there Lua fellows!

First e-mail I'm sending to the list - I hope this is not a repeated question, I searched through the archive and couldn't find what I'm looking for.

So.. I've built a game engine in C++ and I have a GameObject class that represents all the objects in my game, now I have some other classes that derive from GameObject, such as Robot, Bullet, Player, etc...

What I'd like to do is to extend the GameObject class in Lua instead of making C++ derivatives, to keep the engine as clean and simple as possible.

The Lua object should have awareness of it's own type, and state. For instance, the 4 callbacks that will make the object "tick" would be Construct, Destruct, Update, Collide -> these will be implemented in Lua. These methods should be able to call getLinearVelocity, getPosition, applyForce, etc... that will be implemented in the game engine. All of these method should work on the context of the same instance.

What is the best approach for doing what I described?

Appreciate your help!

Thanks,
Guy