On 4/17/06, Ray Gilbert <[EMAIL PROTECTED]> wrote:
> I would overwrite it - just note how we should generate overloaded
> function bindings.
>
> I was thinking that when genwxbind.lua member.AltName ~= member.Name we
> track overloads of member.Name and generate appropriate code.

All done! I hope I didn't step on your toes, but I had some free time
and figured I've give adding it to genwxbind.lua a shot.

You have to use a new "%overload" tag in the bindings. This is because
as you go through the .i files you don't know if you'll have duplicate
functions until after you've already written the binding code for the
earlier function. So if you had wxPoint(int, int) and wxPoint(const
wxPoint&) and *didn't* use the "%constructor" tag (or for members the
%rename tag) there would be two functions
wxPoint_constructor(lua_State*) and obviously you get a compile error.
I track these and just add a number from 1 to whatever so there's no
name clashes. Additionally the WXLUAMETHOD map would have already been
created with a "wxPoint" constructor in it and you'd never get to the
overload function.

Currently I've tested it with the wxPen constructors and
wxPen::SetColour and it seems to work nicely. You can see the code in
modules/wxbind/src/gdi.cpp bindings/wxwidgets/gdi.i.

I had to tweak the args in wxLuaState::CallOverloadedFunction since if
you call a member function the "self" is the first arg and we don't
want that. Other than that it works great and the error message is
really nice.

For testing you can use wxLuaEdit and try these out
a = wx.wxPen(wx.wxRED, 1, 1)
b = wx.wxPen(a)
b:SetColour("RED")
print(b:GetColour():Red())
b:SetColour(0,0,0)
print(b:GetColour():Red())
print(a:GetColour():Red())

255
0
255

-- test out a mistake
b:SetColour(1,2,3,4)

Err: lua: Error while running chunk
wxLua overloaded function SetColour(number, number, number, number)
has invalid argument 4 on method 01
wxLua Function Overload Table:
01. SetColour(number, number, number)
02. SetColour(string)
03. SetColour(userdata)

stack traceback:
        [C]: in function 'SetColour'
        [string "shell"]:1: in main chunk


Thanks,
    John Labenski


>
> -----Original Message-----
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] On Behalf Of John
> Labenski
> Sent: Tuesday, 18 April 2006 07:31
> To: wxlua-users@lists.sourceforge.net
> Subject: Re: [Wxlua-users] Re: Added Overloaded Function Capability To
> wxlstate
>
> On 4/17/06, Ray Gilbert <[EMAIL PROTECTED]> wrote:
> > Yep, I know that it will be over written. Just added it so you could
> see proof of concept.
> >
> > It should be added to genwxbind, but I will leave that to later.
>
> I need to overwrite it to fix some issues w/ wxWidgets CVS head.
> Should I keep it or just let it get overwritten?
>
> What do the bindings look like for them, is this ok or is there some
> sort of tag for it?
>
> %class ... wxColour
>     wxColour(const wxString& name)
>     wxColour(int r, int g, int b)
>     wxColour(const wxColour& colour)
>     // and for functions
>     bool DoStuff(int i)
>     bool DoStuff(const wxString& i)
>
> Thanks,
>     John Labenski
>
>
>
>
> > From: [EMAIL PROTECTED] on behalf of Francesco
> Montorsi
> > Sent: Tue 18/04/2006 12:08 AM
> > To: wxlua-users@lists.sourceforge.net
> > Subject: [Wxlua-users] Re: Added Overloaded Function Capability To
> wxlstate
> >
> >
> >
> > Hi,
> >
> > Ray Gilbert ha scritto:
> > > I have added the ability to add overloaded functions to wxLua
> > indeed this feature looks great !
> >
> > > - added
> > > test directly into wx_bind.cpp
> > >
> > > #define TESTOVERLOAD
> > > #if defined(TESTOVERLOAD)
> > > // Test Overloaded Function Binding
> > > // a std function binding
> > > static int LUACALL wx_TestOverLoad_Int(lua_State *L)
> > > {
> > >     wxLuaState wxlState(L);
> > >     wxString returns;
> > >     int argCount = lua_gettop(L);
> > >     int value = (argCount >= 1 ? (int)wxlState.GetNumberType(1) :
> 0);
> > >  returns = wxString::Format(wxT("wx.TestOverLoad(%d) called C
> Function
> > > wx_TestOverLoad_Int"), value);
> > >  lua_pushstring(L, wx2lua(returns) );
> > >     return 1;
> > > }
> > > // a std function binding
> > > static int LUACALL wx_TestOverLoad_String(lua_State *L)
> > > {
> > >     wxLuaState wxlState(L);
> > >     wxString returns;
> > >     int argCount = lua_gettop(L);
> > >     wxString value = (argCount >= 1 ?
> lua2wx(wxlState.GetStringType(1))
> > > : wxEmptyString);
> > I did a small fix in line above:
> >
> >      // wxT("") is required instead of wxEmptyString otherwise GCC
> says:
> >      //  ../modules/wxbind/src/wx_bind.cpp:52: error: operands to ?:
> > have different types
> >      wxString value = (argCount >= 1 ?
> lua2wx(wxlState.GetStringType(1))
> > : wxT(""));
> >
> > and just committed it; however I wonder: wx_bind.cpp is regenerated by
> > genwxbind.lua... so, adding this code directly in wx_bind.cpp doesn't
> > mean that next time it's regenerated, the code will be lost ?
> >
> > Francesco
> >
> >
> >
> > -------------------------------------------------------
> > This SF.Net email is sponsored by xPML, a groundbreaking scripting
> language
> > that extends applications into web and mobile media. Attend the live
> webcast
> > and join the prime developer group breaking into this new coding
> territory!
> >
> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
> > _______________________________________________
> > Wxlua-users mailing list
> > Wxlua-users@lists.sourceforge.net
> > https://lists.sourceforge.net/lists/listinfo/wxlua-users
> >
> >
> >
> >
>
>
> -------------------------------------------------------
> This SF.Net email is sponsored by xPML, a groundbreaking scripting
> language
> that extends applications into web and mobile media. Attend the live
> webcast
> and join the prime developer group breaking into this new coding
> territory!
> http://sel.as-us.falkag.net/sel?cmd=k&kid0944&bid$1720&dat1642
> _______________________________________________
> Wxlua-users mailing list
> Wxlua-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/wxlua-users
>
>
> -------------------------------------------------------
> This SF.Net email is sponsored by xPML, a groundbreaking scripting language
> that extends applications into web and mobile media. Attend the live webcast
> and join the prime developer group breaking into this new coding territory!
> http://sel.as-us.falkag.net/sel?cmdlnk&kid0944&bid$1720&dat1642
> _______________________________________________
> Wxlua-users mailing list
> Wxlua-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/wxlua-users
>


-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid0944&bid$1720&dat1642
_______________________________________________
Wxlua-users mailing list
Wxlua-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wxlua-users

Reply via email to