View Single Post
08-31-16, 11:38 PM   #2
zork
A Pyroguard Emberseer
 
zork's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 1,740
I use a similar approach in rLib
https://github.com/zorker/rothui/blo...b/core.lua#L39

Lua Code:
  1. --rLib:RegisterCallback
  2. function rLib:RegisterCallback(event, callback, ...)
  3.   if not self.eventFrame then
  4.     self.eventFrame = CreateFrame("Frame")
  5.     function self.eventFrame:OnEvent(event, ...)
  6.       for callback, args in next, self.callbacks[event] do
  7.         callback(args, ...)
  8.       end
  9.     end
  10.     self.eventFrame:SetScript("OnEvent", self.eventFrame.OnEvent)
  11.   end
  12.   if not self.eventFrame.callbacks then self.eventFrame.callbacks = {} end
  13.   if not self.eventFrame.callbacks[event] then self.eventFrame.callbacks[event] = {} end
  14.   self.eventFrame.callbacks[event][callback] = {...}
  15.   self.eventFrame:RegisterEvent(event)
  16. end
__________________
| Simple is beautiful.
| WoWI AddOns | GitHub | Zork (WoW)

"I wonder what the non-pathetic people are doing tonight?" - Rajesh Koothrappali (The Big Bang Theory)
  Reply With Quote