mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
Add lua::toString which converts value to a string
This commit is contained in:
parent
d945663162
commit
da05115506
2 changed files with 11 additions and 0 deletions
|
@ -146,5 +146,12 @@ bool peek(lua_State *L, std::string *out, StackIdx idx)
|
||||||
*out = std::string(str, len);
|
*out = std::string(str, len);
|
||||||
return true;
|
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
|
} // namespace chatterino::lua
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
|
|
||||||
# include <QList>
|
# include <QList>
|
||||||
|
|
||||||
|
# include <string>
|
||||||
# include <vector>
|
# include <vector>
|
||||||
struct lua_State;
|
struct lua_State;
|
||||||
class QJsonObject;
|
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, QByteArray *out, StackIdx idx = -1);
|
||||||
bool peek(lua_State *L, std::string *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
|
/// TEMPLATES
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
|
|
Loading…
Reference in a new issue