mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
Add stackDump lua utility, for debugging or tests
This commit is contained in:
parent
5b9f3e95ee
commit
3625f5706b
2 changed files with 45 additions and 0 deletions
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue