Page 1 of 1

Lua wrapping overloaded functions situation.

Posted: Sun Oct 19, 2008 4:51 pm
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?

Re: Lua wrapping overloaded functions situation.

Posted: Sun Oct 19, 2008 5:10 pm
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...

Re: Lua wrapping overloaded functions situation.

Posted: Tue Oct 21, 2008 8:58 am
by MarauderIIC

Re: Lua wrapping overloaded functions situation.

Posted: Tue Oct 21, 2008 9:06 am
by Falco Girgis
That's the exact document that I used, actually.