diff utils.lua @ 16:250d01156e21

Use local references to global functions in the utils functions
author contrebasse
date Wed, 06 Apr 2011 00:32:00 +0200
parents ed0582126cae
children 5f3a5b88fb19
line wrap: on
line diff
--- 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