diff --git a/src/deh_lua.c b/src/deh_lua.c index 43e25a49d18966ff35eb63975e7a132c6ea4686e..62a1717a84e4ae40833d02ed3c649b8ad8fd4c75 100644 --- a/src/deh_lua.c +++ b/src/deh_lua.c @@ -214,7 +214,6 @@ static int action_call(lua_State *L) // Set in lua_infolib. const char *luaactions[MAX_ACTION_RECURSION]; UINT8 luaactionstack = 0; -UINT8 superstack = 0; static int lib_dummysuper(lua_State *L) { diff --git a/src/dehacked.h b/src/dehacked.h index e29aef6ff892d3b20728b1fa8d88da68659fba96..bf4d5c12157b292781c2c0f076d09eb2dcce9957 100644 --- a/src/dehacked.h +++ b/src/dehacked.h @@ -43,7 +43,6 @@ extern boolean introchanged; #define MAX_ACTION_RECURSION 30 extern const char *luaactions[MAX_ACTION_RECURSION]; extern UINT8 luaactionstack; -extern UINT8 superstack; // If the dehacked patch does not match this version, we throw a warning #define PATCHVERSION 220 diff --git a/src/lua_infolib.c b/src/lua_infolib.c index e20202495a6ac536b0ac5c6e2325bed9f55497f8..ad7bc7b6f83c80c36e4b505e98f93373f49ebbed 100644 --- a/src/lua_infolib.c +++ b/src/lua_infolib.c @@ -812,6 +812,7 @@ boolean LUA_SetLuaAction(void *stv, const char *action) return true; // action successfully set. } +static UINT8 superstack[NUMACTIONS]; boolean LUA_CallAction(enum actionnum actionnum, mobj_t *actor) { I_Assert(actor != NULL); @@ -819,7 +820,7 @@ boolean LUA_CallAction(enum actionnum actionnum, mobj_t *actor) if (actionsoverridden[actionnum][0] == LUA_REFNIL) { // The action was not overridden at all, - // so call the hardcoded version. + // so just call the hardcoded version. return false; } @@ -830,24 +831,27 @@ boolean LUA_CallAction(enum actionnum actionnum, mobj_t *actor) // 0 is just the reference to the one we're calling, // so we increment here. - superstack++; + superstack[actionnum]++; - if (superstack >= MAX_ACTION_RECURSION) + if (superstack[actionnum] >= MAX_ACTION_RECURSION) { CONS_Alert(CONS_WARNING, "Max Lua super recursion reached! Cool it on calling super!\n"); + superstack[actionnum] = 0; return false; } } - else - { - // Not calling itself, reset the super counter. - superstack = 0; - } - if (actionsoverridden[actionnum][superstack] == LUA_REFNIL) + if (actionsoverridden[actionnum][superstack[actionnum]] == LUA_REFNIL) { // No Lua reference beyond this point. // Let it call the hardcoded function instead. + + if (superstack[actionnum]) + { + // Decrement super stack + superstack[actionnum]--; + } + return false; } @@ -855,7 +859,7 @@ boolean LUA_CallAction(enum actionnum actionnum, mobj_t *actor) lua_pushcfunction(gL, LUA_GetErrorMessage); // Push function by reference. - lua_getref(gL, actionsoverridden[actionnum][superstack]); + lua_getref(gL, actionsoverridden[actionnum][superstack[actionnum]]); if (lua_isnil(gL, -1)) // no match { @@ -883,6 +887,12 @@ boolean LUA_CallAction(enum actionnum actionnum, mobj_t *actor) LUA_Call(gL, 3, 0, -(2 + 3)); lua_pop(gL, -1); // Error handler + if (superstack[actionnum]) + { + // Decrement super stack + superstack[actionnum]--; + } + --luaactionstack; luaactions[luaactionstack] = NULL; return true; // action successfully called.