View Single Post
01-12-15, 12:23 AM   #3
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Well, after looking at that auras.lua file I'm not even a little surprised you're getting "script ran too long" errors. Whoever wrote it clearly had no idea how functions in Lua work. Every time anyone's auras change (which can be dozens or even hundreds of times per second per unit in combat!) it's calling the "UpdateUnitAuras" method, which creates seven functions every time it runs, not to mention the many, many tables it's creating every time. I didn't even look at the rest of the addon, but it's probably doing the same thing everywhere. All these functions should only be created once and then called when needed -- not created over and over again. Outside of a few specific situations (which are generally advanced topics that most addons will never encounter) you should never create a function inside another function.

If you want to fix it, you've got a lot of boring work on your hands -- you'll need to move all functions outside of other functions, and then modify them to accept (and be passed) the additional variables they're currently acting on. For example, the first function-in-function:

Code:
function Auras:UpdateUnitAuras(event, unit)
	if not self.buffFrame[unit] and not self.debuffFrame[unit] then return end

	--[[ bunch of local variables defined here ]]

	local function set_aura(index, buff)
After you move "set_aura" outside of the "UpdateUnitAuras" method, you'd also need to make it receive the other variables it works on:

Code:
local function set_aura(index, buff, auraFrame, icon_index, aurasBuffsMax)
... then pass those variables when you call the function later (currently line 375):

Code:
if set_aura(aura_index, buffs, auraFrame, icon_index, aurasBuffsMax) then return end
Also, since the value of "icon_index" is modified inside the function, you'd need to make more changes so that the new value was passed back at the end of the "set_aura" function:

Code:
return icon_index > aurasBuffsMax, icon_index
... and receive that value on line 375, assigning it to the original "icon_index" variable:

Code:
local stop_here
stop_here, icon_index = set_aura(aura_index, buffs, auraFrame, icon_index, aurasBuffsMax)
if stop_here then return end
In this particular case though, it would be more efficient to just rewrite the "set_aura" function so it doesn't need any of those additional variables:

Code:
local function set_aura(aura_frame, index, buff)
	-- local aura_frame = auraFrame[icon_index] -- REMOVE THIS LINE

	--[[ code here is fine ]]

	-- show
	aura_frame:Show()
	-- icon_index = icon_index + 1 -- REMOVE THIS LINE
	-- return icon_index > aurasBuffsMax -- REMOVE THIS LINE
end
Then change the part where it's called to this:
Code:
			set_aura(aura_frame, aura_index, buffs)
			icon_index = icon_index + 1
			if icon_index > aurasBuffsMax then return end
Frankly I'd say it would be a lot easier just to use some other addon that's actually being maintained and was written by someone who knows what they're doing (at least enough to avoid such glaring errors as re-creating functions billions of times inside a UNIT_AURA handler) or even to write your own from scratch as an oUF layout -- at least oUF handles all this basic stuff like placing aura icons for you!
__________________
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.

Last edited by Phanx : 01-12-15 at 12:27 AM.
  Reply With Quote