diff --git a/src/controllers/plugins/LuaUtilities.cpp b/src/controllers/plugins/LuaUtilities.cpp index de5bb75af..e02170e99 100644 --- a/src/controllers/plugins/LuaUtilities.cpp +++ b/src/controllers/plugins/LuaUtilities.cpp @@ -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 diff --git a/src/controllers/plugins/LuaUtilities.hpp b/src/controllers/plugins/LuaUtilities.hpp index 029c74b09..132a1e26e 100644 --- a/src/controllers/plugins/LuaUtilities.hpp +++ b/src/controllers/plugins/LuaUtilities.hpp @@ -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