From a0d8d6d723933ec135e89ebd1fc250abbda29b04 Mon Sep 17 00:00:00 2001 From: Brues <5278969+brues-code@users.noreply.github.com> Date: Mon, 3 Aug 2026 14:21:03 -0500 Subject: [PATCH] fix(events): forward leading-nil event payloads to callbacks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit EventRegistry callbacks (RegisterOnceFrameEventAndCallback, etc.) dropped any payload whose first arg was nil — e.g. this client's reload PLAYER_ENTERING_WORLD (arg1=nil, arg2=1) delivered nil to every callback parameter. Root cause is a WoW Lua 5.0 quirk: unpacking a table whose hole lands right after a present element into a `func(first, ...)` collapses the receiving vararg count to 0, so the payload after `owner` was silently lost. Fix both build-then-unpack sites in CallbackRegistry to pass the leading arg explicitly and the payload as the unpacked tail: - TriggerEvent Function branch: func(owner, unpack(arg, 1, arg.n)) - GenerateClosure: func(bound[1], unpack(rest, 1, restN)) Verified in-game: RegisterOnceFrameEventAndCallback("PLAYER_ENTERING_WORLD", cb) now delivers arg2=1 to the callback's 2nd parameter on reload. --- .../!!!ClassicAPI/Util/CallbackRegistry.lua | 28 +++++++++++++------ 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/AddOns/!!!ClassicAPI/Util/CallbackRegistry.lua b/AddOns/!!!ClassicAPI/Util/CallbackRegistry.lua index dd9d9c47..d7e93499 100644 --- a/AddOns/!!!ClassicAPI/Util/CallbackRegistry.lua +++ b/AddOns/!!!ClassicAPI/Util/CallbackRegistry.lua @@ -26,10 +26,17 @@ local function GenerateClosure(func, ...) for i = 1, boundN do bound[i] = arg[i] end return function(...) local callN = arg.n - local merged = {} - for i = 1, boundN do merged[i] = bound[i] end - for i = 1, callN do merged[boundN + i] = arg[i] end - return func(unpack(merged, 1, boundN + callN)) + -- Pass the first bound arg (the owner, always bound[1] here) explicitly + -- and everything else as the unpacked tail. Merging bound + call into + -- one table and unpacking THAT collapses the vararg count on this Lua + -- 5.0 build when a hole lands right after a present element — same trap + -- fixed in TriggerEvent's Function branch. Keeping owner out of the + -- unpacked table keeps a leading-nil payload inside the vararg tail. + local rest = {} + local restN = 0 + for i = 2, boundN do restN = restN + 1; rest[restN] = bound[i] end + for i = 1, callN do restN = restN + 1; rest[restN] = arg[i] end + return func(bound[1], unpack(rest, 1, restN)) end end @@ -145,11 +152,14 @@ function CallbackRegistryMixin:TriggerEvent(event, ...) if funcs then for owner, func in pairs(funcs) do -- Stock 3.3.5 passes the owner as the first arg so callers can - -- distinguish multiple registrations of the same function. - local n = arg.n - local merged = { owner } - for i = 1, n do merged[i + 1] = arg[i] end - func(unpack(merged, 1, n + 1)) + -- distinguish multiple registrations of the same function. Pass it + -- explicitly with the payload as the unpacked tail. Do NOT build a + -- { owner, ... } table and unpack THAT: on this Lua 5.0 build, + -- unpacking a table whose hole lands right after a present element + -- (owner) into a `func(first, ...)` collapses the vararg count to 0, + -- silently dropping a leading-nil event payload (verified in-game + -- with reload's PLAYER_ENTERING_WORLD, arg1=nil arg2=1). + func(owner, unpack(arg, 1, arg.n)) end end end