# HG changeset patch # User contrebasse # Date 1302042720 -7200 # Node ID 250d01156e219b75ff33c7802316b6e1302f9066 # Parent cc56799582f23b4daa08ee987f4c204bcf59af6e Use local references to global functions in the utils functions diff -r cc56799582f2 -r 250d01156e21 utils.lua --- a/utils.lua Wed Apr 06 00:28:13 2011 +0200 +++ b/utils.lua Wed Apr 06 00:32:00 2011 +0200 @@ -1,13 +1,21 @@ local addonName, A = ... +-- Lua functions +local tonumber = tonumber +local select = select +local sfind = string.find + +-- Wow functions + -- DEBUG Print function A.DEBUG(msg) + -- GLOBALS: DEFAULT_CHAT_FRAME DEFAULT_CHAT_FRAME:AddMessage(msg or "nil",1,0,0) end -- function -- Returns the item ID from its link function A.link2ID(link) - return tonumber(select(3,string.find(link or "", "-*:(%d+)[:|].*")) or "") + return tonumber(select(3,sfind(link or "", "-*:(%d+)[:|].*")) or "") end -- function -- Returns the button number for the reagents buttons @@ -16,30 +24,37 @@ return tonumber(btn:GetName():sub(-1)) end --- Gives the number of craftable objects -function A.numMakable(reagentID) - -- Look for the recipe to make the item - local reagentIndex = A.findSkillIndex(reagentID) - if not reagentIndex then return 0 end +do + -- Wow functions + local GetTradeSkillInfo = GetTradeSkillInfo + local GetNumTradeSkills = GetNumTradeSkills + local GetTradeSkillItemLink = GetTradeSkillItemLink - -- Check how many items we can craft - local skillName, skillType, numReagentMakable, isExpanded, serviceType, numSkillUps = GetTradeSkillInfo(reagentIndex) - return numReagentMakable or 0, reagentIndex -end + -- Gives the number of craftable objects + function A.numMakable(reagentID) + -- Look for the recipe to make the item + local reagentIndex = A.findSkillIndex(reagentID) + if not reagentIndex then return 0 end --- Find the first tradeskill index of the recipe to make an item -function A.findSkillIndex(itemID) - for i = 1,GetNumTradeSkills() do - local skillName, skillType, numAvailable, isExpanded, serviceType, numSkillUps = GetTradeSkillInfo(i) - if skillType == "header" then - else - if skillName then - local ID = A.link2ID(GetTradeSkillItemLink(i)) - if ID and ID == itemID then - return i + -- Check how many items we can craft + local skillName, skillType, numReagentMakable, isExpanded, serviceType, numSkillUps = GetTradeSkillInfo(reagentIndex) + return numReagentMakable or 0, reagentIndex + end + + -- Find the first tradeskill index of the recipe to make an item + function A.findSkillIndex(itemID) + for i = 1,GetNumTradeSkills() do + local skillName, skillType, numAvailable, isExpanded, serviceType, numSkillUps = GetTradeSkillInfo(i) + if skillType == "header" then + else + if skillName then + local ID = A.link2ID(GetTradeSkillItemLink(i)) + if ID and ID == itemID then + return i + end -- if end -- if end -- if - end -- if - end -- for - A.DEBUG("Tradeskill not found for "..itemID) -end -- function + end -- for + A.DEBUG("Tradeskill not found for "..itemID) + end -- function +end -- do