I just wrote myself a function that triggers a callback on any given event. On top of that you have access to two sets of arguments. One which you define on init. One which is passed along on event.
Benefit is that you only need one event frame for any future event callback.
Lua Code:
--rLib:RegisterCallback
function rLib:RegisterCallback(event, callback, ...)
if not self.eventFrame then
self.eventFrame = CreateFrame("Frame")
function self.eventFrame:OnEvent(event, ...)
for callback, args in next, self.callbacks[event] do
callback(args, ...)
end
end
self.eventFrame:SetScript("OnEvent", self.eventFrame.OnEvent)
end
if not self.eventFrame.callbacks then self.eventFrame.callbacks = {} end
if not self.eventFrame.callbacks[event] then self.eventFrame.callbacks[event] = {} end
self.eventFrame.callbacks[event][callback] = {...}
self.eventFrame:RegisterEvent(event)
end
--init
local function OnLogin(...)
print(...)
end
rLib:RegisterCallback("PLAYER_LOGIN",OnLogin,"hello1","hello2")
Arguments you pass along on init are the first argument in the triggered callback packed as a table.
Any thoughts?