diff --git a/src/dehacked.c b/src/dehacked.c index fd66bf3ea..e283d80cf 100644 --- a/src/dehacked.c +++ b/src/dehacked.c @@ -653,6 +653,9 @@ static void readfreeslots(MYFILE *f) for (i = 0; i < NUMSTATEFREESLOTS; i++) if (!FREE_STATES[i]) { CONS_Printf("State S_%s allocated.\n",word); + + LUA_InvalidateMathlibStateCache(word); + FREE_STATES[i] = Z_Malloc(strlen(word)+1, PU_STATIC, NULL); strcpy(FREE_STATES[i],word); freeslotusage[0][0]++; @@ -9212,6 +9215,11 @@ static inline int lib_freeslot(lua_State *L) for (i = 0; i < NUMSTATEFREESLOTS; i++) if (!FREE_STATES[i]) { CONS_Printf("State S_%s allocated.\n",word); + + lua_pushcfunction(L, lua_glib_invalidate_cache); + lua_pushfstring(L, "S_%s", word); + lua_call(L, 1, 0); + FREE_STATES[i] = Z_Malloc(strlen(word)+1, PU_STATIC, NULL); strcpy(FREE_STATES[i],word); freeslotusage[0][0]++; diff --git a/src/lua_script.c b/src/lua_script.c index 30df39fbb..51c15062a 100644 --- a/src/lua_script.c +++ b/src/lua_script.c @@ -415,6 +415,16 @@ void LUA_InvalidateMathlibMobjCache(const char *name) lua_call(mL, 1, 0); } +void LUA_InvalidateMathlibStateCache(const char *name) +{ + // No state => no cache => nothing to invalidate :3 + if (mL == NULL) return; + + lua_pushcfunction(mL, lua_glib_invalidate_cache); + lua_pushfstring(mL, "S_%s", name); + lua_call(mL, 1, 0); +} + // Takes a pointer, any pointer, and a metatable name // Creates a userdata for that pointer with the given metatable // Pushes it to the stack and stores it in the registry. diff --git a/src/lua_script.h b/src/lua_script.h index a84415ba6..82768c1d5 100644 --- a/src/lua_script.h +++ b/src/lua_script.h @@ -50,6 +50,7 @@ fixed_t LUA_EvalMath(const char *word); // Need better name for this ;-; void LUA_InvalidateMathlibMobjCache(const char *name); +void LUA_InvalidateMathlibStateCache(const char *name); void LUA_PushUserdata(lua_State *L, void *data, const char *meta); void LUA_InvalidateUserdata(void *data);