diff options
| author | ruki <[email protected]> | 2020-01-17 22:15:32 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2020-01-17 22:15:32 +0800 |
| commit | a859e101ee88ec25fd948a08d2a02e7621241e7f (patch) | |
| tree | b6558e583ac20627222139a28f2c9c87c3af3c19 /xmake/plugins/lua | |
| parent | ffce1ede94e7873e7ab248b05d468e84f6c205d0 (diff) | |
| parent | dc25ac7a87256a0470f523017ee790b29e9b6f2d (diff) | |
Merge pull request #667 from OpportunityLiu/options
Improve to parse command line options
Diffstat (limited to 'xmake/plugins/lua')
| -rw-r--r-- | xmake/plugins/lua/xmake.lua | 30 |
1 files changed, 23 insertions, 7 deletions
diff --git a/xmake/plugins/lua/xmake.lua b/xmake/plugins/lua/xmake.lua index 1fc96c724..e264ba14d 100644 --- a/xmake/plugins/lua/xmake.lua +++ b/xmake/plugins/lua/xmake.lua @@ -53,18 +53,32 @@ task("lua") -- get script if script then + local args = option.get("arguments") or {} + args.n = #args + for i, value in ipairs(args) do + if value:startswith('@') then + local v, err = string.deserialize(value:sub(2)) + if err then + -- for strings that failed to deserialize, regaed it as a normal string, just show a warning message + utils.warning(err) + else + args[i] = v + end + end + end + -- import and run script if path.extension(script) == ".lua" and os.isfile(script) then -- run the given lua script file (xmake lua /tmp/script.lua) vprint("running given lua script file: %s", path.relative(script)) - import(path.basename(script), {rootdir = path.directory(script), anonymous = true})(unpack(option.get("arguments") or {})) + import(path.basename(script), {rootdir = path.directory(script), anonymous = true})(table.unpack(args, 1, args.n)) elseif os.isfile(path.join(os.scriptdir(), "scripts", script .. ".lua")) then -- run builtin lua script (xmake lua echo "hello xmake") vprint("running builtin lua script: %s", script) - import("scripts." .. script, {anonymous = true})(unpack(option.get("arguments") or {})) + import("scripts." .. script, {anonymous = true})(table.unpack(args, 1, args.n)) else -- attempt to find the builtin module @@ -79,13 +93,13 @@ task("lua") if object then -- run builtin modules (xmake lua core.xxx.xxx) vprint("running builtin module: %s", script) - result = object(unpack(option.get("arguments") or {})) + result = table.pack(object(table.unpack(args, 1, args.n))) else -- run imported modules (xmake lua core.xxx.xxx) vprint("running imported module: %s", script) - result = import(script, {anonymous = true})(unpack(option.get("arguments") or {})) + result = table.pack(import(script, {anonymous = true})(table.unpack(args, 1, args.n))) end - if result ~= nil then utils.dump(result) end + if result and result.n ~= 0 then utils.dump(unpack(result, 1, result.n)) end end else -- enter interactive mode @@ -115,9 +129,11 @@ task("lua") " - xmake lua (enter interactive mode)", " - xmake lua /tmp/script.lua", " - xmake lua echo 'hello xmake'", - " - xmake lua core.xxx.xxx", + " - xmake lua core.xxx.xxx", " - xmake lua -c 'print(...)' hello xmake!" } - , {nil, "arguments", "vs", nil, "The script arguments." } + , {nil, "arguments", "vs", nil, "The script arguments, use '@' to enable deserializing.", + "e.g.", + " - xmake lua lib.detect.find_tool tar @{version=true}" } } } |
