aboutsummaryrefslogtreecommitdiff
path: root/src/client/callbackhandeler.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/callbackhandeler.cpp')
-rw-r--r--src/client/callbackhandeler.cpp24
1 files changed, 18 insertions, 6 deletions
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 <stdio.h>
#include <stdlib.h>
#include <vector>
+#include <assert.h>
extern "C" {
#include <lua.h>
#include <lauxlib.h>
@@ -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;
}