From: klaas.holwerda <kho...@xs...> - 2006-02-24 20:48:28
|
Hi John, 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. 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. Do you have any idea what i am doing wrong? It would be nice if the sample actually worked before the first release :-( Thanks for some help if you can find the time. Thanks also for the nice changes, i hope to once understand them all :-) Klaas bool wxlCanObjScript::DoIsHit( double x, double y, double absx, double absy ) { double xh,yh; xh = x - absx; yh = y - absy; // run all statements in the script which should be returning a hit on the object or not wxLuaState lst = *(m_canvas->GetLuastate()); lua_State* L = 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 ) != 0 ) lst.SendErrorEvent( wxT("wrong hit function") ); int argCount = lua_gettop(L); bool hit = lst.GetBooleanType(9); //wxLogDebug( "hit %d", hit ); if (hit) return true; return false; } |
From: John L. <jla...@gm...> - 2006-02-24 22:17:18
|
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 |
From: klaas.holwerda <kho...@xs...> - 2006-02-25 00:14:08
|
John Labenski wrote: > > I'm committing the changes now. > Thanks a lot John, i have obviously have bin reading in the wrong locations somehow :-( I toke as an example the functions called in C++ like in the wrappings, but calling functions in lua seems to be different. But no i have a problem compiling wx_define.cpp ( line 107 syntax error ','), regenerated the bindings, but it does not help. Will look further tomorrow, its is already far to late ;-) regards, Klaas |