mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
Add lua::{peek,push} support for std::string
This commit is contained in:
parent
0a9fa2fe09
commit
d945663162
2 changed files with 24 additions and 1 deletions
|
@ -61,7 +61,12 @@ StackIdx pushEmptyTable(lua_State *L, int countProperties)
|
|||
|
||||
StackIdx push(lua_State *L, const QString &str)
|
||||
{
|
||||
lua_pushstring(L, str.toStdString().c_str());
|
||||
return lua::push(L, str.toStdString());
|
||||
}
|
||||
|
||||
StackIdx push(lua_State *L, const std::string &str)
|
||||
{
|
||||
lua_pushstring(L, str.c_str());
|
||||
return lua_gettop(L);
|
||||
}
|
||||
|
||||
|
@ -125,5 +130,21 @@ bool peek(lua_State *L, QByteArray *out, StackIdx idx)
|
|||
*out = QByteArray(str, int(len));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool peek(lua_State *L, std::string *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 = std::string(str, len);
|
||||
return true;
|
||||
}
|
||||
} // namespace chatterino::lua
|
||||
#endif
|
||||
|
|
|
@ -26,12 +26,14 @@ StackIdx pushEmptyTable(lua_State *L, int countProperties);
|
|||
|
||||
StackIdx push(lua_State *L, const CommandContext &ctx);
|
||||
StackIdx push(lua_State *L, const QString &str);
|
||||
StackIdx push(lua_State *L, const std::string &str);
|
||||
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);
|
||||
bool peek(lua_State *L, std::string *out, StackIdx idx = -1);
|
||||
|
||||
/// TEMPLATES
|
||||
|
||||
|
|
Loading…
Reference in a new issue