From 0b704ba6188ee47763ab682c64b0d43138152846 Mon Sep 17 00:00:00 2001 From: Yukita Mayako Date: Thu, 3 Mar 2016 17:07:05 -0500 Subject: [PATCH] Updated NetArchiveHook to lua_hooklib.c Fixes I_Assert failure crash due to hooks working differently now. --- src/lua_hooklib.c | 24 ++++++++++++++++++++++++ src/lua_script.c | 28 +++------------------------- 2 files changed, 27 insertions(+), 25 deletions(-) diff --git a/src/lua_hooklib.c b/src/lua_hooklib.c index 0415d23e..4a3325cf 100644 --- a/src/lua_hooklib.c +++ b/src/lua_hooklib.c @@ -768,4 +768,28 @@ boolean LUAh_HurtMsg(player_t *player, mobj_t *inflictor, mobj_t *source) return hooked; } +void LUAh_NetArchiveHook(lua_CFunction archFunc) +{ + hook_p hookp; + + if (!gL || !(hooksAvailable[hook_NetVars/8] & (1<<(hook_NetVars%8)))) + return; + + // stack: tables + I_Assert(lua_gettop(gL) > 0); + I_Assert(lua_istable(gL, -1)); + + for (hookp = roothook; hookp; hookp = hookp->next) + if (hookp->type == hook_NetVars) + { + lua_pushfstring(gL, FMT_HOOKID, hookp->id); + lua_gettable(gL, LUA_REGISTRYINDEX); + lua_pushvalue(gL, -2); // tables + LUA_Call(gL, 1); + } + + // pop tables + lua_pop(gL, 1); +} + #endif diff --git a/src/lua_script.c b/src/lua_script.c index a7315ad6..2e076b02 100644 --- a/src/lua_script.c +++ b/src/lua_script.c @@ -915,29 +915,7 @@ static void UnArchiveTables(void) } } -static void NetArchiveHook(lua_CFunction archFunc) -{ - int TABLESINDEX; - - if (!gL) - return; - - TABLESINDEX = lua_gettop(gL); - lua_getfield(gL, LUA_REGISTRYINDEX, "hook"); - I_Assert(lua_istable(gL, -1)); - lua_rawgeti(gL, -1, hook_NetVars); - lua_remove(gL, -2); - I_Assert(lua_istable(gL, -1)); - - lua_pushvalue(gL, TABLESINDEX); - lua_pushcclosure(gL, archFunc, 1); - lua_pushnil(gL); - while (lua_next(gL, -3) != 0) { - lua_pushvalue(gL, -3); // function - LUA_Call(gL, 1); - } - lua_pop(gL, 2); -} +void LUAh_NetArchiveHook(lua_CFunction archFunc); void LUA_Step(void) { @@ -972,7 +950,7 @@ void LUA_Archive(void) } WRITEUINT32(save_p, UINT32_MAX); // end of mobjs marker, replaces mobjnum. - NetArchiveHook(NetArchive); // call the NetArchive hook in archive mode + LUAh_NetArchiveHook(NetArchive); // call the NetArchive hook in archive mode ArchiveTables(); if (gL) @@ -1003,7 +981,7 @@ void LUA_UnArchive(void) UnArchiveExtVars(th); // apply variables } while(mobjnum != UINT32_MAX); // repeat until end of mobjs marker. - NetArchiveHook(NetUnArchive); // call the NetArchive hook in unarchive mode + LUAh_NetArchiveHook(NetUnArchive); // call the NetArchive hook in unarchive mode UnArchiveTables(); if (gL)