On 2/13/07, Ryan Pusztai <[EMAIL PROTECTED]> wrote:

> > Interface file:
> > %class %delete %noclassinfo %encapsulate wxSerialPort, wxSerialPort_x
> >         wxSerialPort()
> >
> >         // Serial port initilization
> >         ...
> >         int Open(const char* devname, void* dcs)
> >         ...
> > %endclass
> >
> > Generated function:
> >
> > static int LUACALL wxLua_wxSerialPort_Open(lua_State *L)
> > {
> >     wxLuaState wxlState(L);
> >     int returns;
> >     // void dcs
> >     void * dcs = (void *)wxlState.ttouserdata(3);
> >     // const char devname
> >     const char * devname = (const char *)wxlState.ttouserdata(2);
> >     // get this
> >     wxSerialPort * self = (wxSerialPort *)wxlState.GetUserDataType(1,
> > s_wxluatag_wxSerialPort);
> >     // call Open
> >     returns = self->Open(devname, dcs);
> >     // push the result number
> >     lua_pushnumber(L, returns);
> >
> >     return 1;
> > }
> >
> > Using it in wxLua:
> >
> > -- device control struct for additional (and device specific
> > -- settings)
> > dcs = wxctb.wxSerialPort_DCS()
> >
> > -- dcs was initiate with 19200 1N8, but you can change
> > -- these with your own settings
> > dcs:SetBaud( baudrate )
> > dcs:SetWordLen( 8 )
> > dcs:SetParity( wxctb.wxPARITY_NONE )
> > dcs:SetStopBits( 1 )
> >
> > -- Create the wxSerialPort variable.
> > com = wxctb.wxSerialPort()
> >
> > -- try to open the given comport
> > if ( com:Open( devname, dcs ) < 0 ) then -- <- this call fails everytime
> >    -- port is not available (wrong or in use)
> >    print( "An error occurred when opening serial port \""..devname.."\"" )
> >    return 1
> > end
> >
> > It keeps failing. I can call other functions that I have wrapped, but
> > the reference to a class doesn't seem to work well for me,
>
> Jon and all,
> Any ideas on this? I am stuck till I can figure this out.

There's two problems, the first is that dcs is a "void*" data which
genwxbind.lua is treating as the userdata pointer which is not the
data itself. Is wxSerialPort_DCS a struct? Maybe you should replace
the binding line with

int Open(const char* devname, wxSerialPort_DCS* dcs)

or override the generated binding with

void * dcs = (void *)wxlState.GetUserDataType(3, s_wxluatag_wxSerialPort_DCS);

secondly, "const char*" is not correctly interpreted in genwxbind.lua
(fixed in cvs) the binding line should be

const char * devname = (const char *)wxlState.GetStringType(2);

hope this helps.
    John Labenski

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
wxlua-users mailing list
wxlua-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wxlua-users

Reply via email to