LuaBind vs ToLua

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
User avatar
jesterguy
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 54
Joined: Wed Oct 08, 2008 8:00 pm
Location: Illinois
Contact:

LuaBind vs ToLua

Post by jesterguy »

This question is sorta directed towards falco but any other input is welcome.

Anyways now that I've finished getting my project switched to ogl I'm about to stick in lua and I'm not exactly sure which I should use, So
I know you guys are using tolua and up till now I've been luabind in my testing project but it adds way too much to compile time plus I don't
think I'll be using even 1/4 of its features anyway so I've decided to go with eather tolua++ or mluabind.
I've been able to build mluabind and from what i've seen of examples its not too different from luabind which is good although i have been getting
a weird lua stack error whenever I quit but that's probably my fault, Tolua however is suposed to make all the luabindings its self I believe so that
would be very useful although I had some trouble when I tried building it since I didn't really know how to.

So basically I was wondering how tolua is working for you guys, how to get it set up and if I could see an example of it at work.
I will live forever or die trying.

"Human beings didn't evolve brains in order to lie around on lakes. Killing's the first thing we learned. And a good thing we did, or we'd be dead, and the tigers would own the earth."
- Valentine to Ender ("Ender's Game")
User avatar
Falco Girgis
Elysian Shadows Team
Elysian Shadows Team
Posts: 10294
Joined: Thu May 20, 2004 2:04 pm
Current Project: Elysian Shadows
Favorite Gaming Platforms: Dreamcast, SNES, NES
Programming Language of Choice: C/++
Location: Studio Vorbis, AL
Contact:

Re: LuaBind vs ToLua

Post by Falco Girgis »

Hey, I'm really sorry for not responding sooner. I had intended to, but I didn't want to make a half assed post. I also had to spend time on my JForce response vid.

toLua++ is working out great. toLua is C-based, toLua++ is C++ based (I'm sure you guessed). I am not sure if toLua is even being worked on anymore, though. If you are using C++, I would recommend toLua++ definitely.

In comparison to LuaBind, the only thing that it really doesn't have is the template metaprogramming. It doesn't dynamically create the code for you (and up your compile time). It generates the wrappers which you then have to include with your project.

After you download toLua++, you have two things that you're going to have to compile. The first is the library. This is extremely easy to get going. It's 5(?) .cpp files that you compile into a library and include with your project. They have function calls, debug checking, error handling, OO extending, and certain things that the outputted wrappers require to work. I compiled it with the DC compiler without changing a single thing.

Next, you have to build the executable. This is just a command line application that generates the wrapper based on a "clean" header file that you send. I also didn't have any problems compiling this. Once it's done, you pass it the name of your ".pkg" (cleaned header file), and it creates your wrapper.

Take the wrapper and add it to your project or makefile. Just make sure that you include your header file in the generated wrapper file. (If it's a level wrapper, include your level.h that it's wrapping to). Then call your tolua_open_levelwrapper(state) function. It opens the wrappers for the state.

That's all that you have to do, and you're good to go. I was actually surprised at how easy it was. I had a structure like:

Code: Select all

class ItemSystem {
    public:
        void AddItem(int x, int y, int number);
        Item *GetItem(int x, int y);
};
That's extremely simplified, but if you will notice, the wrapper is going to need to be able to handle the "Item" class as well.

You just do the equivalent of a #include and include your cleaned Item wrapper. ToLua++ handles everything. The result is still a single wrapper file, not an "item_wrap" and an "itemsystem_wrap."

I look here almost constantly: http://www.codenix.com/~tolua/

It should answer almost all of your questions. If you have any more, feel free to post.
User avatar
jesterguy
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 54
Joined: Wed Oct 08, 2008 8:00 pm
Location: Illinois
Contact:

Re: LuaBind vs ToLua

Post by jesterguy »

Its no problem I ended up remaking the weapon system while waiting and its way better now. Anyways I'm probably doing something wrong but I can't get the executable built, the library wasn't too difficult assuming I did it right but the exec keeps giving my errors. I've put in all files and tried putting lua and tolua in the linker but I still get 66 errors when building, All the errors are essentially the same three errors in each code block.

Code: Select all

1>.\toluabind_default.c(33) : error C2143: syntax error : missing ';' before 'type'
1>.\toluabind_default.c(94) : error C2065: 'B' : undeclared identifier
1>.\toluabind_default.c(94) : error C2065: 'B' : undeclared identifier
Anyways I'm not really sure what I did wrong but this is also only the second library I've tried building and I'm not actually sure I did the mluabind one right either since I still get errors when using it.

Edit

I think I got but I'm not sure, I found something online that said to exclude the toluabind_default.c file and when i did it built but is that really what I'm supposed to do???

Edit

I guess that was the correct way to do it because I've got everything working now and tolua++ is actually turning out to be really easy to use. I now have all the functions i wanted access to setup with lua
and it really only took maybe an hour to get all the needed headers setup as .pkg files and included in the project.
I will live forever or die trying.

"Human beings didn't evolve brains in order to lie around on lakes. Killing's the first thing we learned. And a good thing we did, or we'd be dead, and the tigers would own the earth."
- Valentine to Ender ("Ender's Game")
Post Reply