Lua Bind

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

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:

Lua Bind

Post by Falco Girgis »

This topic is mostly directed at trufun, but it's an open discussion, and it might be beneficial to everybody else.

I looked at your private message on Youtube. You're using Luabind? I had actually looked into that awhile ago. I didn't realize that you could give Lua a pointer to the object. I thought that you'd be instantiating a completely new instance independent of what the engine was using. That's really cool and clever.

But now I'm wondering. How heavy weight do you think Luabind is? I read up quite a deal on it. It apparently does quite a bit more than I had realized. It also provides some really cool OO mechanisms to Lua (making classes, inheritance, etc.) that would make things easier/prettier. Do you think that LuaBind has a large amount of overhead?

I'm kind of uneasy about hopping aboard things like this. I'd have to compile the lib for Dreamcast and test it out. I already broke the DC build awhile ago. I still need to compile Lua for it.

The register functions/classes deal doesn't really seem like it would have too much overhead. I believe that luabind is making wrappers to these at compile time. Does anybody know for sure?
User avatar
trufun202
Game Developer
Game Developer
Posts: 1105
Joined: Sun Sep 21, 2008 12:27 am
Location: Dallas, TX
Contact:

Re: Lua Bind

Post by trufun202 »

Yeah, I've been really impressed with LuaBind. It allows for a much cleaner engine. You're not having to create a ton of "flat" methods that you'll never use for anything other than Lua. With LuaBind, rather, you're just exposing existing objects and methods to another outlet.

From what I've done so far, LuaBind has minimal impact, because you register everything at once (when you load up the script).

Enabling / disabling Lua causes no impact on my framerates, but I'll admit I haven't paid much attention to memory usage. In theory, you're mostly dealing with pointers, so it might infact allocate less memory.
-Chris

YouTube | Twitter | Rad Raygun

“REAL ARTISTS SHIP” - Steve Jobs
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: Lua Bind

Post by Falco Girgis »

Yeah, that's what I'm thinking too. And also, I'm otherwise creating a get/set function for every value/set of values which are passing things by value to and from the Lua stack. I think passing pointers to Lua might actually up our performance. I can't wait to screw around with it. Thanks for your help, I really appreciate it.
User avatar
trufun202
Game Developer
Game Developer
Posts: 1105
Joined: Sun Sep 21, 2008 12:27 am
Location: Dallas, TX
Contact:

Re: Lua Bind

Post by trufun202 »

GyroVorbis wrote:Yeah, that's what I'm thinking too. And also, I'm otherwise creating a get/set function for every value/set of values which are passing things by value to and from the Lua stack. I think passing pointers to Lua might actually up our performance. I can't wait to screw around with it. Thanks for your help, I really appreciate it.
Just a heads up, you'll still need to create getter and setter methods if you want to expose properties using LuaBind, such as:

luabind::module(L) [
luabind::class_<Player>("Player")
.def(luabind::constructor<std::string>())
.def("Init", &Player::Init)
.def("Print", &Player::Print)
.def("GetName", &Player::GetName)
.property("HP", &Player::GetHP, &Player::SetHP) <----
.property("MP", &Player::GetMP, &Player::SetMP)
];

But it'll all be referencing the same memory. So no more passing by value.
-Chris

YouTube | Twitter | Rad Raygun

“REAL ARTISTS SHIP” - Steve Jobs
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: Lua Bind

Post by Falco Girgis »

Okay, so I finally got off my ass (or sat on my ass, technically) and got LuaBind built and all that. I'm glad to see that it doesn't actually use boost, just uses some of the headers... because the boost "download" is a 52meg+ compressed file that became 135megs unextracted. A lot of the boost libraries look pretty heavy also, doesn't sound Dreamcast friendly.

So I finally built the ugly bastard. And is it just me, or do the things in the "test" directory of LuaBind not compile? Seriously, they're doing things in there (passing states to LuaBind calls) that it appears have changed in the newer builds of LuaBind. I've had to change some things in that directory to get them to compile.

Anybody else noticed that it seems "test" is using an older version?
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: Lua Bind

Post by Falco Girgis »

On that topic, it was the benchmark that I was trying to run. My results are actually pretty nice.

It's calling a function with luabind and one with empty binding. It kept returning 0 microseconds... which I thought was a mistake. Apparently it wasn't, because I added a few more zeros to the call, and I got these results:

Code: Select all

luabind: 1.6e-005 microseconds per call
empty: 1.5e-005 microseconds per call

Difference of 1e-006 microseconds per call.
So LuaBind really doesn't seem to be very heavy weight after all. Not to mention what you're saving by being able to retrieve references instead of passing everything all over the place as value.

Looking goood.
User avatar
trufun202
Game Developer
Game Developer
Posts: 1105
Joined: Sun Sep 21, 2008 12:27 am
Location: Dallas, TX
Contact:

