diff options
| author | Alexander Pickering <alex@cogarr.net> | 2018-10-31 12:40:59 -0400 |
|---|---|---|
| committer | Alexander Pickering <alex@cogarr.net> | 2018-10-31 12:40:59 -0400 |
| commit | 6e5697a125973bca83d368364e088777d23f824a (patch) | |
| tree | 3cb170028bb5af3bf58621db671d2715be518b8b /src/shared/lua_api/common.cpp | |
| parent | 6df9cb0de3e457788808b485b8b34bd8f0d6e42b (diff) | |
| download | brokengine-6e5697a125973bca83d368364e088777d23f824a.tar.gz brokengine-6e5697a125973bca83d368364e088777d23f824a.tar.bz2 brokengine-6e5697a125973bca83d368364e088777d23f824a.zip | |
Added error handeling function
Added an error handeling function to avoid crashes on errors in
callbacked handeled code (ex, error in button press)
Diffstat (limited to 'src/shared/lua_api/common.cpp')
| -rw-r--r-- | src/shared/lua_api/common.cpp | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/shared/lua_api/common.cpp b/src/shared/lua_api/common.cpp index 55f2b23..57d1db0 100644 --- a/src/shared/lua_api/common.cpp +++ b/src/shared/lua_api/common.cpp @@ -235,3 +235,41 @@ int popvector2i(lua_State* L, long* a, long* b){ return 0; } + +//errfunc("mssg",false) +int errfunc(lua_State *L){ + printf("Error function called\n"); + int nargs = lua_gettop(L); + for(int i = 1; i <= nargs; i++){ + printf("Arguemtn %d to errorfun was type %s\n",i,lua_typename(L,lua_type(L,i))); + } + if (!lua_isstring(L, 1)){ /* 'message' not a string? */ + printf("Error is not a string, it is a %s\n",lua_typename(L,lua_type(L,1))); + //return 1; [> keep it intact <] + } + printf("Error:%s\n",lua_tostring(L,1)); + lua_getglobal(L, "debug");//error,{debug} + lua_getglobal(L, "print");//error,{debug},print + if (!lua_istable(L, -2)) { + printf("debug is not a table, abort\n"); + lua_pop(L, 1); + return 1; + } + lua_getfield(L, -2, "traceback");//error,{debug},print,debug.traceback + if (!lua_isfunction(L, -1)) { + printf("debug does not have a .traceback function, abort\n"); + lua_pop(L, 2); + return 1; + } + lua_pushvalue(L, -4); //error,{debug},print,debug.traceback,error + //lua_pushinteger(L, 3); //error,{debug},print,debug.traceback,error,2 + lua_call(L, 2, 1);//error,{debug},print,str_traceback + printf("Error:%s\n",lua_tostring(L,-1)); + lua_call(L,1,0);//error,{debug} + lua_pop(L,1); + printf("Returning"); + return 1; +} +void pusherrorfunc(lua_State *L){ + lua_pushcfunction(L,errfunc); +} |
