From 90e91e6e508e26cedc2c5c801e40d8f8fc299fa6 Mon Sep 17 00:00:00 2001 From: "Johnny C. Lam" Date: Thu, 31 Oct 2013 19:06:21 +0000 Subject: [PATCH] Rudimentary support for Include(name) directives in scripts. - Include(name) will cause the the contents of from the script library to be inserted at that point prior to compiling the script. - Include() may be nested, i.e., a script may include a script that includes another script, etc. - A script that is intended to be included in other scripts and not to be listed as a selectable script for evaluation at runtime should be registered with OvaleScripts using: :RegisterScript(class, name, description, code, scriptType) where scriptType is anything other than "script", e.g., "include" git-svn-id: svn://svn.curseforge.net/wow/ovale/mainline/trunk@1118 d5049fe3-3747-40f7-a4b5-f36d6801af5f --- Ovale.toc | 1 + OvaleCompile.lua | 34 +++++++++++++++++++++++++--------- OvaleScripts.lua | 30 +++++++++++++++++------------- scripts/scripts.xml | 2 ++ 4 files changed, 45 insertions(+), 22 deletions(-) create mode 100644 scripts/scripts.xml diff --git a/Ovale.toc b/Ovale.toc index 8ad5da8..15c8dd2 100644 --- a/Ovale.toc +++ b/Ovale.toc @@ -41,6 +41,7 @@ OvaleAura.lua OvaleComboPoints.lua OvaleRecount.lua OvaleScripts.lua +scripts\scripts.xml defaut\scripts.xml OvaleSkada.lua OvaleSpellDamage.lua diff --git a/OvaleCompile.lua b/OvaleCompile.lua index 185fa56..2d53696 100644 --- a/OvaleCompile.lua +++ b/OvaleCompile.lua @@ -269,7 +269,7 @@ local function ParseFunction(prefix, func, params) self_missingSpellList[spellId] = spellName end else - Ovale:DebugPrintf(OVALE_UNKNOWN_SPELL_DEBUG, "Unknown spell with ID %d", spellId) + Ovale:DebugPrintf(OVALE_UNKNOWN_SPELL_DEBUG, "Unknown spell with ID %s", spellId) end end end @@ -575,6 +575,18 @@ local function ParseLua(text) return AddNode(node) end +local function ParseInclude(name) + local code + local script = OvaleScripts.script[name] + if script then + code = script.code + end + if not code then + Ovale:FormatPrint("Cannot Include(...): script named \"%s\" not found", name) + end + return code or "" +end + local function ParseCommands(text) local original = text text = strgsub(text,"(%b[])", ParseLua) @@ -699,13 +711,6 @@ local function ParseL(text) return '"'..L[text]..'"' end --- Suppression des commentaires -local function CompileComments(text) - text = strgsub(text, "#.-\n","") - text = strgsub(text, "#.*$","") - return text -end - -- On compile les AddCheckBox et AddListItem local function CompileInputs(text) Ovale.casesACocher = {} @@ -768,7 +773,18 @@ local function CompileScript(text) end wipe(self_node) - text = CompileComments(text) + -- Loop and strip out comments and replace Include() directives until there + -- are no more inclusions to make. + while true do + local was = text + text = strgsub(text, "#.-\n","") + text = strgsub(text, "#.*$","") + text = strgsub(text, "Include%s*%(%s*([%w_]+)%s*%)", ParseInclude) + if was == text then + break + end + end + text = CompileDeclarations(text) text = CompileInputs(text) diff --git a/OvaleScripts.lua b/OvaleScripts.lua index 0e19b33..6d982e6 100644 --- a/OvaleScripts.lua +++ b/OvaleScripts.lua @@ -18,31 +18,35 @@ local OvalePaperDoll = Ovale.OvalePaperDoll -- -- --- Table of scripts, indexed by source; a script is a table { description = description, code = "..." }. +-- A "script" is a table { type = "scriptType", desc = "description", code = "..." } +-- Table of scripts, indexed by name. OvaleScripts.script = {} -- -- --- Return a table of script descriptions indexed by source. -function OvaleScripts:GetDescriptions() +-- Return a table of script descriptions indexed by name. +function OvaleScripts:GetDescriptions(scriptType) + scriptType = scriptType or "script" local descriptionsTable = {} - for src, tbl in pairs(self.script) do - descriptionsTable[src] = tbl.desc + for name, script in pairs(self.script) do + if script.type == scriptType then + descriptionsTable[name] = script.desc + end end return descriptionsTable end -function OvaleScripts:RegisterScript(class, source, description, code) +function OvaleScripts:RegisterScript(class, name, description, code, scriptType) 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 "" + self.script[name] = self.script[name] or {} + local script = self.script[name] + script.type = scriptType or "script" + script.desc = description or name + script.code = code or "" end end -function OvaleScripts:UnregisterScript(class, source) - if class == OvalePaperDoll.class then - self.script[source] = nil - end +function OvaleScripts:UnregisterScript(name) + self.script[name] = nil end -- diff --git a/scripts/scripts.xml b/scripts/scripts.xml new file mode 100644 index 0000000..13345be --- /dev/null +++ b/scripts/scripts.xml @@ -0,0 +1,2 @@ + + -- 1.7.9.5