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