diff options
| author | ruki <[email protected]> | 2017-05-18 16:28:43 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2017-05-18 16:28:43 +0800 |
| commit | 75cfb11546cd271ebb8b251d291ad9c7b6277b66 (patch) | |
| tree | a54d87f951beef41ae0be1be17cd47d849b2e416 /xmake | |
| parent | 102c4ce16295fe322704b6e5186f325effa989a8 (diff) | |
improve print and table.dump
Diffstat (limited to 'xmake')
| -rw-r--r-- | xmake/core/base/table.lua | 31 | ||||
| -rw-r--r-- | xmake/core/base/utils.lua | 18 | ||||
| -rw-r--r-- | xmake/plugins/lua/xmake.lua | 7 |
3 files changed, 24 insertions, 32 deletions
diff --git a/xmake/core/base/table.lua b/xmake/core/base/table.lua index 3767fc1c4..b7f5719a9 100644 --- a/xmake/core/base/table.lua +++ b/xmake/core/base/table.lua @@ -208,18 +208,9 @@ end -- dump it with the level function table._dump(self, exclude, level) - -- dump string - if type(self) == "string" then - io.write(string.format("%q", self)) - -- dump boolean - elseif type(self) == "boolean" then + -- dump basic type + if type(self) == "string" or type(self) == "boolean" or type(self) == "number" then io.write(tostring(self)) - -- dump number - elseif type(self) == "number" then - io.write(self) - -- dump function - elseif type(self) == "function" then - io.write("<function>") -- dump table elseif type(self) == "table" then @@ -254,9 +245,7 @@ function table._dump(self, exclude, level) end -- dump value - if not table._dump(v, exclude, level + 1) then - return false - end + table._dump(v, exclude, level + 1) -- dump newline io.write("\n") @@ -269,17 +258,9 @@ function table._dump(self, exclude, level) io.write(" ") end io.write("}\n") - -- dump userdata - elseif type(self) == "userdata" then - io.write("<userdata>") - else - -- error - print(string.format("error: invalid object type: %s", type(self))) - return false - end - - -- ok - return true + else + io.write("<" .. tostring(v) .. ">") + end end -- dump it diff --git a/xmake/core/base/utils.lua b/xmake/core/base/utils.lua index 030c10d5c..3bda8060c 100644 --- a/xmake/core/base/utils.lua +++ b/xmake/core/base/utils.lua @@ -29,13 +29,29 @@ local utils = utils or {} local option = require("base/option") local colors = require("base/colors") local string = require("base/string") +local table = require("base/table") -- print string with newline function utils._print(...) -- print it if not quiet if not option.get("quiet") then - print(...) + local values = {...} + for i, v in ipairs(values) do + -- dump basic type + if type(v) == "string" or type(v) == "boolean" or type(v) == "number" then + io.write(tostring(v)) + -- dump table + elseif type(v) == "table" then + table.dump(v) + else + io.write("<" .. tostring(v) .. ">") + end + if i ~= #values then + io.write(" ") + end + end + io.write('\n') end end diff --git a/xmake/plugins/lua/xmake.lua b/xmake/plugins/lua/xmake.lua index 77833e9a3..2789bf26a 100644 --- a/xmake/plugins/lua/xmake.lua +++ b/xmake/plugins/lua/xmake.lua @@ -69,12 +69,7 @@ task("lua") else -- run modules (xmake lua core.xxx.xxx) - local result = import(script)(unpack(option.get("arguments") or {})) - if type(result) == "table" then - table.dump(table) - elseif result ~= nil then - print(result) - end + print(import(script)(unpack(option.get("arguments") or {}))) end else -- enter interactive mode |
