summaryrefslogtreecommitdiff
path: root/xmake/core/base/task.lua
diff options
context:
space:
mode:
authorruki <[email protected]>2018-02-01 23:20:56 +0800
committerruki <[email protected]>2018-02-01 14:05:36 +0800
commit7338d6b1e13648f3175555b1f1c4c69301f5bbd0 (patch)
treef838f2569ee75c8f2b0f4b268fb761659eae1018 /xmake/core/base/task.lua
parentdc29eb443366d6ff754c7f0c05e51e7d1aab3c21 (diff)
add choice to config menu
Diffstat (limited to 'xmake/core/base/task.lua')
-rw-r--r--xmake/core/base/task.lua54
1 files changed, 35 insertions, 19 deletions
diff --git a/xmake/core/base/task.lua b/xmake/core/base/task.lua
index 92a74ff3d..7288f966f 100644
--- a/xmake/core/base/task.lua
+++ b/xmake/core/base/task.lua
@@ -210,7 +210,23 @@ function task._interpreter()
return interp
end
--- bind tasks for menu with an sandbox instance
+-- bind script with a sandbox instance
+function task._bind_script(interp, script)
+
+ -- make sandbox instance with the given script
+ local instance, errors = sandbox.new(script, interp:filter(), interp:rootdir())
+ if not instance then
+ return nil, errors
+ end
+
+ -- check
+ assert(instance:script())
+
+ -- update option script
+ return instance:script()
+end
+
+-- bind tasks for menu with a sandbox instance
function task._bind(tasks, interp)
-- check
@@ -231,20 +247,16 @@ function task._bind(tasks, interp)
if options then
-- make full options
+ local errors = nil
local options_full = {}
for _, opt in ipairs(options) do
-- this option is function? translate it
if type(opt) == "function" then
-
- -- make sandbox instance with the given script
- local instance, errors = sandbox.new(opt, interp:filter(), interp:rootdir())
- if not instance then
+ opt, errors = task._bind_script(interp, opt)
+ if not opt then
return false, errors
end
-
- -- update option script
- opt = instance:script()
end
-- insert option
@@ -255,11 +267,13 @@ function task._bind(tasks, interp)
options = options_full
taskinfo.menu.options = options_full
- -- bind sandbox for option description
+ -- bind sandbox for scripts in option
for _, opt in ipairs(options) do
- -- bind description
+ -- bind description and values
if type(opt) == "table" then
+
+ -- bind description
for i = 5, 64 do
-- the description, @note some option may be nil
@@ -268,19 +282,21 @@ function task._bind(tasks, interp)
-- the description is function? wrap it for calling it in the sandbox
if type(description) == "function" then
-
- -- make sandbox instance with the given script
- local instance, errors = sandbox.new(description, interp:filter(), interp:rootdir())
- if not instance then
+ description, errors = task._bind_script(interp, description)
+ if not description then
return false, errors
end
+ opt[i] = description
+ end
+ end
- -- check
- assert(instance:script())
-
- -- update option script
- opt[i] = instance:script()
+ -- bind values
+ if type(opt.values) == "function" then
+ local values, errors = task._bind_script(interp, opt.values)
+ if not values then
+ return false, errors
end
+ opt.values = values
end
end
end