Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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.

share|improve this question
    
This is why Lua sucks. –  DeadMG Feb 25 '11 at 0:09
2  
i actually like it. could you provide why you dislike it, or any alternatives? –  cppanda Feb 25 '11 at 2:19
1  
I'd also be interested in why you think Lua sucks. –  michael.bartnett Feb 25 '11 at 3:56
1  
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! –  DeadMG Feb 25 '11 at 9:38
    
@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. –  user744 Mar 17 '11 at 16:14
show 1 more comment

2 Answers 2

up vote 2 down vote accepted

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.

http://www.rasterbar.com/products/luabind.html

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.

share|improve this answer
add comment

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
{
public:
   SomeCppClass();
   ~SomeCppClass();

   int some_field;
   void some_method();
};
// tolua_end

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


#!lua
-- 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"

obj1:delete()

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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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