View Single Post
10-25-13, 10:15 PM   #7
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Also, do not do this:

Code:
function events:COMBAT_LOG_EVENT_UNFILTERED(self, event, ...)
    local eventType = select(2,...);
    local destGUID = select(7,...);
Calling functions is really, really slow (relatively speaking) and should be avoided whenever possible. In this case, you're doing two calls to select, which is almost always a completely useless function, this being no exception. Instead, assign all the variables (or at least the 1st-nth, where n is the highest number you care about) and just ignore the ones you're not using. A common convention in Lua is to use an underscore as the name of any variable you don't care about:

Code:
function events:COMBAT_LOG_EVENT_UNFILTERED(self, event, ...)
    local _, eventType, _, _, _, _, destGUID = ...
Alternatively, you can just name the arguments in the function definition itself:

Code:
function events:COMBAT_LOG_EVENT_UNFILTERED(self, event, _, eventType, _, _, _, _, destGUID, ...)
^ Here I've left the vararg at the end to contain all the unnamed variables, but if you know your code will never use anything past destGUID you can omit it.

Finally, a common practice for handling CLEU is to name all the variables that are the same for all sub-events, and use the vararg only for the event-specific variables:

Code:
function events:COMBAT_LOG_EVENT_UNFILTERED(self, event, timestamp, eventType, hideCaster, sourceGUID, sourceName, sourceFlags, sourceRaidFlags, destGUID, destName, destFlags, destRaidFlags, ...)
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote