summaryrefslogtreecommitdiff
path: root/xmake/core/base/utils.lua
diff options
context:
space:
mode:
authorOpportunityLiu <[email protected]>2019-07-05 18:49:12 +0800
committerOpportunityLiu <[email protected]>2019-07-05 18:49:12 +0800
commitdae10753450c75af10c300dbaf00653b15a27e87 (patch)
treec17e7b563d8a4bcd3fac50ffbf8ae78864efac41 /xmake/core/base/utils.lua
parent789e43df6a5430db61fae2c2b268ab42376616e6 (diff)
improve dump
Diffstat (limited to 'xmake/core/base/utils.lua')
-rw-r--r--xmake/core/base/utils.lua39
1 files changed, 36 insertions, 3 deletions
diff --git a/xmake/core/base/utils.lua b/xmake/core/base/utils.lua
index ec7c63bcc..d8f1ec7c2 100644
--- a/xmake/core/base/utils.lua
+++ b/xmake/core/base/utils.lua
@@ -30,11 +30,44 @@ local io = require("base/io")
local dump = require("base/dump")
-- dump value
-function utils.dump(value, indent)
- if not option.get("quiet") then
- dump(value, indent or "")
+function utils.dump(...)
+ if option.get("quiet") then
+ return ...
+ end
+
+ -- show caller info
+ if option.get("diagnosis") then
+ local info = debug.getinfo(2)
+ local line = info.currentline
+ if not line or line < 0 then line = info.linedefined end
+ io.write(string.format("dump form %s %s:%s\n", info.name or "<anonymous>", info.source, line))
+ end
+
+ local values = table.pack(...)
+ if values.n == 0 then
+ return
+ end
+ local indent = nil
+ local values_count = values.n
+ values.n = nil
+ -- use last input as indent if it is a string
+ if values_count > 1 and type(values[values_count]) == "string" then
+ indent = values[values_count]
+ values[values_count] = nil
+ values_count = values_count - 1
+ end
+
+ if values_count == 1 then
+ dump(values[1], indent or "")
io.write("\n")
+ else
+ for i = 1, values_count do
+ dump(values[i], indent or string.format("%2d: ", i))
+ io.write("\n")
+ end
end
+
+ return table.unpack(values, 1, values_count)
end
-- print string with newline