Lua wrapping overloaded functions situation.

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
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 wrapping overloaded functions situation.

Post by Falco Girgis »

So I've decided that I'm pretty much screwed, but I'd like to come here and bitch about it. Sort of like a rape victim, I have just taken it in the ass, but in order for my experience to mean something to myself, I have to make light of the situation and convince myself that I can use this experience to help others.

I have these functions in inventory:

Code: Select all

AddItem(int number)
AddItem(char *name)
I want to be able to do either AddItem("potion") or AddItem(3) to add a potion. But nooooooo! I CAN'T.

I am pretty sure that this situation isn't restricted to toLua++. Or maybe it is, but I'm boned nonetheless. When you pass it a 3, it considers that also a valid Lua string. Which is okay, but it appears that toLua++ doesn't handle that. There should be a way to specify a priority or something. Like if the function signature with "int" works, go with it, otherwise go to "string." An int is a valid int and string, but a string is not a valid integer. But I don't see any way that toLua++ would let you do this.

How does LuaBind/SWIG/whatever wrapper generator you guys are using handle this shitty scenario?
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 wrapping overloaded functions situation.

Post by Falco Girgis »

OH HELL YES, NEVERMIND!

I got cocky, so I started manually editing the wrapper files that toLua++ was spitting out. It said that if you arrange the order that they're defined, it adjusts their priority. So I went in and tried to do it manually rather than running my header back through toLua++ again (being lazy actually would've been better here).

Because it was doing this:

Code: Select all

void AddItem(char) {

    if(didn't work)
    return AddItem(int)
}

void AddItem(int) {

    return 0;
}
So the integer matched the string case and didn't bother running the integer function. When I switched the order, it would only try AddItem then stop, because AddItem was returning a 0 (rather than returning a call to the char-based function).

So reparsing back through my header file reversed their priority. At least I learned something about how toLua++'s internals work...
User avatar
MarauderIIC
Respected Programmer
Respected Programmer
Posts: 3406
Joined: Sat Jul 10, 2004 3:05 pm
Location: Maryland, USA

Re: Lua wrapping overloaded functions situation.

Post by MarauderIIC »

I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.
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 wrapping overloaded functions situation.

Post by Falco Girgis »

That's the exact document that I used, actually.
Post Reply