Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you glue Lua to C++ code?

Tags:

c++

scripting

lua

Do you use Luabind, toLua++, or some other library (if so, which one) or none at all?

For each approach, what are the pro's and con's?

like image 399
steffenj Avatar asked Sep 19 '08 16:09

steffenj


1 Answers

I can't really agree with the 'roll your own' vote, binding basic types and static C functions to Lua is trivial, yes, but the picture changes the moment you start dealing with tables and metatables; things go trickier very quickly.

LuaBind seems to do the job, but I have a philosophical issue with it. For me it seems like if your types are already complicated the fact that Luabind is heavily templated is not going to make your code any easier to follow, as a friend of mine said "you'll need Herb Shutter to figure out the compilation messages". Plus it depends on Boost, plus compilation times get a serious hit, etc.

After trying a few bindings, Tolua++ seems the best. Tolua doesn't seem to be very much in development, where as Tolua++ seems to work fine (plus half the 'Tolua' tutorials out there are, in fact, 'Tolua++' tutorials, trust me on that:) Tolua does generate the right stuff, the source can be modified and it seems to deal with complicated cases (like templates, unions, nameless structs, etc, etc)

The biggest issue with Tolua++ seems to be the lack of proper tutorials, pre-set Visual Studio projects, or the fact that the command line is a bit tricky to follow (you path/files can't have white spaces -in Windows at least- and so on) Still, for me it is the winner.

like image 89
Rodrigo Lopez Avatar answered Oct 07 '22 15:10

Rodrigo Lopez