LuaExtraArgs is now fully implemented, efficiently
This commit is contained in:
@@ -139,6 +139,9 @@ obj/eris/%.o: ext/eris-master/src/%.c
|
||||
obj/core/%.o: cpp/core/%.cpp
|
||||
$(GPP) -fPIC -I./ext/eris-master/src -I./cpp/wrap -I./cpp/core -o $@ -c $<
|
||||
|
||||
obj/core/%.s: cpp/core/%.cpp
|
||||
$(GPP) -S -fPIC -I./ext/eris-master/src -I./cpp/wrap -I./cpp/core -o $@ -c $<
|
||||
|
||||
obj/drv/%.o: cpp/drv/%.cpp
|
||||
$(GPP) -I./ext -I./src/drv -o $@ -c $<
|
||||
|
||||
|
||||
@@ -667,33 +667,8 @@ public:
|
||||
|
||||
class LuaDefStack : public LuaCoreStack {
|
||||
private:
|
||||
int top_;
|
||||
int nret_;
|
||||
|
||||
template<int RETP, int ARGP, int VARP, int EXTRAP, int EXTRAC, class... SS>
|
||||
void assign_slots(LuaRet &v, SS & ... stackslots) {
|
||||
v.index_ = RETP;
|
||||
assign_slots<RETP+1, ARGP, VARP, EXTRAP, EXTRAC>(stackslots...);
|
||||
}
|
||||
template<int RETP, int ARGP, int VARP, int EXTRAP, int EXTRAC, class... SS>
|
||||
void assign_slots(LuaArg &v, SS & ... stackslots) {
|
||||
v.index_ = ARGP;
|
||||
assign_slots<RETP, ARGP+1, VARP, EXTRAP, EXTRAC>(stackslots...);
|
||||
}
|
||||
template<int RETP, int ARGP, int VARP, int EXTRAP, int EXTRAC, class... SS>
|
||||
void assign_slots(LuaVar &v, SS & ... stackslots) {
|
||||
v.index_ = VARP;
|
||||
assign_slots<RETP, ARGP, VARP+1, EXTRAP, EXTRAC>(stackslots...);
|
||||
}
|
||||
template<int RETP, int ARGP, int VARP, int EXTRAP, int EXTRAC, class... SS>
|
||||
void assign_slots(LuaExtraArgs &v, SS & ... stackslots) {
|
||||
v.index_ = EXTRAP;
|
||||
v.size_ = EXTRAC;
|
||||
assign_slots<RETP, ARGP, VARP, EXTRAP, EXTRAC>(stackslots...);
|
||||
}
|
||||
template<int RETP, int ARGP, int VARP, int EXTRAP, int EXTRAC>
|
||||
void assign_slots() {}
|
||||
|
||||
template<class... SS>
|
||||
void vassign_slots(int retp, int argp, int varp, int extrap, int extrac, LuaRet &v, SS & ... stackslots) {
|
||||
v.index_ = retp;
|
||||
@@ -722,21 +697,24 @@ public:
|
||||
template<class... SS>
|
||||
inline LuaDefStack(lua_State *L, SS & ... stackslots) : LuaCoreStack(L) {
|
||||
constexpr Counts counts = count_slots<0, 0, 0, 0>(stackslots...);
|
||||
if (lua_gettop(L_) < counts.narg) {
|
||||
int nargs = lua_gettop(L);
|
||||
if (counts.nextra == 0) {
|
||||
if (nargs != counts.narg) {
|
||||
luaL_error(L_, "function expects exactly %d arguments", counts.narg);
|
||||
}
|
||||
} else {
|
||||
if (nargs < counts.narg) {
|
||||
luaL_error(L_, "function expects at least %d arguments", counts.narg);
|
||||
}
|
||||
lua_checkstack(L, counts.nvar + counts.nret + 20);
|
||||
int top = lua_gettop(L);
|
||||
for (int i = 0; i < counts.nvar + counts.nret; i ++) {
|
||||
lua_pushnil(L_);
|
||||
}
|
||||
vassign_slots(1 + counts.nvar + top, 1, 1 + top, 1 + counts.narg, top - counts.narg, stackslots...);
|
||||
top_ = top + counts.nvar + counts.nret;
|
||||
lua_checkstack(L, counts.nret + counts.nvar + 20);
|
||||
lua_insert_frame(L, counts.nret + counts.nvar);
|
||||
vassign_slots(1, 1 + counts.nret + counts.nvar, 1 + counts.nret, 1 + counts.nret + counts.nvar + counts.narg, nargs - counts.narg, stackslots...);
|
||||
nret_ = counts.nret;
|
||||
}
|
||||
|
||||
int result() {
|
||||
lua_settop(L_, top_);
|
||||
lua_settop(L_, nret_);
|
||||
return nret_;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user