Quantcast

Allow for custom functions in scripts to support the usual parameters.

Johnny C. Lam [10-19-13 - 07:54]
Allow for custom functions in scripts to support the usual parameters.

The new syntax is:

    AddFunction FuncName param1=value1 param2=value2 { ... }

Where the parameter=value pairs can be used to determine if that function
meets the current conditions, e.g., mastery=1 to only have that function
be valid in the first specialization.

git-svn-id: svn://svn.curseforge.net/wow/ovale/mainline/trunk@1079 d5049fe3-3747-40f7-a4b5-f36d6801af5f
Filename
OvaleCompile.lua
diff --git a/OvaleCompile.lua b/OvaleCompile.lua
index 4bf920a..cab9f5b 100644
--- a/OvaleCompile.lua
+++ b/OvaleCompile.lua
@@ -586,12 +586,16 @@ local function ParseCommands(text)
 	return nodeId
 end

-local function ParseAddFunction(name, text)
+local function ParseAddFunction(name, params, text)
 	local nodeId = ParseCommands(text)
 	local node = self_pool:Get()
 	node.type = "customfunction"
 	node.name = name
+	node.params = ParseParameters(params)
 	node.a = self_node[tonumber(nodeId)]
+	if not TestConditions(node.params) then
+		return nil
+	end
 	return AddNode(node)
 end

@@ -716,8 +720,8 @@ local function CompileScript(text)
 	text = CompileDeclarations(text)
 	text = CompileInputs(text)

-	for name, t in strgmatch(text, "AddFunction%s+(%w+)%s*(%b{})") do
-		local node = ParseAddFunction(name, t)
+	for name, p, t in strgmatch(text, "AddFunction%s+(%w+)%s*(.-)%s*(%b{})") do
+		local node = ParseAddFunction(name, p, t)
 		if node then
 			self_customFunctions[name] = node
 		end