diff --git a/src/controllers/plugins/LuaUtilities.cpp b/src/controllers/plugins/LuaUtilities.cpp index e02170e99..3726f7d63 100644 --- a/src/controllers/plugins/LuaUtilities.cpp +++ b/src/controllers/plugins/LuaUtilities.cpp @@ -146,5 +146,12 @@ bool peek(lua_State *L, std::string *out, StackIdx idx) *out = std::string(str, len); return true; } + +QString toString(lua_State *L, StackIdx idx) +{ + size_t len{}; + const auto *ptr = luaL_tolstring(L, idx, &len); + return QString::fromUtf8(ptr, int(len)); +} } // namespace chatterino::lua #endif diff --git a/src/controllers/plugins/LuaUtilities.hpp b/src/controllers/plugins/LuaUtilities.hpp index 132a1e26e..eb0a8d661 100644 --- a/src/controllers/plugins/LuaUtilities.hpp +++ b/src/controllers/plugins/LuaUtilities.hpp @@ -5,6 +5,7 @@ # include +# include # include struct lua_State; class QJsonObject; @@ -35,6 +36,9 @@ bool peek(lua_State *L, QString *out, StackIdx idx = -1); bool peek(lua_State *L, QByteArray *out, StackIdx idx = -1); bool peek(lua_State *L, std::string *out, StackIdx idx = -1); +// forces conversion of value at idx to a string +QString toString(lua_State *L, StackIdx idx = -1); + /// TEMPLATES template