From 0d2de2ba9c616862d7881f089382db772d034f89 Mon Sep 17 00:00:00 2001 From: Alexander Date: Sun, 27 Oct 2019 17:25:16 -0400 Subject: Various updates --- src/client/callbackhandeler.cpp | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) (limited to 'src/client/callbackhandeler.cpp') diff --git a/src/client/callbackhandeler.cpp b/src/client/callbackhandeler.cpp index 0f1f87f..d522e84 100644 --- a/src/client/callbackhandeler.cpp +++ b/src/client/callbackhandeler.cpp @@ -1,6 +1,7 @@ #include #include #include +#include extern "C" { #include #include @@ -38,8 +39,10 @@ GlobalEventReceiver::GlobalEventReceiver(IrrlichtDevice* d){ //device = d; } + int callMouse(lua_State* L, const char* funcname, double x, double y, double event){ int consume = 0; + assert(lua_gettop(L) == 0); lua_getglobal(L,"GAME");//GAME pusherrorfunc(L);//{GAME},errfun lua_getfield(L,-2,funcname);//{GAME},errfunc,funcname? @@ -53,18 +56,22 @@ int callMouse(lua_State* L, const char* funcname, double x, double y, double eve }else{ if(!lua_isnil(L,-1)){ consume = lua_toboolean(L,-1); - lua_pop(L,-1); } } - lua_pop(L,2); + lua_pop(L,3); + assert(lua_gettop(L) == 0); }else{ //{GAME},errfunc,nil lua_pop(L,3);// + assert(lua_gettop(L) == 0); } + assert(lua_gettop(L) == 0); return consume; } bool GlobalEventReceiver::OnEvent(const SEvent& e){ + //printf("Onevent triggered when top was %d\n", lua_gettop(L)); + assert(lua_gettop(L) == 0); //lua_State* L = this->L; EEVENT_TYPE type = e.EventType; SEvent::SMouseInput se = e.MouseInput; @@ -95,7 +102,7 @@ bool GlobalEventReceiver::OnEvent(const SEvent& e){ case EGET_LISTBOX_SELECTED_AGAIN: fieldname = "onSame"; break; case EGET_FILE_SELECTED: fieldname = "onFileSelect"; break; case EGET_DIRECTORY_SELECTED: fieldname = "onDirectorySelect"; break; - case EGET_FILE_CHOOSE_DIALOG_CANCELLED: fieldname = "onFileChooserCancel"; break; + case EGET_FILE_CHOOSE_DIALOG_CANCELLED: fieldname = "onCanceled"; break; case EGET_MESSAGEBOX_YES: fieldname = "onYes"; break; case EGET_MESSAGEBOX_NO: fieldname = "onNo"; break; case EGET_MESSAGEBOX_OK: fieldname = "onOk"; break; @@ -122,6 +129,7 @@ bool GlobalEventReceiver::OnEvent(const SEvent& e){ if(lua_isnil(L,-1)){ printf("Element did not have a function %s, returning\n",fieldname); lua_pop(L,3);// + assert(lua_gettop(L) == 0); return false; } lua_rawgeti(L,LUA_REGISTRYINDEX,ref);//{guielement},errfunc(),func(),{guielement} @@ -130,9 +138,12 @@ bool GlobalEventReceiver::OnEvent(const SEvent& e){ if(!lua_isnil(L,-1)){ printf("Got an argument back!\n"); int ans = lua_toboolean(L,-1); + lua_pop(L,3); + assert(lua_gettop(L) == 0); return ans; } lua_pop(L,3);// + assert(lua_gettop(L) == 0); return false; } break; @@ -199,6 +210,7 @@ Detects any key presses from the game. case EET_KEY_INPUT_EVENT:{ //printf("Got input event\n"); SEvent::SKeyInput se = e.KeyInput; + assert(lua_gettop(L) == 0); lua_getglobal(L,"GAME");//{} lua_getfield(L,-1,"onKeyDown");//{},()|nil if(!lua_isnil(L,-1)){ @@ -210,10 +222,9 @@ Detects any key presses from the game. lua_pushboolean(L,se.Control);//{GAME},GAME.onKeyDown(),errfunc,onKeyDown(),key_number,is_down,is_ctrl lua_pushboolean(L,se.Shift);//{GAME},GAME.onKeyDown(),errfunc,onKeyDown(),key_number,is_down,is_ctrl,is_shift lua_pcall(L,4,0,-6);//GAME,GAME.onKeyDown() - lua_pop(L,2); - }else{ - lua_pop(L,2); } + lua_pop(L,lua_gettop(L)); + assert(lua_gettop(L) == 0); return false; break; } @@ -222,5 +233,6 @@ Detects any key presses from the game. return false; } } + assert(lua_gettop(L) == 0); return true; } -- cgit v1.2.3-70-g09d2