Add lua::toString which converts value to a string

This commit is contained in:
Mm2PL 2023-02-08 23:57:32 +01:00
parent d945663162
commit da05115506
No known key found for this signature in database
GPG key ID: 94AC9B80EFA15ED9
2 changed files with 11 additions and 0 deletions

View file

@ -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

View file

@ -5,6 +5,7 @@
# include <QList>
# include <string>
# include <vector>
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 <typename T>