Thread: best practice
View Single Post
04-10-16, 02:51 AM   #1
gmarco
An Onyxian Warder
 
gmarco's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2009
Posts: 362
best practice

Hi all,

because this is a period quite calm in game for me now I'd like to take some time to fix, rewrite, or coding better some of my addons

I'd like to ask if this is written well (even if it works

Lua Code:
  1. local ADDON = ...
  2.  
  3. -- bla bla bla ..
  4.  
  5. local frame = CreateFrame("FRAME")
  6. frame:RegisterEvent("ZONE_CHANGED_NEW_AREA")
  7. frame:RegisterEvent("PLAYER_ENTERING_WORLD")
  8. frame:RegisterEvent("UPDATE_MOUSEOVER_UNIT")
  9. frame:RegisterEvent("ADDON_LOADED")
  10.  
  11. frame:SetScript("OnEvent", function(self, event, ...)
  12.  
  13.     if event == "ADDON_LOADED" and ... == ADDON then
  14.  
  15.         -- bla bla bla
  16.  
  17.         elseif event=="COMBAT_LOG_EVENT_UNFILTERED" then
  18.    
  19.         timeStamp, event, _, sourceGUID, sourceName, _, _, destGUID, destName, _, _, prefixParam1, prefixParam2, _, suffixParam1, suffixParam2 = ...
  20.  
  21.          -- bla bla bla
  22.  
  23.          end

what I like to understand if the construct "...==ADDON" is fine ... or I should to get the addon name parsing the ... but it could be expensive.


Or I should create a dedicated frame only for the ADDON_LOADED event and then parse in this way ...

Lua Code:
  1. frame:SetScript("OnEvent", function(self, event, addon)
  2.  
  3.     if event == "ADDON_LOADED" and addon == ADDON then


Thanks .
__________________
This is Unix-Land. In quiet nights, you can hear the Windows machines reboot.

Last edited by gmarco : 04-10-16 at 02:55 AM.
  Reply With Quote