FORGET the last message, I sent it by accident when I pressed tab and
then enter.
On 2/7/07, John Labenski <[EMAIL PROTECTED]> wrote:
> On 2/6/07, Ryan Pusztai <[EMAIL PROTECTED]> wrote:
> > On 2/6/07, Ryan Pusztai <[EMAIL PROTECTED]> wrote:
> > > Well I am still a bit lost.
> > >
> > > First, here is the documentation for the function I want to wrap.
> > > /*!
> > > The constructor creates an timer object with the given
> > > properties. The timer at this moment is not started. This
> > > will be done with the start() member function.
> > > \param msec time interval after that the the variable
> > > pointed by exitflag is setting to one.
> > > \param exitflag the adress of an integer, which was set
> > > to one after the given time interval.
> > > \warning The integer variable shouldn't leave it's valid
> > > range, before the timer was finished. So never take a
> > > local variable.
> > > \param exitfnc A function, which was called after msec.
> > > If you don't want this, refer a NULL pointer.
> > > */
> > > timer(unsigned int msec,int* exitflag,void*(*exitfnc)(void*));
> > >
> > > I am willing to take the last parameter out for now, at least until I
> > > understand Lua/wxLua better. I still don't know how to just re-wrap
> > > the call to the function using 'NULL' as the third parameter and
> > > passing whatever the user wanted for the rest of the parameters.
> > >
> > > Here is a example, notice I just want to remove the third parameter
> > > and then write a function to override the default.
> > >
> > > Interface file: (.i)
> > >
> > > //-----------------------------------------------------------------------------
> > > // Timer class
> > >
> > > %class %delete %noclassinfo %encapsulate timer
> > > timer(unsigned int msec,int* exitflag)
> > > int start()
> > > int stop()
> > > %endclass
> > >
> > > I just don't know where to start on the overrides.hpp. I am sorry if
> > > my questions are simple. I just want to use wxLua without integrating
> > > it into an application for my first exercise. I have plans to, but as
> > > you can see I don't get the whole integrating wxLua with C++. Thanks
> > > for your patients.
> > >
> > > I don't know anything about the wxLua and C++ connection, so I don't
> > > understand the function
> > >
> > > "...new wxLuaObject(wxlState, 3);"
> > >
> > > What is the 3?
> >
> > I worked on a piece of code from looking at examples and this is the
> > best I could come up with. Most of it is sudo-code to give you an idea
> > of what I want to do.
Do you need to know when the exitFlag is 1? From the docs it looks
like in C++ you'd take an integer, set it to 0, call the timer(msec,
&exitFlag, NULL) and could then check exitFlag periodically to see if
the timer is done. A really lame hack could use a wxPoint (or better
yet your own minimal C++ class that has only an int member).
Alternatively if you will only make one timer call at a time you can
use "static int exitFlag" in the function and completely hide the
exitFlag from lua completely.
Lua code:
-- not local since it MUST exist for the life of the timer call
exitFlag = wx.wxPoint(0,0)
timer(1000, exitFlag)
> %override wxLua_function_timer
> // %function timer(unsigned int msec, int* exitflag)
> static int LUACALL wxLua_function_timer(lua_State *L)
> {
> wxLuaState wxlState(L);
// int* exitFlag = NULL; (could make this a static var if only
one timer call at a time)
wxPoint *exitFlag = (wxPoint *)wxlState.GetUserDataType(2,
s_wxluatag_wxPoint);
unsigned int mSec = (unsigned int)wxlState.GetNumberType(1);
>
> timer* returns;
>
> // call timer constructor
> returns = new timer(mSec, &exitFlag.x, NULL);
// let the lua garbage collector delete this when out of scope
wxLua_AddTrackedObject(wxlState, (timer*)returns);
> // push the result datatype
> wxlState.PushUserDataType(s_wxluatag_timer, returns);
>
> // return the number of parameters
return 1;
> }
> %end
I think the above should work. The easiest way to get the code above
is to change your timer function in the *.i file to
"timer(unsigned int msec, int exitflag)"
and then run the generator. You now have code that is close to what you want.
Note how we removed int* exitflag so that the generator works (it
actually might even work with the *exitFlag, but I don't think it
would compile since it'd be taking the address of a temporary since
lua uses only double and the generator would cast the returned double
from lua to a int. This is why I've used the wxPoint's int x member
var.
Hope this helps,
John Labenski
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier.
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
wxlua-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wxlua-users