Quantcast

Don't load/reference script code for other classes that won't be used.

Johnny C. Lam [10-24-13 - 05:40]
Don't load/reference script code for other classes that won't be used.

Only register scripts that are for the current class and allow the garbage
collector to sweep away unused code strings.

git-svn-id: svn://svn.curseforge.net/wow/ovale/mainline/trunk@1110 d5049fe3-3747-40f7-a4b5-f36d6801af5f
Filename
OvaleCompile.lua
OvaleOptions.lua
OvaleScripts.lua
diff --git a/OvaleCompile.lua b/OvaleCompile.lua
index 218fb63..dc51f8f 100644
--- a/OvaleCompile.lua
+++ b/OvaleCompile.lua
@@ -841,8 +841,8 @@ function OvaleCompile:Compile()
 	local profile = OvaleOptions:GetProfile()
 	local source = profile.source
 	local code
-	if source and OvaleScripts.script[OvalePaperDoll.class][source] then
-		code = OvaleScripts.script[OvalePaperDoll.class][source].code
+	if source and OvaleScripts.script[source] then
+		code = OvaleScripts.script[source].code
 	else
 		code = ""
 	end
diff --git a/OvaleOptions.lua b/OvaleOptions.lua
index f33cf17..00fe530 100644
--- a/OvaleOptions.lua
+++ b/OvaleOptions.lua
@@ -352,8 +352,8 @@ local self_options =
 					get = function(info)
 						local source = OvaleOptions.db.profile.source
 						local code
-						if source and OvaleScripts.script[OvalePaperDoll.class][source] then
-							code = OvaleScripts.script[OvalePaperDoll.class][source].code
+						if source and OvaleScripts.script[source] then
+							code = OvaleScripts.script[source].code
 						else
 							code = ""
 						end
@@ -380,12 +380,12 @@ local self_options =
 						local class = OvalePaperDoll.class
 						local source = OvaleOptions.db.profile.source
 						local code
-						if source and OvaleScripts.script[OvalePaperDoll.class][source] then
-							code = OvaleScripts.script[OvalePaperDoll.class][source].code
+						if source and OvaleScripts.script[source] then
+							code = OvaleScripts.script[source].code
 						else
 							code = ""
 						end
-						OvaleScripts.script[class]["custom"].code = code
+						OvaleScripts.script["custom"].code = code
 						OvaleOptions.db.profile.source = "custom"
 						OvaleOptions.db.profile.code = code
 						OvaleOptions:SendMessage("Ovale_ScriptChanged")
diff --git a/OvaleScripts.lua b/OvaleScripts.lua
index edf1a01..0e19b33 100644
--- a/OvaleScripts.lua
+++ b/OvaleScripts.lua
@@ -18,45 +18,31 @@ local OvalePaperDoll = Ovale.OvalePaperDoll
 --</private-static-properties>

 --<public-static-properties>
--- Table of default class scripts, indexed by class tokens.
-OvaleScripts.script = {
-	DEATHKNIGHT = {},
-	DRUID = {},
-	HUNTER = {},
-	MAGE = {},
-	MONK = {},
-	PALADIN = {},
-	PRIEST = {},
-	ROGUE = {},
-	SHAMAN = {},
-	WARLOCK = {},
-	WARRIOR = {},
-}
+-- Table of scripts, indexed by source; a script is a table { description = description, code = "..." }.
+OvaleScripts.script = {}
 --</public-static-properties>

 --<public-static-methods>
 -- Return a table of script descriptions indexed by source.
 function OvaleScripts:GetDescriptions()
 	local descriptionsTable = {}
-	for src, tbl in pairs(self.script[OvalePaperDoll.class]) do
+	for src, tbl in pairs(self.script) do
 		descriptionsTable[src] = tbl.desc
 	end
 	return descriptionsTable
 end

 function OvaleScripts:RegisterScript(class, source, description, code)
-	-- Default values for description and code.
-	description = description or source
-	code = code or ""
-
-	if not self.script[class][source] then
-		self.script[class][source] = {}
+	if class == OvalePaperDoll.class then
+		self.script[source] = self.script[source] or {}
+		self.script[source].desc = description or source
+		self.script[source].code = code or ""
 	end
-	self.script[class][source].desc = description
-	self.script[class][source].code = code
 end

 function OvaleScripts:UnregisterScript(class, source)
-	self.script[class][source] = nil
+	if class == OvalePaperDoll.class then
+		self.script[source] = nil
+	end
 end
---</public-static-methods>
\ No newline at end of file
+--</public-static-methods>