Merge branch 'main' of https://github.com/jyelon/luprex into main
This commit is contained in:
@@ -147,6 +147,7 @@
|
|||||||
#include "wrap-set.hpp"
|
#include "wrap-set.hpp"
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
#include "lua.h"
|
#include "lua.h"
|
||||||
#include "lauxlib.h"
|
#include "lauxlib.h"
|
||||||
@@ -296,34 +297,45 @@ protected:
|
|||||||
int nvar;
|
int nvar;
|
||||||
int nextra;
|
int nextra;
|
||||||
constexpr Counts(int nr, int na, int nv, int ne) : nret(nr), narg(na), nvar(nv), nextra(ne) {}
|
constexpr Counts(int nr, int na, int nv, int ne) : nret(nr), narg(na), nvar(nv), nextra(ne) {}
|
||||||
|
constexpr Counts(Counts a, Counts b)
|
||||||
|
: nret(a.nret+b.nret), narg(a.narg+b.narg), nvar(a.nvar+b.nvar), nextra(a.nextra+b.nextra) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
template<int NRET, int NARG, int NVAR, int NEXTRA, class... SS>
|
template<class... SS>
|
||||||
constexpr static Counts count_slots(LuaRet &v, SS & ... stackslots)
|
constexpr static Counts count_slots(LuaRet &v, SS && ... stackslots)
|
||||||
{
|
{
|
||||||
return count_slots<NRET+1, NARG, NVAR, NEXTRA>(stackslots...);
|
return Counts(Counts(1, 0, 0, 0), count_slots(stackslots...));
|
||||||
}
|
}
|
||||||
template<int NRET, int NARG, int NVAR, int NEXTRA, class... SS>
|
template<class... SS>
|
||||||
constexpr static Counts count_slots(LuaArg &v, SS & ... stackslots)
|
constexpr static Counts count_slots(LuaArg &v, SS && ... stackslots)
|
||||||
{
|
{
|
||||||
return count_slots<NRET, NARG+1, NVAR, NEXTRA>(stackslots...);
|
return Counts(Counts(0, 1, 0, 0), count_slots(stackslots...));
|
||||||
}
|
}
|
||||||
template<int NRET, int NARG, int NVAR, int NEXTRA, class... SS>
|
template<class... SS>
|
||||||
constexpr static Counts count_slots(LuaVar &v, SS & ... stackslots)
|
constexpr static Counts count_slots(LuaVar &v, SS && ... stackslots)
|
||||||
{
|
{
|
||||||
return count_slots<NRET, NARG, NVAR+1, NEXTRA>(stackslots...);
|
return Counts(Counts(0, 0, 1, 0), count_slots(stackslots...));
|
||||||
}
|
}
|
||||||
template<int NRET, int NARG, int NVAR, int NEXTRA, class... SS>
|
template<class... SS>
|
||||||
constexpr static Counts count_slots(LuaExtraArgs &v, SS & ... stackslots)
|
constexpr static Counts count_slots(LuaExtraArgs &v, SS && ... stackslots)
|
||||||
{
|
{
|
||||||
return count_slots<NRET, NARG, NVAR, NEXTRA+1>(stackslots...);
|
return Counts(Counts(0, 0, 0, 1), count_slots(stackslots...));
|
||||||
}
|
}
|
||||||
template<int NRET, int NARG, int NVAR, int NEXTRA>
|
|
||||||
constexpr static Counts count_slots() {
|
constexpr static Counts count_slots() {
|
||||||
return Counts(NRET, NARG, NVAR, NEXTRA);
|
return Counts(0, 0, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
|
||||||
|
template<class... SS>
|
||||||
|
constexpr static int count_vars(LuaVar &v, SS && ... stackslots)
|
||||||
|
{
|
||||||
|
return 1 + count_vars(stackslots...);
|
||||||
|
}
|
||||||
|
constexpr static int count_vars() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
// Push any value on the stack, by type.
|
// Push any value on the stack, by type.
|
||||||
void push_any_value(LuaNewTableMarker s) const { lua_newtable(L_); }
|
void push_any_value(LuaNewTableMarker s) const { lua_newtable(L_); }
|
||||||
void push_any_value(LuaNilMarker s) const { lua_pushnil(L_); }
|
void push_any_value(LuaNilMarker s) const { lua_pushnil(L_); }
|
||||||
@@ -587,7 +599,7 @@ private:
|
|||||||
public:
|
public:
|
||||||
template<class... SS>
|
template<class... SS>
|
||||||
inline LuaDefStack(lua_State *L, SS & ... stackslots) : LuaCoreStack(L) {
|
inline LuaDefStack(lua_State *L, SS & ... stackslots) : LuaCoreStack(L) {
|
||||||
constexpr Counts counts = count_slots<0, 0, 0, 0>(stackslots...);
|
Counts counts = count_slots(stackslots...);
|
||||||
int nargs = lua_gettop(L);
|
int nargs = lua_gettop(L);
|
||||||
if (counts.nextra == 0) {
|
if (counts.nextra == 0) {
|
||||||
if (nargs != counts.narg) {
|
if (nargs != counts.narg) {
|
||||||
@@ -645,13 +657,10 @@ private:
|
|||||||
public:
|
public:
|
||||||
template<class... SS>
|
template<class... SS>
|
||||||
LuaExtStack(lua_State *L, SS & ... stackslots) : LuaCoreStack(L) {
|
LuaExtStack(lua_State *L, SS & ... stackslots) : LuaCoreStack(L) {
|
||||||
constexpr Counts counts = count_slots<0, 0, 0, 0>(stackslots...);
|
int nvars = count_vars(stackslots...);
|
||||||
static_assert(counts.narg == 0, "LuaExtStack doesn't allow LuaArg parameters");
|
lua_checkstack(L_, nvars + 20);
|
||||||
static_assert(counts.nret == 0, "LuaExtStack doesn't allow LuaRet parameters");
|
|
||||||
static_assert(counts.nextra == 0, "LuaExtStack doesn't allow LuaExtraArgs parameters");
|
|
||||||
lua_checkstack(L_, counts.nvar + 20);
|
|
||||||
oldtop_ = lua_gettop(L_);
|
oldtop_ = lua_gettop(L_);
|
||||||
for (int i = 0; i < counts.nvar; i++) {
|
for (int i = 0; i < nvars; i++) {
|
||||||
lua_pushnil(L_);
|
lua_pushnil(L_);
|
||||||
}
|
}
|
||||||
assign_slots(oldtop_ + 1, stackslots...);
|
assign_slots(oldtop_ + 1, stackslots...);
|
||||||
|
|||||||
Reference in New Issue
Block a user