Fix an issue related to the use of constexpr in luastack

This commit is contained in:
2023-05-08 13:32:22 -04:00
parent 8ea6c47e4c
commit 5ece3a71ba

View File

@@ -147,6 +147,7 @@
#include "wrap-set.hpp"
#include <cstring>
#include <type_traits>
#include <cassert>
#include "lua.h"
#include "lauxlib.h"
@@ -297,34 +298,45 @@ protected:
int nvar;
int nextra;
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>
constexpr static Counts count_slots(LuaRet &v, SS & ... stackslots)
template<class... SS>
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>
constexpr static Counts count_slots(LuaArg &v, SS & ... stackslots)
template<class... SS>
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>
constexpr static Counts count_slots(LuaVar &v, SS & ... stackslots)
template<class... SS>
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>
constexpr static Counts count_slots(LuaExtraArgs &v, SS & ... stackslots)
template<class... SS>
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() {
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.
void push_any_value(LuaNewTableMarker s) const { lua_newtable(L_); }
void push_any_value(LuaNilMarker s) const { lua_pushnil(L_); }
@@ -698,7 +710,7 @@ private:
public:
template<class... SS>
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);
if (counts.nextra == 0) {
if (nargs != counts.narg) {
@@ -757,13 +769,10 @@ private:
public:
template<class... SS>
LuaExtStack(lua_State *L, SS & ... stackslots) : LuaCoreStack(L) {
constexpr Counts counts = count_slots<0, 0, 0, 0>(stackslots...);
static_assert(counts.narg == 0, "LuaExtStack doesn't allow LuaArg parameters");
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);
int nvars = count_vars(stackslots...);
lua_checkstack(L_, nvars + 20);
oldtop_ = lua_gettop(L_);
for (int i = 0; i < counts.nvar; i++) {
for (int i = 0; i < nvars; i++) {
lua_pushnil(L_);
}
assign_slots(oldtop_ + 1, stackslots...);