View Single Post
09-24-13, 10:46 PM   #22
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by asett View Post
Lua Code:
  1. if tContains({...}, "MyMovingBarTemplate") then
On a side note, creating a bunch of single-use tables and using tContains -- which, by the way, is not a real Lua or WoW API function, but is just a wrapper around a loop written in Blizzard's Lua code for the default UI -- is pretty inefficient and will generate a lot of garbage, especially if you're making a lot of frames.

You should either create just one table from the arguments, at the beginning of the function, and refer to it for each check:

Code:
local templateList = { ... }
for i = 1, #templateList do
   -- this enables us to do tbl["k"] instead of having
   -- to loop over the table every time we want to see
   -- if it contains something
   templateList[templateList[i]] = true
end

if templateList["MyMovingBarTemplate"] then
   -- add moving stuff
end
Also, if you end up adding more templates, you could split them out into their own functions to avoid having your BuildFrame function be 500 lines of if blocks:

Code:
-- outside of BuildFrame:
local templates = {
    MyMovingBarTemplate = function(frame)
        -- add moving stuff to frame
        return frame
    end
}

-- inside of BuildFrame, after creating the frame:
local templateList = { ... }
for i = 1, #templateList do
    frame = templates[templateList[i]](frame)
end
__________________
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