Start refactoring LuaStack
This commit is contained in:
@@ -181,6 +181,7 @@ public:
|
||||
|
||||
friend class LuaCoreStack;
|
||||
friend class LuaOldStack;
|
||||
friend class LuaDefStack;
|
||||
friend class LuaExtStack;
|
||||
};
|
||||
|
||||
@@ -275,6 +276,8 @@ class LuaCoreStack : public eng::nevernew {
|
||||
protected:
|
||||
lua_State *L_;
|
||||
|
||||
LuaCoreStack(lua_State *L) : L_(L) {}
|
||||
|
||||
private:
|
||||
// Push any value on the stack, by type.
|
||||
void push_any_value(LuaNewTableMarker s) const { lua_newtable(L_); }
|
||||
@@ -549,8 +552,7 @@ private:
|
||||
|
||||
public:
|
||||
template<class... SS>
|
||||
LuaOldStack(lua_State *L, SS & ... stackslots) {
|
||||
L_ = L;
|
||||
LuaOldStack(lua_State *L, SS & ... stackslots) : LuaCoreStack(L) {
|
||||
count_slots<0, 0, 0>(stackslots...);
|
||||
if (lua_gettop(L) < narg_) {
|
||||
luaL_error(L, "not enough arguments to function");
|
||||
@@ -624,8 +626,7 @@ private:
|
||||
|
||||
public:
|
||||
template<class... SS>
|
||||
LuaDefStack(lua_State *L, SS & ... stackslots) {
|
||||
L_ = L;
|
||||
LuaDefStack(lua_State *L, SS & ... stackslots) : LuaCoreStack(L) {
|
||||
count_slots<0, 0, 0>(stackslots...);
|
||||
if (lua_gettop(L_) != narg_) {
|
||||
luaL_error(L_, "function expects exactly %d arguments", narg_);
|
||||
@@ -642,11 +643,12 @@ public:
|
||||
assign_slots(1, 1 + nret_, 1 + nret_ + narg_, stackslots...);
|
||||
}
|
||||
|
||||
~LuaDefStack() {
|
||||
if (!lua_isthrowing(L_)) {
|
||||
lua_settop(L_, nret_);
|
||||
};
|
||||
int result() {
|
||||
lua_settop(L_, nret_);
|
||||
return nret_;
|
||||
}
|
||||
|
||||
~LuaDefStack() { }
|
||||
};
|
||||
|
||||
class LuaExtStack : public LuaCoreStack {
|
||||
@@ -673,8 +675,7 @@ private:
|
||||
|
||||
public:
|
||||
template<class... SS>
|
||||
LuaExtStack(lua_State *L, SS & ... stackslots) {
|
||||
L_ = L;
|
||||
LuaExtStack(lua_State *L, SS & ... stackslots) : LuaCoreStack(L) {
|
||||
count_slots<0>(stackslots...);
|
||||
lua_checkstack(L_, nvar_ + 20);
|
||||
oldtop_ = lua_gettop(L_);
|
||||
@@ -685,8 +686,7 @@ public:
|
||||
}
|
||||
|
||||
template<class... SS>
|
||||
LuaExtStack(const LuaCoreStack &LS0, SS & ... stackslots) {
|
||||
L_ = LS0.state();
|
||||
LuaExtStack(const LuaCoreStack &LS0, SS & ... stackslots) : LuaCoreStack(LS0.state()) {
|
||||
count_slots<0>(stackslots...);
|
||||
lua_checkstack(L_, nvar_ + 20);
|
||||
oldtop_ = lua_gettop(L_);
|
||||
|
||||
Reference in New Issue
Block a user