Quantcast

Use standard library function "tostring" instead of nilstring.

Johnny C. Lam [10-12-12 - 00:46]
Use standard library function "tostring" instead of nilstring.

git-svn-id: svn://svn.curseforge.net/wow/ovale/mainline/trunk@589 d5049fe3-3747-40f7-a4b5-f36d6801af5f
Filename
OvaleBestAction.lua
OvaleCondition.lua
OvaleState.lua
diff --git a/OvaleBestAction.lua b/OvaleBestAction.lua
index 4c0a018..a10b785 100644
--- a/OvaleBestAction.lua
+++ b/OvaleBestAction.lua
@@ -9,15 +9,11 @@

 OvaleBestAction = {}

---<private-static-methods>
-local function nilstring(text)
-	if text == nil then
-		return "nil"
-	else
-		return text
-	end
-end
+--<private-static-properties>
+local tostring = tostring
+--</private-static-properties>

+--<private-static-methods>
 local function printTime(temps)
 	if (temps == nil) then
 		Ovale:Print("> nil")
@@ -153,7 +149,7 @@ function OvaleBestAction:GetActionInfo(element)
 		end

 		if (Ovale.trace) then
-			Ovale:Print("Item "..nilstring(itemId))
+			Ovale:Print("Item "..tostring(itemId))
 		end

 		local spellName = GetItemSpell(itemId)
@@ -254,7 +250,7 @@ function OvaleBestAction:Compute(element)
 				else
 					restant = actionCooldownDuration + actionCooldownStart
 				end
-				Ovale:Log("restant = "..restant.." attenteFinCast="..nilstring(OvaleState.attenteFinCast))
+				Ovale:Log("restant = "..restant.." attenteFinCast="..tostring(OvaleState.attenteFinCast))
 				if restant<OvaleState.attenteFinCast then
 					if	not OvaleData.spellInfo[OvaleState.currentSpellId] or
 							not OvaleData.spellInfo[OvaleState.currentSpellId].canStopChannelling then
@@ -308,7 +304,7 @@ function OvaleBestAction:Compute(element)
 				for k,v in pairs(element.params) do
 					parameterList = parameterList..k.."="..v..","
 				end
-				Ovale:Print("Function "..parameterList..") returned "..nilstring(start)..","..nilstring(ending)..","..nilstring(value)..","..nilstring(origin)..","..nilstring(rate))
+				Ovale:Print("Function "..parameterList..") returned "..tostring(start)..","..tostring(ending)..","..tostring(value)..","..tostring(origin)..","..tostring(rate))
 			end

 			if value  then
@@ -335,7 +331,7 @@ function OvaleBestAction:Compute(element)
 		return addTime(startA, timeA), addTime(endA, timeA)
 	elseif (element.type == "before") then
 		if (Ovale.trace) then
-			--Ovale:Print(nilstring(element.time).."s before ["..element.nodeId.."]")
+			--Ovale:Print(tostring(element.time).."s before ["..element.nodeId.."]")
 		end
 		local timeA = self:Compute(element.time)
 		local startA, endA = self:Compute(element.a)
@@ -379,7 +375,7 @@ function OvaleBestAction:Compute(element)
 		Ovale:Log("compare "..element.comparison)
 		local tempsA = self:Compute(element.a)
 		local timeB = self:Compute(element.time)
-		Ovale:Log(nilstring(tempsA).." "..element.comparison.." "..nilstring(timeB))
+		Ovale:Log(tostring(tempsA).." "..element.comparison.." "..tostring(timeB))
 		if element.comparison == "more" and (not tempsA or tempsA>timeB) then
 			if Ovale.trace then Ovale:Print(element.type.." return 0") end
 			return 0
@@ -425,7 +421,7 @@ function OvaleBestAction:Compute(element)
 			endB = endA
 		end
 		if Ovale.trace then
-			Ovale:Print(element.type.." return "..nilstring(startB)..","..nilstring(endB).." ["..element.nodeId.."]")
+			Ovale:Print(element.type.." return "..tostring(startB)..","..tostring(endB).." ["..element.nodeId.."]")
 		end
 		return startB, endB, prioriteB, elementB
 	elseif element.type == "unless" then
@@ -441,7 +437,7 @@ function OvaleBestAction:Compute(element)
 		end

 		if isAfterEqual(startA, startB) and isBefore(endA, endB) then
-			if Ovale.trace then Ovale:Print(element.type.." return "..nilstring(endA)..","..nilstring(endB)) end
+			if Ovale.trace then Ovale:Print(element.type.." return "..tostring(endA)..","..tostring(endB)) end
 			return endA, endB, prioriteB, elementB
 		end

@@ -453,7 +449,7 @@ function OvaleBestAction:Compute(element)
 			startB = endA
 		end

