Jump to content

  • Log In with Google      Sign In   
  • Create Account


Selecting a Lua/C++ binding library


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
13 replies to this topic

#1 Roots   Members   -  Reputation: 657

Like
0Likes
Like

Posted 15 December 2004 - 12:16 PM

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 --- http://www.allacrost.org
A free, open-source 2D RPG in development.

Latest release Oct. 10th, 2010.

Sponsor:

#2 JTippetts   Moderators   -  Reputation: 8159

Like
0Likes
Like

Posted 15 December 2004 - 04:16 PM

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.

#3 rogerdv   Members   -  Reputation: 158

Like
0Likes
Like

Posted 18 December 2004 - 01:53 AM

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.


#4 Mephisztoe   Members   -  Reputation: 118

Like
0Likes
Like

Posted 19 December 2004 - 11:07 AM

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.

#5 Roots   Members   -  Reputation: 657

Like
0Likes
Like

Posted 21 December 2004 - 02:57 AM

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 --- http://www.allacrost.org
A free, open-source 2D RPG in development.

Latest release Oct. 10th, 2010.

#6 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

0Likes

Posted 21 December 2004 - 03:23 AM

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...

#7 BradDaBug   Members   -  Reputation: 892

Like
0Likes
Like

Posted 21 December 2004 - 08:16 AM

I hope I'm not hijacking (ignore me if I am) but what do these libraries do that plain old Lua won't do?

#8 wendigo23   Members   -  Reputation: 512

Like
0Likes
Like

Posted 21 December 2004 - 09:05 AM

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.

#9 XXX_Andrew_XXX   Members   -  Reputation: 340

Like
0Likes
Like

Posted 21 December 2004 - 12:56 PM

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.

#10 Roots   Members   -  Reputation: 657

Like
0Likes
Like

Posted 21 December 2004 - 01:20 PM

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 --- http://www.allacrost.org
A free, open-source 2D RPG in development.

Latest release Oct. 10th, 2010.

#11 JTippetts   Moderators   -  Reputation: 8159

Like
0Likes
Like

Posted 22 December 2004 - 09:41 AM

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.

#12 jackiechan   Members   -  Reputation: 132

Like
0Likes
Like

Posted 25 December 2004 - 04:21 PM

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!

#13 rogerdv   Members   -  Reputation: 158

Like
0Likes
Like

Posted 26 December 2004 - 01:51 AM

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.

#14 guanohead   Members   -  Reputation: 122

Like
0Likes
Like

Posted 21 February 2012 - 05:38 AM

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 this comparison of lua/c++ bindings for those who come to this thread in the future.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS