summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormadmaxoft <github@xoft.cz>2013-08-21 20:06:37 +0200
committermadmaxoft <github@xoft.cz>2013-08-21 20:06:37 +0200
commite0e8e18ab20ee4815424832afe2cba958ec1b2f2 (patch)
tree15881f9f7d23221ea2ca0cedaf591f7e86b4fff9
parentIgnoring all memdump files. (diff)
downloadcuberite-e0e8e18ab20ee4815424832afe2cba958ec1b2f2.tar
cuberite-e0e8e18ab20ee4815424832afe2cba958ec1b2f2.tar.gz
cuberite-e0e8e18ab20ee4815424832afe2cba958ec1b2f2.tar.bz2
cuberite-e0e8e18ab20ee4815424832afe2cba958ec1b2f2.tar.lz
cuberite-e0e8e18ab20ee4815424832afe2cba958ec1b2f2.tar.xz
cuberite-e0e8e18ab20ee4815424832afe2cba958ec1b2f2.tar.zst
cuberite-e0e8e18ab20ee4815424832afe2cba958ec1b2f2.zip
Diffstat (limited to '')
-rw-r--r--source/LuaState.cpp43
-rw-r--r--source/LuaState.h6
2 files changed, 49 insertions, 0 deletions
diff --git a/source/LuaState.cpp b/source/LuaState.cpp
index bbf47fb27..8d2fa8eca 100644
--- a/source/LuaState.cpp
+++ b/source/LuaState.cpp
@@ -884,6 +884,49 @@ bool cLuaState::ReportErrors(lua_State * a_LuaState, int a_Status)
+void cLuaState::LogStackTrace(void)
+{
+ LOGWARNING("Stack trace:");
+ lua_Debug entry;
+ int depth = 0;
+ while (lua_getstack(m_LuaState, depth, &entry))
+ {
+ int status = lua_getinfo(m_LuaState, "Sln", &entry);
+ assert(status);
+
+ LOGWARNING(" %s(%d): %s", entry.short_src, entry.currentline, entry.name ? entry.name : "?");
+ depth++;
+ }
+ LOGWARNING("Stack trace end");
+}
+
+
+
+
+
+AString cLuaState::GetTypeText(int a_StackPos)
+{
+ int Type = lua_type(m_LuaState, a_StackPos);
+ switch (Type)
+ {
+ case LUA_TNONE: return "TNONE";
+ case LUA_TNIL: return "TNIL";
+ case LUA_TBOOLEAN: return "TBOOLEAN";
+ case LUA_TLIGHTUSERDATA: return "TLIGHTUSERDATA";
+ case LUA_TNUMBER: return "TNUMBER";
+ case LUA_TSTRING: return "TSTRING";
+ case LUA_TTABLE: return "TTABLE";
+ case LUA_TFUNCTION: return "TFUNCTION";
+ case LUA_TUSERDATA: return "TUSERDATA";
+ case LUA_TTHREAD: return "TTHREAD";
+ }
+ return Printf("Unknown (%d)", Type);
+}
+
+
+
+
+
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// cLuaState::cRef:
diff --git a/source/LuaState.h b/source/LuaState.h
index 0eae8206d..aa2a4af0f 100644
--- a/source/LuaState.h
+++ b/source/LuaState.h
@@ -782,6 +782,12 @@ public:
/// If the status is nonzero, prints the text on the top of Lua stack and returns true
static bool ReportErrors(lua_State * a_LuaState, int status);
+ /// Logs all items in the current stack trace to the server console
+ void LogStackTrace(void);
+
+ /// Returns the type of the item on the specified position in the stack
+ AString GetTypeText(int a_StackPos);
+
protected:
lua_State * m_LuaState;