tags:

views:

2867

answers:

6

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?

+1  A: 

There was some discussion of this topic here.

Mark
+3  A: 

To answer my own question in part:

Luabind: once you know how to bind methods and classes via this awkward template syntax, it's pretty straightforward and easy to add new bindings. However, luabind has a significant performance impact and shouldn't be used for realtime applications. About 5-20 times more overhead than calling C functions that manipulate the stack directly.

steffenj
+1  A: 

I don't use any library. I have used SWIG to expose a C library some time ago, but there was too much overhead, and I stop using it.

The pros are better performance and more control, but its takes more time to write.

Kknd
+1  A: 

Use raw Lua API for your bindings -- and keep them simple. Take inspiration in the API itself (AUX library) and libraries by Lua authors.

With some practice raw API is the best option -- maximum flexibility and minimum of unneeded overhead. You've got what you want and no more, the way you need it to be.

If you must bind large third-party libraries use automated generators like tolua, tolua++ (or even roll your own for the specific case). It would free you from manual work.

I would not recommend using Luabind. At the moment it's development stalled (however starting to come back to life), and if you would meet some corner case, you may be on your own. Also Luabind heavily uses template metaprogramming. This may (and may not) be unacceptable, depending on the point of view.

Alexander Gladysh
Aside from people who may be using compilers which cannot support TMP, I don't see why it would be unacceptable. As for development, there is some (I recently contributed an enhancement/fix), and most of the time I don't find it lacking anything too important. It's not *very* active, though, true.
John Zwinck
+3  A: 

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.

Rodrigo Lopez
A: 

There is a simple tolua++ example at: http://lightfeather.de/forum_viewtopic.php?17.1139

Remember have the tolua and lua lib. have the headers for tolua++ and lua.

sum1nil
The link is broken.
caspin