From b368936b03b3e65e7cb8c5fdf417660806fc05cc Mon Sep 17 00:00:00 2001 From: Yukita Mayako Date: Thu, 3 Mar 2016 17:30:46 -0500 Subject: [PATCH] Fix bad logic in LUAh_NetArchiveHook rewrite... Argh, I knew I was forgetting something! archFunc is the argument to be passed to the hooks, not tables! --- src/lua_hooklib.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/lua_hooklib.c b/src/lua_hooklib.c index 01d4314c8..5230886a8 100644 --- a/src/lua_hooklib.c +++ b/src/lua_hooklib.c @@ -779,15 +779,21 @@ void LUAh_NetArchiveHook(lua_CFunction archFunc) I_Assert(lua_gettop(gL) > 0); I_Assert(lua_istable(gL, -1)); + // tables becomes an upvalue of archFunc + lua_pushvalue(gL, -1); + lua_pushcclosure(gL, archFunc, 1); + // stack: tables, archFunc + 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_pushvalue(gL, -2); // archFunc LUA_Call(gL, 1); } + lua_pop(gL, 1); // pop archFunc // stack: tables }