diff --git a/src/controllers/plugins/LuaUtilities.cpp b/src/controllers/plugins/LuaUtilities.cpp index 3726f7d63..ee8183ad7 100644 --- a/src/controllers/plugins/LuaUtilities.cpp +++ b/src/controllers/plugins/LuaUtilities.cpp @@ -2,6 +2,7 @@ #ifdef CHATTERINO_HAVE_PLUGINS # include "common/Channel.hpp" +# include "common/QLogging.hpp" # include "controllers/commands/CommandContext.hpp" # include "lauxlib.h" # include "lua.h" @@ -11,6 +12,43 @@ namespace chatterino::lua { +void stackDump(lua_State *L, const QString &tag) +{ + qCDebug(chatterinoLua) << "--------------------"; + auto count = lua_gettop(L); + if (!tag.isEmpty()) + { + qCDebug(chatterinoLua) << "Tag: " << tag; + } + qCDebug(chatterinoLua) << "Count elems: " << count; + for (int i = 1; i <= count; i++) + { + auto typeint = lua_type(L, i); + if (typeint == LUA_TSTRING) + { + QString str; + lua::peek(L, &str, i); + qCDebug(chatterinoLua) + << "At" << i << "is a" << lua_typename(L, typeint) << "(" + << typeint << "): " << str; + } + else if (typeint == LUA_TTABLE) + { + qCDebug(chatterinoLua) + << "At" << i << "is a" << lua_typename(L, typeint) << "(" + << typeint << ")" + << "its length is " << lua_rawlen(L, i); + } + else + { + qCDebug(chatterinoLua) + << "At" << i << "is a" << lua_typename(L, typeint) << "(" + << typeint << ")"; + } + } + qCDebug(chatterinoLua) << "--------------------"; +} + QString humanErrorText(lua_State *L, int errCode) { QString errName; diff --git a/src/controllers/plugins/LuaUtilities.hpp b/src/controllers/plugins/LuaUtilities.hpp index 817b11386..e5f6f98fd 100644 --- a/src/controllers/plugins/LuaUtilities.hpp +++ b/src/controllers/plugins/LuaUtilities.hpp @@ -19,6 +19,13 @@ struct CommandContext; namespace chatterino::lua { +/** + * @brief Dumps the Lua stack into qCDebug(chatterinoLua) + * + * @param tag is a string to let you know which dump is which when browsing logs + */ +void stackDump(lua_State *L, const QString &tag); + /** * @brief Converts a lua error code and potentially string on top of the stack into a human readable message */