From d96cd236f3e983ff35ef16f7c9979c8341d5ae0c Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Sat, 3 Dec 2011 02:45:55 +0200 Subject: Enforced mod global naming convention and better error reporting --- src/script.cpp | 46 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) (limited to 'src/script.cpp') diff --git a/src/script.cpp b/src/script.cpp index 5a6c98026..8b1b7013e 100644 --- a/src/script.cpp +++ b/src/script.cpp @@ -31,6 +31,27 @@ extern "C" { #include } +LuaError::LuaError(lua_State *L, const std::string &s) +{ + m_s = "LuaError: "; + m_s += s + "\n"; + lua_getfield(L, LUA_GLOBALSINDEX, "debug"); + if(lua_istable(L, -1)){ + lua_getfield(L, -1, "traceback"); + if(lua_isfunction(L, -1)){ + lua_call(L, 0, 1); + if(lua_isstring(L, -1)){ + m_s += lua_tostring(L, -1); + } + lua_pop(L, 1); + } + else{ + lua_pop(L, 1); + } + } + lua_pop(L, 1); +} + void script_error(lua_State *L, const char *fmt, ...) { va_list argp; @@ -39,13 +60,34 @@ void script_error(lua_State *L, const char *fmt, ...) vsnprintf(buf, 10000, fmt, argp); va_end(argp); //errorstream<<"SCRIPT ERROR: "<