From 6a6ae2e320c2c03e6cca4782c230f0382e82c6b0 Mon Sep 17 00:00:00 2001 From: "Johnny C. Lam" Date: Fri, 29 Mar 2013 06:50:05 +0000 Subject: [PATCH] Use helper function to deal with nil arguments to formatted strings. This fixes using the trace functionality to explore the decisions that Ovale is making. git-svn-id: svn://svn.curseforge.net/wow/ovale/mainline/trunk@858 d5049fe3-3747-40f7-a4b5-f36d6801af5f --- Ovale.lua | 30 +++++++++++++++++++++++++++--- OvaleAura.lua | 2 +- OvaleBestAction.lua | 4 ++-- OvaleComboPoints.lua | 2 +- OvaleCompile.lua | 18 +++++++++--------- OvaleEnemies.lua | 2 +- OvaleEquipement.lua | 8 ++++---- OvaleFuture.lua | 32 ++++++++++++++++---------------- OvaleGUID.lua | 2 +- OvaleIcone.lua | 2 +- OvalePaperDoll.lua | 32 ++++++++++++++++---------------- OvalePool.lua | 2 +- OvaleStance.lua | 2 +- 13 files changed, 81 insertions(+), 57 deletions(-) diff --git a/Ovale.lua b/Ovale.lua index 2c71364..6d6f50c 100644 --- a/Ovale.lua +++ b/Ovale.lua @@ -17,6 +17,8 @@ local OvaleOptions = nil local format = string.format local pairs = pairs +local select = select +local tostring = tostring local wipe = table.wipe local API_GetTime = GetTime local API_RegisterAddonMessagePrefix = RegisterAddonMessagePrefix @@ -27,6 +29,10 @@ local API_UnitHasVehicleUI = UnitHasVehicleUI local API_UnitIsDead = UnitIsDead local self_damageMeterMethods = {} + +local OVALE_FALSE_STRING = tostring(false) +local OVALE_NIL_STRING = tostring(nil) +local OVALE_TRUE_STRING = tostring(true) -- -- @@ -66,6 +72,20 @@ BINDING_NAME_OVALE_CHECKBOX3 = L["Inverser la boîte à cocher "].."(4)" BINDING_NAME_OVALE_CHECKBOX4 = L["Inverser la boîte à cocher "].."(5)" -- +-- format() wrapper that turns nil arguments into tostring(nil) +local function Format(...) + local arg = {} + for i = 1, select("#", ...) do + local v = select(i, ...) + if type(v) == "boolean" then + arg[i] = v and OVALE_TRUE_STRING or OVALE_FALSE_STRING + else + arg[i] = v or OVALE_NIL_STRING + end + end + return format(unpack(arg)) +end + local function OnCheckBoxValueChanged(widget) OvaleOptions:GetProfile().check[widget.userdata.k] = widget:GetValue() if Ovale.casesACocher[widget.userdata.k].compile then @@ -293,6 +313,10 @@ function Ovale:SendScoreToDamageMeter(name, guid, scored, scoreMax) end -- Debugging methods. +function Ovale:FormatPrint(...) + self:Print(Format(...)) +end + function Ovale:DebugPrint(flag, ...) local profile = OvaleOptions:GetProfile() if profile and profile.debug and profile.debug[flag] then @@ -303,7 +327,7 @@ end function Ovale:DebugPrintf(flag, ...) local profile = OvaleOptions:GetProfile() if profile and profile.debug and profile.debug[flag] then - self:Printf("[%s] %s", flag, format(...)) + self:Printf("[%s] %s", flag, Format(...)) end end @@ -313,7 +337,7 @@ function Ovale:Error(...) end function Ovale:Errorf(...) - self:Printf("Fatal error: %s", format(...)) + self:Printf("Fatal error: %s", Format(...)) self.bug = true end @@ -325,7 +349,7 @@ end function Ovale:Logf(...) if self.trace then - return self:Printf(...) + return self:Printf(Format(...)) end end -- diff --git a/OvaleAura.lua b/OvaleAura.lua index a34d1a2..037a1e7 100644 --- a/OvaleAura.lua +++ b/OvaleAura.lua @@ -439,7 +439,7 @@ function OvaleAura:Debug() for filter, auraList in pairs(auraTable) do for spellId, whoseTable in pairs(auraList) do for whose, aura in pairs(whoseTable) do - Ovale:Printf("%s %s %s %s %s stacks=%d tick=%s", guid, filter, whose, spellId, aura.name, aura.stacks, aura.tick) + Ovale:FormatPrint("%s %s %s %s %s stacks=%d tick=%s", guid, filter, whose, spellId, aura.name, aura.stacks, aura.tick) end end end diff --git a/OvaleBestAction.lua b/OvaleBestAction.lua index 4d4bf08..98bb9f1 100644 --- a/OvaleBestAction.lua +++ b/OvaleBestAction.lua @@ -295,10 +295,10 @@ local function ComputeFunction(element) if Ovale.trace then local conditionCall = element.func .. "(" for k, v in pairs(element.params) do - conditionCall = parameterList .. k .. "=" .. v .. "," + conditionCall = conditionCall .. k .. "=" .. v .. "," end conditionCall = conditionCall .. ")" - Ovale:Printf("Condition %s returned %s, %s, %s, %s, %s", conditionCall, start, ending, value, origin, rate) + Ovale:FormatPrint("Condition %s returned %s, %s, %s, %s, %s", conditionCall, start, ending, value, origin, rate) end if value then diff --git a/OvaleComboPoints.lua b/OvaleComboPoints.lua index 349f3b7..a556729 100644 --- a/OvaleComboPoints.lua +++ b/OvaleComboPoints.lua @@ -81,6 +81,6 @@ function OvaleComboPoints:Refresh() end function OvaleComboPoints:Debug() - Ovale:Printf("Player has %d combo points on target %s.", self.combo, OvaleGUID:GetGUID("target")) + Ovale:FormatPrint("Player has %d combo points on target %s.", self.combo, OvaleGUID:GetGUID("target")) end -- diff --git a/OvaleCompile.lua b/OvaleCompile.lua index 7d31024..5d74a86 100644 --- a/OvaleCompile.lua +++ b/OvaleCompile.lua @@ -99,7 +99,7 @@ local function HasTalent(talentId) if OvaleData.pointsTalent[talentId]~=nil then return OvaleData.pointsTalent[talentId]>0 else - Ovale:Printf("Unknown talent %s", talentId) + Ovale:FormatPrint("Unknown talent %s", talentId) return false end else @@ -329,10 +329,10 @@ local function ParseScoreSpells(params) for v in strgmatch(params, "(%d+)") do local spellId = tonumber(v) if spellId then - --Ovale:Printf("Add spell to score %d", spellId) + --Ovale:FormatPrint("Add spell to score %d", spellId) OvaleData.scoreSpell[spellId] = true else - Ovale:Printf("ScoreSpell with unknown spell %s", v) + Ovale:FormatPrint("ScoreSpell with unknown spell %s", v) end end end @@ -461,7 +461,7 @@ local function ParseGroup(text) text = strgsub(text, "node%d+", "") if (strmatch(text,"[^ ]")) then - Ovale:Printf("syntax error: %s", text) + Ovale:FormatPrint("syntax error: %s", text) return nil end @@ -586,8 +586,8 @@ local function ParseCommands(text) -- Si il reste autre chose que des espaces, c'est une erreur de syntaxe text = strgsub(text, "node%d+", "", 1) if strmatch(text,"[^ ]") then - Ovale:Printf("Group: %s", original) - Ovale:Printf("syntax error: %s", text) + Ovale:FormatPrint("Group: %s", original) + Ovale:FormatPrint("syntax error: %s", text) return nil end return masterNode @@ -611,7 +611,7 @@ local function ParseCanStopChannelling(text) if spellId then OvaleData:GetSpellInfo(spellId).canStopChannelling = true else - Ovale:Printf("CanStopChannelling with unknown spell %s", text) + Ovale:FormatPrint("CanStopChannelling with unknown spell %s", text) end return "" end @@ -622,7 +622,7 @@ local function ParseItemName(text) local item = API_GetItemInfo(spellId) or "Item " .. itemId return '"' .. item .. '"' else - Ovale:Printf("ItemName of %s unknown\n", text) + Ovale:FormatPrint("ItemName of %s unknown\n", text) return nil end end @@ -633,7 +633,7 @@ local function ParseSpellName(text) if spell then return '"' .. spell .. '"' else - Ovale:Printf("SpellName of %s unknown", text) + Ovale:FormatPrint("SpellName of %s unknown", text) return nil end end diff --git a/OvaleEnemies.lua b/OvaleEnemies.lua index 37f8ae0..a364295 100644 --- a/OvaleEnemies.lua +++ b/OvaleEnemies.lua @@ -126,7 +126,7 @@ end function OvaleEnemies:Debug() for guid, timestamp in pairs(self_enemyLastSeen) do - Ovale:Printf("enemy %s (%s) last seen at %f", guid, self_enemyName[guid], timestamp) + Ovale:FormatPrint("enemy %s (%s) last seen at %f", guid, self_enemyName[guid], timestamp) end end -- diff --git a/OvaleEquipement.lua b/OvaleEquipement.lua index 18fba02..54e5262 100644 --- a/OvaleEquipement.lua +++ b/OvaleEquipement.lua @@ -1065,12 +1065,12 @@ end function OvaleEquipement:Debug() for slotId = INVSLOT_FIRST_EQUIPPED, INVSLOT_LAST_EQUIPPED do - Ovale:Printf("Slot %d = %s", slotId, self:GetEquippedItem(slotId)) + Ovale:FormatPrint("Slot %d = %s", slotId, self:GetEquippedItem(slotId)) end - Ovale:Printf("Main-hand item type: %s", self_mainHandItemType) - Ovale:Printf("Off-hand item type: %s", self_offHandItemType) + Ovale:FormatPrint("Main-hand item type: %s", self_mainHandItemType) + Ovale:FormatPrint("Off-hand item type: %s", self_offHandItemType) for k, v in pairs(self_armorSetCount) do - Ovale:Printf("Player has %d piece(s) of %s armor set.", v, k) + Ovale:FormatPrint("Player has %d piece(s) of %s armor set.", v, k) end end -- diff --git a/OvaleFuture.lua b/OvaleFuture.lua index 9021ae3..5b93a02 100644 --- a/OvaleFuture.lua +++ b/OvaleFuture.lua @@ -85,14 +85,14 @@ local function AddSpellToQueue(spellId, lineId, startTime, endTime, channeled, a spellcast.allowRemove = allowRemove --TODO unable to know what is the real target if lineId == self_lastLineID and self_lastTarget then - -- Ovale:Printf("found lineId %d, target is %s", lineId, self_lastTarget) + -- Ovale:FormatPrint("found lineId %d, target is %s", lineId, self_lastTarget) spellcast.target = self_lastTarget else spellcast.target = API_UnitGUID("target") end if self.traceSpellId and self.traceSpellId == spellId then - Ovale:Printf(" AddSpellToQueue: %f %s (%d), lineId = %d", Ovale.now, OvaleData:GetSpellName(spellId), spellId, lineId) - Ovale:Printf(" startTime = %f, endTime = %f, target = %s", startTime, endTime, spellcast.target) + Ovale:FormatPrint(" AddSpellToQueue: %f %s (%d), lineId = %d", Ovale.now, OvaleData:GetSpellName(spellId), spellId, lineId) + Ovale:FormatPrint(" startTime = %f, endTime = %f, target = %s", startTime, endTime, spellcast.target) end -- Snapshot the current stats for the spellcast. @@ -155,7 +155,7 @@ local function RemoveSpellFromQueue(spellId, lineId) for index, spellcast in ipairs(self_activeSpellcast) do if spellcast.lineId == lineId then if self.traceSpellId and self.traceSpellId == spellId then - Ovale:Printf(" RemoveSpellFromQueue: %f %s (%d)", Ovale.now, OvaleData:GetSpellName(spellId), spellId) + Ovale:FormatPrint(" RemoveSpellFromQueue: %f %s (%d)", Ovale.now, OvaleData:GetSpellName(spellId), spellId) end tremove(self_activeSpellcast, index) self_pool:Release(spellcast) @@ -192,8 +192,8 @@ function OvaleFuture:UNIT_SPELLCAST_CHANNEL_START(event, unit, name, rank, lineI if unit == "player" then local startTime, endTime = select(5, API_UnitChannelInfo("player")) if self.traceSpellId and self.traceSpellId == spellId then - Ovale:Printf("%s: %f %s (%d), lineId = %d", event, Ovale.now, spellName, spellId, lineId) - Ovale:Printf(" startTime = %f, endTime = %f", startTime, endTime) + Ovale:FormatPrint("%s: %f %s (%d), lineId = %d", event, Ovale.now, spellName, spellId, lineId) + Ovale:FormatPrint(" startTime = %f, endTime = %f", startTime, endTime) end AddSpellToQueue(spellId, lineId, startTime/1000, endTime/1000, true, false) end @@ -202,7 +202,7 @@ end function OvaleFuture:UNIT_SPELLCAST_CHANNEL_STOP(event, unit, name, rank, lineId, spellId) if unit == "player" then if self.traceSpellId and self.traceSpellId == spellId then - Ovale:Printf("%s: %f %s (%d), lineId = %d", event, Ovale.now, spellName, spellId, lineId) + Ovale:FormatPrint("%s: %f %s (%d), lineId = %d", event, Ovale.now, spellName, spellId, lineId) end RemoveSpellFromQueue(spellId, lineId) end @@ -213,8 +213,8 @@ function OvaleFuture:UNIT_SPELLCAST_START(event, unit, name, rank, lineId, spell if unit == "player" then local startTime, endTime = select(5, API_UnitCastingInfo("player")) if self.traceSpellId and self.traceSpellId == spellId then - Ovale:Printf("%s: %f %s (%d), lineId = %d", event, Ovale.now, spellName, spellId, lineId) - Ovale:Printf(" startTime = %f, endTime = %f", startTime, endTime) + Ovale:FormatPrint("%s: %f %s (%d), lineId = %d", event, Ovale.now, spellName, spellId, lineId) + Ovale:FormatPrint(" startTime = %f, endTime = %f", startTime, endTime) end AddSpellToQueue(spellId, lineId, startTime/1000, endTime/1000, false, false) end @@ -224,7 +224,7 @@ end function OvaleFuture:UNIT_SPELLCAST_INTERRUPTED(event, unit, name, rank, lineId, spellId) if unit == "player" then if self.traceSpellId and self.traceSpellId == spellId then - Ovale:Printf("%s: %f %s (%d), lineId = %d", event, Ovale.now, spellName, spellId, lineId) + Ovale:FormatPrint("%s: %f %s (%d), lineId = %d", event, Ovale.now, spellName, spellId, lineId) end RemoveSpellFromQueue(spellId, lineId) end @@ -245,8 +245,8 @@ function OvaleFuture:UNIT_SPELLCAST_SENT(event, unit, spell, rank, target, lineI self_lastTarget = targetGUID self_lastLineID = lineId if self.traceSpellId and self.traceSpellId == spellId then - Ovale:Printf("%s: %f %s (%d), lineId = %d", event, Ovale.now, spellName, spellId, lineId) - Ovale:Printf(" targetGUID = %s", targetGUID) + Ovale:FormatPrint("%s: %f %s (%d), lineId = %d", event, Ovale.now, spellName, spellId, lineId) + Ovale:FormatPrint(" targetGUID = %s", targetGUID) end for _, spellcast in ipairs(self_activeSpellcast) do if spellcast.lineId == lineId then @@ -259,7 +259,7 @@ end function OvaleFuture:UNIT_SPELLCAST_SUCCEEDED(event, unit, name, rank, lineId, spellId) if unit == "player" then if self.traceSpellId and self.traceSpellId == spellId then - Ovale:Printf("%s: %f %s (%d), lineId = %d", event, Ovale.now, spellName, spellId, lineId) + Ovale:FormatPrint("%s: %f %s (%d), lineId = %d", event, Ovale.now, spellName, spellId, lineId) end -- Search for a cast-time spell matching this spellcast that was added by UNIT_SPELLCAST_START. for _, spellcast in ipairs(self_activeSpellcast) do @@ -334,13 +334,13 @@ function OvaleFuture:COMBAT_LOG_EVENT_UNFILTERED(event, ...) or strfind(event, "SPELL_MISSED") == 1 then local spellId, spellName = select(12, ...) if self.traceSpellId and self.traceSpellId == spellId then - Ovale:Printf("%s: %f %s (%d), lineId = %d", event, Ovale.now, spellName, spellId, lineId) + Ovale:FormatPrint("%s: %f %s (%d), lineId = %d", event, Ovale.now, spellName, spellId, lineId) end for index, spellcast in ipairs(self_activeSpellcast) do if spellcast.allowRemove and (spellcast.spellId == spellId or spellcast.auraSpellId == spellId) then if not spellcast.channeled and (spellcast.removeOnSuccess or strfind(event, "SPELL_CAST_SUCCESS") ~= 1) then if self.traceSpellId and self.traceSpellId == spellId then - Ovale:Printf(" Spell finished: %f %s (%d)", Ovale.now, OvaleData:GetSpellName(spellId), spellId) + Ovale:FormatPrint(" Spell finished: %f %s (%d)", Ovale.now, OvaleData:GetSpellName(spellId), spellId) end tremove(self_activeSpellcast, index) self_pool:Release(spellcast) @@ -428,7 +428,7 @@ function OvaleFuture:Debug() Ovale:Print("No spells in flight!") end for spellId, lineId in self:InFlightSpells(Ovale.now) do - Ovale:Printf(" %s (%d), lineId = %s", OvaleData:GetSpellName(spellId), spellId, lineId) + Ovale:FormatPrint(" %s (%d), lineId = %s", OvaleData:GetSpellName(spellId), spellId, lineId) end end -- diff --git a/OvaleGUID.lua b/OvaleGUID.lua index bb015cf..044dad6 100644 --- a/OvaleGUID.lua +++ b/OvaleGUID.lua @@ -56,7 +56,7 @@ function OvaleGUID:OnDisable() end function OvaleGUID:Update(unitId) - --self:Printf("OvaleGUID:Update %s", unitId) + --self:FormatPrint("OvaleGUID:Update %s", unitId) local guid = API_UnitGUID(unitId) local previousGuid = self_guid[unitId] if previousGuid ~= guid then diff --git a/OvaleIcone.lua b/OvaleIcone.lua index cef6daa..865facb 100644 --- a/OvaleIcone.lua +++ b/OvaleIcone.lua @@ -199,7 +199,7 @@ local function SetParams(self, params, secure) local prefix = strsub(k, 1, f-1) local suffix = strsub(k, f + 5) local param - Ovale:Printf("%stype%s", prefix, suffix) + Ovale:FormatPrint("%stype%s", prefix, suffix) self:SetAttribute(prefix .. "type" .. suffix, "spell") self:SetAttribute("unit", self.params.target or "target") self:SetAttribute(k, OvaleData.spellList[v]) diff --git a/OvalePaperDoll.lua b/OvalePaperDoll.lua index 2f00dbd..1265018 100644 --- a/OvalePaperDoll.lua +++ b/OvalePaperDoll.lua @@ -202,21 +202,21 @@ function OvalePaperDoll:GetSpellHasteMultiplier() end function OvalePaperDoll:Debug() - Ovale:Printf("Class: %s", self.class) - Ovale:Printf("Level: %d", self.level) - Ovale:Printf("Specialization: %s", self.specialization) - Ovale:Printf("Agility: %d", self.agility) - Ovale:Printf("Intellect: %d", self.intellect) - Ovale:Printf("Spirit: %d", self.spirit) - Ovale:Printf("Stamina: %d", self.stamina) - Ovale:Printf("Strength: %d", self.strength) - Ovale:Printf("AP: %d", self.attackPower) - Ovale:Printf("RAP: %d", self.rangedAttackPower) - Ovale:Printf("Spell bonus damage: %d", self.spellBonusDamage) - Ovale:Printf("Spell bonus healing: %d", self.spellBonusHealing) - Ovale:Printf("Spell haste effect: %f%%", self.spellHaste) - Ovale:Printf("Melee haste effect: %f%%", self.meleeHaste) - Ovale:Printf("Ranged haste effect: %f%%", self.rangedHaste) - Ovale:Printf("Mastery effect: %f%%", self.masteryEffect) + Ovale:FormatPrint("Class: %s", self.class) + Ovale:FormatPrint("Level: %d", self.level) + Ovale:FormatPrint("Specialization: %s", self.specialization) + Ovale:FormatPrint("Agility: %d", self.agility) + Ovale:FormatPrint("Intellect: %d", self.intellect) + Ovale:FormatPrint("Spirit: %d", self.spirit) + Ovale:FormatPrint("Stamina: %d", self.stamina) + Ovale:FormatPrint("Strength: %d", self.strength) + Ovale:FormatPrint("AP: %d", self.attackPower) + Ovale:FormatPrint("RAP: %d", self.rangedAttackPower) + Ovale:FormatPrint("Spell bonus damage: %d", self.spellBonusDamage) + Ovale:FormatPrint("Spell bonus healing: %d", self.spellBonusHealing) + Ovale:FormatPrint("Spell haste effect: %f%%", self.spellHaste) + Ovale:FormatPrint("Melee haste effect: %f%%", self.meleeHaste) + Ovale:FormatPrint("Ranged haste effect: %f%%", self.rangedHaste) + Ovale:FormatPrint("Mastery effect: %f%%", self.masteryEffect) end -- diff --git a/OvalePool.lua b/OvalePool.lua index 7e51e09..925bf93 100644 --- a/OvalePool.lua +++ b/OvalePool.lua @@ -57,6 +57,6 @@ function OvalePool:Drain() end function OvalePool:Debug() - Ovale:Printf("Pool %s has size %d with %d item(s).", self.name, self.size, self.unused) + Ovale:FormatPrint("Pool %s has size %d with %d item(s).", self.name, self.size, self.unused) end -- diff --git a/OvaleStance.lua b/OvaleStance.lua index 2741b42..7a6d8c2 100644 --- a/OvaleStance.lua +++ b/OvaleStance.lua @@ -129,7 +129,7 @@ function OvaleStance:DebugStances() end function OvaleStance:Debug() - Ovale:Printf("current stance: %s", self_stance) + Ovale:FormatPrint("current stance: %s", self_stance) end -- Return true if the current stance matches the given name. -- 1.7.9.5