I've implemented LuaPlus in my engine eventmanager successfully and really like the flexibility I gained. But I'm still not exactly where I want to be, because I can't link my c++ classes to a Lua class.

For example, I have a Actor class in C++, and I want to be able to create the same class in Lua and gain access to members with LuaPlus, but I can't figure how I can achieve that.

Is this actually LuaPlus built-in functionality, or do I have to write my own interface that exchanges data tables between C++ and Lua?

My current approach would be to fire an event in Lua that creates an new actor class in C++ code, and transfer its ID and the data I need to back to Lua. When I modify the data I send the modifications back to C++ code again, but I actually thought there's something in LuaPlus that exposes this functionality already.

  • \$\begingroup\$ This is why Lua sucks. \$\endgroup\$ – DeadMG Feb 25 '11 at 0:09
  • 2
    \$\begingroup\$ i actually like it. could you provide why you dislike it, or any alternatives? \$\endgroup\$ – cppanda Feb 25 '11 at 2:19
  • 1
    \$\begingroup\$ I'd also be interested in why you think Lua sucks. \$\endgroup\$ – michael.bartnett Feb 25 '11 at 3:56
  • 1
    \$\begingroup\$ The interoperation with C++ is truly terrible- the language was only designed to interop with C and it shows. Then, when you spend your life finally making the damn thing work, the language itself is very poor- hard to debug, limited powers from Lua, etc. For example, how come full userdata can have __gc but not tables or light userdata? It's a mystery! \$\endgroup\$ – DeadMG Feb 25 '11 at 9:38
  • \$\begingroup\$ @DeadMG: Every language's interoperation with C++ is terrible (including C++ itself from different compilers) - that's usually C++'s fault, not the other language's. \$\endgroup\$ – user744 Mar 17 '11 at 16:14

I don't know how to achieve this with luaplus, but I have been using luabind and the behavior that you explains is very easy to program.


In my experience, LUA has incremented the workflow efficiency, especially on things like AI and things that change a lot in development.

For example, you could reprogram the AI on the fly, with the game in execution, reload the AI and see the changes. All this without recompile or launch the game again.


tolua++ uses all the metatable features to allow a very straightforward manipulation of your c++ types in lua.

For example, this declaration :

// tolua_begin
class SomeCppClass

   int some_field;
   void some_method();
// tolua_end

Will automatically generate the lua bindings to allow this lua scipt :

-- obj1 must be deleted manually
local obj1 = SomeCppClass:new() 
-- obj1 will be automatically garbage collected 
local obj2 = SomeCppClass:new_local()

obj1.some_field = 3 -- direct access to "some_field"
obj2:some_method() -- direct call to "some_method"


The advantage of this technique is that your lua code will ve very consistent with the relying C++ code. See http://www.codenix.com/~tolua/tolua++.html


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.