Quantcast

Follow Model-View-Controller better to avoid infinite loops.

Johnny C. Lam [07-14-14 - 01:25]
Follow Model-View-Controller better to avoid infinite loops.

This avoids UpdateIcons() calling EvaluateScript() which may call
UpdateIcons() again.
Filename
OvaleCompile.lua
OvaleFrame.lua
diff --git a/OvaleCompile.lua b/OvaleCompile.lua
index 27693c6..3ada701 100644
--- a/OvaleCompile.lua
+++ b/OvaleCompile.lua
@@ -426,10 +426,10 @@ function OvaleCompile:CompileScript(event)
 	self:EventHandler(event)
 end

-function OvaleCompile:EvaluateScript()
+function OvaleCompile:EvaluateScript(forceEvaluation)
 	profiler.Start("OvaleCompile_EvaluateScript")
 	self_canEvaluate = self_canEvaluate or Ovale:IsPreloaded(self_requirePreload)
-	if self_canEvaluate and self.ast then
+	if self_canEvaluate and self.ast and (forceEvaluation or not self.serial or self.serial < self_serial) then
 		Ovale:DebugPrint(OVALE_COMPILE_DEBUG, "Evaluating script.")
 		-- Reset compilation state.
 		local ok = true
@@ -438,6 +438,7 @@ function OvaleCompile:EvaluateScript()
 		wipe(self_icon)
 		OvaleCooldown:ResetSharedCooldowns()
 		self_timesEvaluated = self_timesEvaluated + 1
+		self.serial = self_serial

 		-- Evaluate every declaration node of the script.
 		for _, node in ipairs(self.ast.child) do
@@ -481,11 +482,6 @@ function OvaleCompile:GetFunctionNode(name)
 end

 function OvaleCompile:GetIconNodes()
-	-- Evaluate the script if it is outdated.
-	if not self.serial or self.serial < self_serial then
-		self.serial = self_serial
-		self:EvaluateScript()
-	end
 	return self_icon
 end

diff --git a/OvaleFrame.lua b/OvaleFrame.lua
index 1fbd443..f49dc05 100644
--- a/OvaleFrame.lua
+++ b/OvaleFrame.lua
@@ -171,6 +171,7 @@ do
 		local refresh = forceRefresh or next(Ovale.refreshNeeded)
 		if not refresh then return end

+		OvaleCompile:EvaluateScript()
 		local iconNodes = OvaleCompile:GetIconNodes()
 		if not iconNodes then return end