Re: Lua Bind

Post by trufun202 »

I don't remember, I'll take a look this weekend. I do remember it was a bitch to get everything compiled.

I think I may have had to grab an older version of boost to get it to work...
-Chris

YouTube | Twitter | Rad Raygun

“REAL ARTISTS SHIP” - Steve Jobs
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: Lua Bind

Post by Falco Girgis »

After nearly a day of waging a bloody battle against the compiler, I'm going to admit defeat. LuaBind isn't going to run on Dreamcast.

I was reading online, and apparently nobody with the GCC version that we have (ours is targetted at DC) has been able to get the Boost headers to work. The very next version up works, but the chances of a GCC version update for the DC compiler are probably next to none nowadays.

I tried everything. I even rewrote small sections of the Boost headers to try and hack it into working. No luck. I googled my final errors that I was unable to resolve and found several people who had the exact same issue. Not a single one of them resolved it. Two upgraded compilers and got it to work correctly and one switched from using LuaBind to using SWIG.

I'm now going to be looking into SWIG. It seems to do everything that I needed from LuaBind and is much lighter weight (and uses much less not-standardized-until-just-recently C++).
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: Lua Bind

Post by jesterguy »

Hey Ive been googling lots of lua and luabind stuff lately and I came across a post about something
called MLuaBind, its sposed to work without the boost stuff. Hope that helps.

thread i saw it in
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: Lua Bind

Post by Falco Girgis »

Wow, that was incredibly helpful. Looking at it, I think MLuaBind would work, but

Look at this: http://www.codenix.com/~tolua/tolua++.html

ToLua++ looks like what we're looking for. It generates wrapper code based on your header files, and generates .cpp/.c files that you compile with your project. It also offers OO capabilities to Lua.

That's pretty much all that I wanted. LuaBind is still pretty overkill. Using RTTI and all of that stuff on Dreamcast is something I would've liked to avoid, and toLua++ looks lightweight as hell.

Now I have to get home to try and build that bad boy on DC before I can celebrate. I've learned my lesson about getting too excited.
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: Lua Bind

Post by jesterguy »

That's interesting, I've seen some posts mentioning toLua but never actually looked at it since i had luabind working.
I think I'll try it out later, I like the idea of it generating all the functions its self. I don't think I'll be using it for anymore
then your planning to.
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: Lua Bind

Post by Falco Girgis »

So I promised myself that I wouldn't sleep until I confirmed that tolua++ would compile for DC.

...and it did. Easily. No hacking required at all.

It's also a tiny library, like 5 .c files and 2 .h files. Everything is looking good. I'll actually get to play around with it on Dreamcast tomorrow, but I had school, work, and gym today, so I'm tired. At least I can rest knowing that it'll work! :)
User avatar
trufun202
Game Developer
Game Developer
Posts: 1105
Joined: Sun Sep 21, 2008 12:27 am
Location: Dallas, TX
Contact:

Re: Lua Bind

Post by trufun202 »

GyroVorbis wrote:... but I had school, work, and gym today, so I'm tired. At least I can rest knowing that it'll work! :)
Falco, this is off topic, but what kinda work do you do? Just curious. When I was 19, I still worked at GameStop. I didn't get my first programming gig until I was 20.
-Chris

YouTube | Twitter | Rad Raygun

“REAL ARTISTS SHIP” - Steve Jobs
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: Lua Bind

Post by Falco Girgis »

I work for a government contractor. I'm contracted out to the US Army at the Redstone Arsenal in Hunstville, AL. It sounds flashy, but I'm just a coop student. I'm here every other semester. What I do ranges from trivial programming tasks (text file parsing, PHP scripts, databases) to certain hardware-related tasks like looking over schematics, helping wire things, and running some automated tests. It's much less software and more hardware. I was hired for a position that is technically considered "electrical engineering," but being a "computer engineering" major, they figured that I could work as a Red Mage.
User avatar
trufun202
Game Developer
Game Developer
Posts: 1105
Joined: Sun Sep 21, 2008 12:27 am
Location: Dallas, TX
Contact:

Re: Lua Bind

Post by trufun202 »

Nifty. Do you plan to go after a job in game development?

Honestly, I have only one regret in my career, and that's not jumping into the gaming industry early. My first programming job was doing web development for a lawfirm, and my career grew from there. I love being a software engineer at an advertising agency, but I never found the right time to make the leap into gaming.

So now, indie game development is about my only option - cuz I've got a wife, a house, and two cars to pay for. :P If I made the jump to gaming, I'd be a lower-end developer and take a noticiable salary hit.

Yeah, yeah, pitiful me, I know... Just figured I'd pass along some words of wisdom. :lol:
-Chris

YouTube | Twitter | Rad Raygun

“REAL ARTISTS SHIP” - Steve Jobs
Post Reply