Add lua::peek for QByteArray

This commit is contained in:
Mm2PL 2023-02-04 01:20:41 +01:00
parent 3013e73e94
commit 24c6003043
No known key found for this signature in database
GPG key ID: 94AC9B80EFA15ED9
2 changed files with 17 additions and 0 deletions

View file

@ -109,5 +109,21 @@ bool peek(lua_State *L, QString *out, StackIdx idx)
*out = QString::fromUtf8(str, int(len));
return true;
}
bool peek(lua_State *L, QByteArray *out, StackIdx idx)
{
size_t len{0};
const char *str = lua_tolstring(L, idx, &len);
if (str == nullptr)
{
return false;
}
if (len >= INT_MAX)
{
assert(false && "string longer than INT_MAX, shit's fucked, yo");
}
*out = QByteArray(str, int(len));
return true;
}
} // namespace chatterino::lua
#endif

View file

@ -31,6 +31,7 @@ StackIdx push(lua_State *L, const bool &b);
// returns OK?
bool peek(lua_State *L, double *out, StackIdx idx = -1);
bool peek(lua_State *L, QString *out, StackIdx idx = -1);
bool peek(lua_State *L, QByteArray *out, StackIdx idx = -1);
/// TEMPLATES