Selecting a Lua/C++ binding library

Started by
12 comments, last by guanohead 12 years, 1 month ago
I'm a little overwhelmed at the number of sources I've found for binding Lua code to C++, so I'm wondering what libraries other developers have chosen and why. The sources I have found are: - LuaPlus - LuaBind - tolua++ - tolua - Luna From my quick glance over the options, it seems that LuaPlus and LuaBind are the most popular choices here and are reasonbly well documents. tolua++ and tolua seem to offer minimal information, and I believe I heard that tolua isn't even being worked on anymore. Luna I couldn't even find any information on after a quick google search. Also, at least for my purposes, its important that the lua binding library I choose is cross-platform (Linux, Windows, MacOS). From my initial search it seems like LuaPlus is Windows only and LuaBind is Windows/*-nix, but no mention of MacOS. Correct me if I'm wrong please. [smile]

Hero of Allacrost - A free, open-source 2D RPG in development.
Latest release June, 2015 - GameDev annoucement

Advertisement
I use tolua, mostly out of force of habit. Some people don't like having to go through the extra steps of creating a separate cleaned header file and processing it with tolua, but I really don't mind. The cleaned headers give me a concise listing of exported functions for documentational purposes; when I'm doing active scripting work, I'll just keep the headers open in a text editor for quick reference. Of course, since I've pretty much frozen my projects at Lua 4.0 for now in the interest of not breaking a lot of code, whether or not tolua is still being worked on is largely irrelevant. I've never found the documentation to be less than adequate, personally; it's a pretty simple tool.
I also find that tolua++ is quite good. Indeed docs arent as good as they should, but you can find what you need to know asking in the right places. Also, tolua devel isnt halted, it is just a bit slow.
Hi there,

I personally like LuaPlus. I talked to Joshua Jensen a couple of times when I had questions about the library and he always helped me a lot. He mainly develops LuaPlus and already worked for several good known game companies.

LuaPlus offers a great and intuitive to use interface, c++ binding, a remote debugger and lots of features including enhancements over the original Lua core.

In case you are working with DevC++, I also created a devpak containing the most current build of LuaPlus (look at www.devpaks.org).

Regards,
T.
Hmmm, this thread isn't helping my decision as much as I thought it would. So it seems that you three just selected your given libraries based on a personal preference, or randomly chose a binding lib before and stuck with it since you know how to use it now? I'll re-iterate that I'm trying to discover *why* you chose the library you did. Thanks for the help so far though guys.


And I know that there are many more people out there who use Lua from the number of threads I've seen here (where are the people who use LuaBind?). Reveal yourselves!!! [smile]

Hero of Allacrost - A free, open-source 2D RPG in development.
Latest release June, 2015 - GameDev annoucement

what: Luna for exporting classes with combination of my own lua wrapper for calling functions, accessing globals, pushing arguments etc.

why: I tested LuaBind, tolua and Luna. I didnt like the extra step of tolua, and luaBind offers nearly everything luna has to offer. luna is only one header and not much code (easy to understand) - so i chose luna. google for lunar and you find some advancement over luna (eg. templated push and pop of classes). you can define macros for all required luna statements so your exported class looks clean and nice (important for me) - with my wrapper (which isnt anything special) for accessing tables, arrays, globals, functions etc. its all I need for extending my games with lua...
I hope I'm not hijacking (ignore me if I am) but what do these libraries do that plain old Lua won't do?
I like the DARK layout!
Quote:Original post by BradDaBug
I hope I'm not hijacking (ignore me if I am) but what do these libraries do that plain old Lua won't do?

Agreed. It is painfully simple to expose functions to Lua. I just added lua scriptability to my game-thing and was blown away at how simple it was - worked first try.
wendigo23 & BradDaBug

One of the nicest things about using one of the binding libraries is that you don't really have to worry about manually keeping classes in sync, the code to do it is provided for you. I guess at heart I'm lazy, and going to the effort of writing pushes and pops for incoming and outgoing data didn't really appeal - I'd rather spend my time working on bigger parts of the projects that I'm working on.

One of the hidden benefits (at least in the case of luabind, can't say for the others) is that you can derive from a C++ class in lua, and then override the methods that you choose. For the OO junkies amongst us (me included), writing a C++ style interface and then exporting it to lua is nicer than using raw function pointers where I have to add C glue code to pass in a 'this' parameter.

The price is that you either need to use an intermediate definition (similar to IDL), or add a small ammount of code to describe the data structure to be exported.

Personally I didn't want external dependancies (SWIG or something like IDL) because they could potentially get out of sync and I didn't want the hassle of something potentially going wrong because a pre-build step didn't work or didn't run successfully. In hindsight I was probably worrying about nothing, and in situations where rapid development or large changes to the exported interfaces at the C++ end is important, toLua would probably have been terrific.

Luabind and other templated methods avoid the problem by using C++ code to define the binding mechanism, however they take an age to compile, even in simple cases on an medium spec (P3 1Gig) machine 1+ minutes for each compilation unit which includes the luabind headers is not surprising. Luabind has the benefit of being one of the first of the scripting languages that will (eventually) be attached to boost::langbinding so if you like boost, it may be the way to go (boost 1.30.2+ is a dependancy).

Luabind has a lot of functionality, perhaps too much for a new user, but it definately provided room to grow. Every time I needed a new feature all I needed to do was go back to the manual and look it up. Luna is a minimalist binding system and from memory you need to do a little more work than with luabind to make it work. Another plus for Luabind is that it makes every effort to prevent you from leaking memory or writing unsafe (wrt exceptions) code through the use of the parameter policies.

Luabind should work on all platforms the boost does (including MacOS), however compilers with poor template support will struggle. The use of the boost config library ensures that if a problem is identified it may be worked around, best to try it and see if it works - it probably will.

Luna is available from the Lua wiki it's listed as the SimplerCppBinding. It also demonstrates how the lua_state needs to be passed around. Luabind avoids this by using a few extra tricks.
Quote:Original post by BradDaBug
I hope I'm not hijacking (ignore me if I am) but what do these libraries do that plain old Lua won't do?



You are right. A binding library is not a requirement, but I thought it would just be easier and cleaner to use one than to do my own interface. And like Andrew said, you can spend time on more important things in your project this way. It was a very good question to ask though. [smile]

Hero of Allacrost - A free, open-source 2D RPG in development.
Latest release June, 2015 - GameDev annoucement

This topic is closed to new replies.

Advertisement