mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
Add lua::peek for QByteArray
This commit is contained in:
parent
3013e73e94
commit
24c6003043
2 changed files with 17 additions and 0 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue