mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
Add a StackIdx type alias
This commit is contained in:
parent
082420b94a
commit
ca0bfb1900
2 changed files with 18 additions and 15 deletions
|
@ -9,25 +9,26 @@
|
|||
#include <cstdlib>
|
||||
|
||||
namespace chatterino::lua {
|
||||
int pushEmptyArray(lua_State *L, int countArray)
|
||||
|
||||
StackIdx pushEmptyArray(lua_State *L, int countArray)
|
||||
{
|
||||
lua_createtable(L, countArray, 0);
|
||||
return lua_gettop(L);
|
||||
}
|
||||
|
||||
int pushEmptyTable(lua_State *L, int countProperties)
|
||||
StackIdx pushEmptyTable(lua_State *L, int countProperties)
|
||||
{
|
||||
lua_createtable(L, 0, countProperties);
|
||||
return lua_gettop(L);
|
||||
}
|
||||
|
||||
int push(lua_State *L, const QString &str)
|
||||
StackIdx push(lua_State *L, const QString &str)
|
||||
{
|
||||
lua_pushstring(L, str.toStdString().c_str());
|
||||
return lua_gettop(L);
|
||||
}
|
||||
|
||||
int push(lua_State *L, const CommandContext &ctx)
|
||||
StackIdx push(lua_State *L, const CommandContext &ctx)
|
||||
{
|
||||
auto outIdx = pushEmptyTable(L, 2);
|
||||
|
||||
|
@ -39,13 +40,13 @@ int push(lua_State *L, const CommandContext &ctx)
|
|||
return outIdx;
|
||||
}
|
||||
|
||||
int push(lua_State *L, const bool &b)
|
||||
StackIdx push(lua_State *L, const bool &b)
|
||||
{
|
||||
lua_pushboolean(L, int(b));
|
||||
return lua_gettop(L);
|
||||
}
|
||||
|
||||
bool peek(lua_State *L, double *out, int idx)
|
||||
bool peek(lua_State *L, double *out, StackIdx idx)
|
||||
{
|
||||
int ok{0};
|
||||
auto v = lua_tonumberx(L, idx, &ok);
|
||||
|
@ -56,7 +57,7 @@ bool peek(lua_State *L, double *out, int idx)
|
|||
return ok != 0;
|
||||
}
|
||||
|
||||
bool peek(lua_State *L, QString *out, int idx)
|
||||
bool peek(lua_State *L, QString *out, StackIdx idx)
|
||||
{
|
||||
size_t len{0};
|
||||
const char *str = lua_tolstring(L, idx, &len);
|
||||
|
|
|
@ -12,16 +12,18 @@ class CommandContext;
|
|||
|
||||
namespace chatterino::lua {
|
||||
|
||||
int pushEmptyArray(lua_State *L, int countArray);
|
||||
int pushEmptyTable(lua_State *L, int countProperties);
|
||||
using StackIdx = int;
|
||||
|
||||
int push(lua_State *L, const CommandContext &ctx);
|
||||
int push(lua_State *L, const QString &str);
|
||||
int push(lua_State *L, const bool &b);
|
||||
StackIdx pushEmptyArray(lua_State *L, int countArray);
|
||||
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 bool &b);
|
||||
|
||||
// returns OK?
|
||||
bool peek(lua_State *L, double *out, int idx = -1);
|
||||
bool peek(lua_State *L, QString *out, int idx = -1);
|
||||
bool peek(lua_State *L, double *out, StackIdx idx = -1);
|
||||
bool peek(lua_State *L, QString *out, StackIdx idx = -1);
|
||||
|
||||
/// TEMPLATES
|
||||
|
||||
|
@ -54,7 +56,7 @@ int push(lua_State *L, QList<T> vec)
|
|||
}
|
||||
|
||||
template <typename T>
|
||||
bool pop(lua_State *L, T *out, int idx = -1)
|
||||
bool pop(lua_State *L, T *out, StackIdx idx = -1)
|
||||
{
|
||||
auto ok = peek(L, out, idx);
|
||||
if (ok)
|
||||
|
|
Loading…
Reference in a new issue