-		if Ovale.trace then Ovale:Print(element.type.." return "..nilstring(startB)..","..nilstring(endB)) end
+		if Ovale.trace then Ovale:Print(element.type.." return "..tostring(startB)..","..tostring(endB)) end
 		return startB, endB, prioriteB, elementB
 	elseif element.type == "not" then
 		local startA, endA = self:ComputeBool(element.a)
@@ -643,7 +639,7 @@ function OvaleBestAction:Compute(element)
 		return startA, endA, 3, result
 	elseif element.type == "lua" then
 		local ret = loadstring(element.lua)()
-		Ovale:Log("lua "..nilstring(ret))
+		Ovale:Log("lua "..tostring(ret))
 		if not element.result then
 			element.result = { type = "value" }
 		end
@@ -727,9 +723,9 @@ function OvaleBestAction:Compute(element)
 					if bestElement.params then
 						id = bestElement.params[1]
 					end
-					Ovale:Print("group best action "..tostring(id).." remains "..meilleurTempsFils..","..nilstring(bestEnd).." ["..element.nodeId.."]")
+					Ovale:Print("group best action "..tostring(id).." remains "..meilleurTempsFils..","..tostring(bestEnd).." ["..element.nodeId.."]")
 				else
-					Ovale:Print("group no best action returns "..meilleurTempsFils..","..nilstring(bestEnd).." ["..element.nodeId.."]")
+					Ovale:Print("group no best action returns "..meilleurTempsFils..","..tostring(bestEnd).." ["..element.nodeId.."]")
 				end
 			end
 			return meilleurTempsFils, bestEnd, meilleurePrioriteFils, bestElement
diff --git a/OvaleCondition.lua b/OvaleCondition.lua
index fece9bb..61f3261 100644
--- a/OvaleCondition.lua
+++ b/OvaleCondition.lua
@@ -42,6 +42,8 @@ local savedHealth = {}
 local targetGUID = {}
 local lastSPD = {}

+local tostring = tostring
+
 --</private-static-properties>

 --<private-static-methods>
@@ -154,14 +156,6 @@ local function addOrSubTime(time1, operator, duration)
 	end
 end

-local function nilstring(text)
-	if text == nil then
-		return "nil"
-	else
-		return text
-	end
-end
-
 -- Get the expiration time of a debuff
 -- that can be on any unit except the target
 -- Returns the first to expires, the last to expires
@@ -335,7 +329,7 @@ local function GetTargetAura(condition, target)
 	end

 	if Ovale.trace then
-		Ovale:Print("GetTargetAura = start=".. nilstring(aura.start) .. " end="..nilstring(aura.ending).." stacks=" ..nilstring(aura.stacks).."/"..stacks)
+		Ovale:Print("GetTargetAura = start=".. tostring(aura.start) .. " end="..tostring(aura.ending).." stacks=" ..tostring(aura.stacks).."/"..stacks)
 	end

 	if (not condition.mine or (aura.mine and condition.mine==1) or (not aura.mine and condition.mine==0)) and aura.stacks>=stacks then
@@ -522,8 +516,8 @@ OvaleCondition.conditions=
 		local start, ending = GetTargetAura(condition, getTarget(condition.target))
 		local timeBefore = avecHate(condition[2], condition.haste)
 		if Ovale.trace then
-			Ovale:Print("timeBefore = " .. nilstring(timeBefore))
-			Ovale:Print("start = " .. nilstring(ending))
+			Ovale:Print("timeBefore = " .. tostring(timeBefore))
+			Ovale:Print("start = " .. tostring(ending))
 		end
 		return addTime(ending, -timeBefore)
 	end,
diff --git a/OvaleState.lua b/OvaleState.lua
index 9a44677..bc97ece 100644
--- a/OvaleState.lua
+++ b/OvaleState.lua
@@ -35,18 +35,9 @@ OvaleState.lastSpellId = nil

 --<private-static-properties>
 local UnitGUID = UnitGUID
+local tostring = tostring
 --</private-static-properties>

---<private-static-methods>
-local function nilstring(text)
-	if text == nil then
-		return "nil"
-	else
-		return text
-	end
-end
---</private-static-methods>
-
 --<public-static-methods>
 function OvaleState:StartNewFrame()
 	self.maintenant = GetTime()
@@ -253,7 +244,7 @@ function OvaleState:AddSpellToStack(spellId, startCast, endCast, nextCast, nocd,
 				local buffAura = self:GetAura("player", newSpellInfo.buffnocd, true)
 				if self.traceAura then
 					if buffAura then
-						Ovale:Print("buffAura stacks = "..buffAura.stacks.." start="..nilstring(buffAura.start).." ending = "..nilstring(buffAura.ending))
+						Ovale:Print("buffAura stacks = "..buffAura.stacks.." start="..tostring(buffAura.start).." ending = "..tostring(buffAura.ending))
 						Ovale:Print("startCast = "..startCast)
 					else
 						Ovale:Print("buffAura = nil")