Sign in to follow this  

Selecting a Lua/C++ binding library

This topic is 2123 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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...

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
Really, you could sit here and weigh the pros and cons of each of the utilities, asking other people why they chose what they did, for the next six weeks and you probably won't get anywhere. If it's really that big of an issue (hint: it's not as big as you might think) then pick up two or three and try them out. Work through the samples in the docs, see how they feel for you. If in further doubt, do a small project using one and if it doesn't feel right, try another. I'm concerned you may be spending too much time worrying about something that really isn't that significant.

Why someone chooses one over the other probably has little to do with which one you should choose. For example, initially I chose tolua completely at random. It was the first in the list that I glanced at, so I downloaded it and gave it a whack. It worked, so I ran with it.

Share this post


Link to post
Share on other sites
I use luaBind...I like use of the overloaded operators to make it look like its some other language embedded into C++ but it's actual c++ syntax (read the docs for the details). The binding is pretty easy and calling lua functions through luabind's object is just the same. My beef is that it requires the boost library, adds to compilation time, and it has some memory overhead. There's some bizarre behavior that comes with luaBind, so beware!

Share this post


Link to post
Share on other sites
My advice is that you download luabind, tolua and luna and give it a try. Thats what I did (after reading the docs) and finnally i decided to use tolua++. I dont remember if i had some problems compiling luabind.
If you decide to use tolua++, I can give you a simple demo i made that ilustrates the use of pkg files to bind a class and some constants, and read/writing C++ classes from lua scripts.

Share this post


Link to post
Share on other sites
While this is quite an old thread, it's also one of the first that pulled up with a google search. I wanted to point out [url="http://realmensch.org/blog/fun-lua-bindings"]this comparison of lua/c++ bindings[/url] for those who come to this thread in the future.

Share this post


Link to post
Share on other sites

This topic is 2123 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this