On 2/24/06, klaas.holwerda <kho...@xs...> wrote:
> After hours of searching around what i possibly do wrong i give up.
> It is the next peace of code in canlua.cpp
>
> It call the hit function in the script incircles.lua, and i tested
> that it does ( after loading it from the menu in the sample of course ).
> But somehow the boolean return result is totally wrong.
Fixed, I think, I added a printf for testing (like your wxLogDebug)
and it shows 0 or 1 depending where the mouse is.
> I went as far as calling a lua function which adds two numbers, and
> return that number, and it has the same behaviour.
> Meaning that at least the first time the result is at number 9 on the
> returned stack?? It even tells there are 9 result, while i think there
> is only one.
> With lst.GetBooleanType(0) the application just stops, there is an error
> generated in the check for the boolean type, but where that error end up
> is not clear to me.
It kills lua if running, calling lua_error, see wxLuaState::terror.
The pushed functions and callbacks continue to work however, but since
you're running code from C, I'm not sure what happens either.
lua_error does a long_jmp, but to where I dunno...
> It would be nice if the sample actually worked before the first release :=
-(
Agreed.
> bool wxlCanObjScript::DoIsHit( double x, double y, double absx, double
> absy )
> {
> double xh,yh;
> xh =3D x - absx;
> yh =3D y - absy;
>
> // run all statements in the script which should be returning a hit
> on the object or not
>
> wxLuaState lst =3D *(m_canvas->GetLuastate());
> lua_State* L =3D lst.GetLuaState();
> lua_getglobal( L, wx2lua(m_objectname + wxT("Hit")) );
>
> lst.lua_PushNumber( xh );
> lst.lua_PushNumber( yh );
>
> if ( lst.lua_PCall( 2, 1, 0 ) !=3D 0 )
> lst.SendErrorEvent( wxT("wrong hit function") );
>
// > int argCount =3D lua_gettop(L); don't need this?
> bool hit =3D lst.GetBooleanType(-1); want return value at top of sta=
ck
lst.lua_Pop(1); // pop returned value from stack to balance it
>
> //wxLogDebug( "hit %d", hit );
>
> if (hit)
> return true;
> return false;
> }
see
http://www.lua.org/pil/25.2.html
I'm committing the changes now.
Regards,
John Labenski
|