summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2019-06-19 21:04:58 +0800
committerGitHub <[email protected]>2019-06-19 21:04:58 +0800
commitfe78b1755a16442fb91eba7cc232cd4446f755ee (patch)
tree0bc0a7e2dbc692e7b1542bc88a4f476791158828
parent526556809d220564e6565fbe2c6deec723c9f343 (diff)
parent608f198b3ab87f83b2458e58c1f7dcc6a2beebc0 (diff)
Merge pull request #459 from OpportunityLiu/dev
fix interactive_dump
-rw-r--r--xmake/core/base/table.lua10
-rw-r--r--xmake/core/sandbox/modules/import/core/sandbox/sandbox.lua25
2 files changed, 28 insertions, 7 deletions
diff --git a/xmake/core/base/table.lua b/xmake/core/base/table.lua
index e21680379..3fd35c082 100644
--- a/xmake/core/base/table.lua
+++ b/xmake/core/base/table.lua
@@ -256,5 +256,15 @@ function table.unique(array, barrier)
return array
end
+-- pack arguments into a table
+function table.pack(...)
+ return { n = select("#", ...), ... }
+end
+
+-- unpack table values
+function table.unpack(list, i, j)
+ return unpack(list, i, j)
+end
+
-- return module: table
return table
diff --git a/xmake/core/sandbox/modules/import/core/sandbox/sandbox.lua b/xmake/core/sandbox/modules/import/core/sandbox/sandbox.lua
index 3f9ed4ccc..5aa55a0c6 100644
--- a/xmake/core/sandbox/modules/import/core/sandbox/sandbox.lua
+++ b/xmake/core/sandbox/modules/import/core/sandbox/sandbox.lua
@@ -27,19 +27,30 @@ local raise = require("sandbox/modules/raise")
local try = require("sandbox/modules/try")
local catch = require("sandbox/modules/catch")
local utils = require("base/utils")
+local table = require("base/table")
local history = require("project/history")
local dump = require("base/dump")
-- print variables for interactive mode
-function sandbox_core_sandbox._interactive_dump(v0, ...)
- local values = { v0, ... }
- if #values <= 1 then
- -- in case v0 is nil
- dump(v0, "< ")
+function sandbox_core_sandbox._interactive_dump(...)
+ local values = table.pack(...)
+ -- do not use #values since nil might be included
+ local n = values.n
+ if n <= 1 then
+ dump(values[1], "< ")
io.write("\n")
else
- for i, v in ipairs(values) do
- dump(v, "<" .. ((i < 10) and (i .. " ") or (i .. " ")))
+ local fmt = "< %d: "
+ if n >= 1000 then
+ -- try `unpack({}, 1, 5000)`, wish you happy!
+ fmt = "< %4d: "
+ elseif n >= 100 then
+ fmt = "< %3d: "
+ elseif n >= 10 then
+ fmt = "< %2d: "
+ end
+ for i = 1, n do
+ dump(values[i], string.format(fmt, i))
io.write("\n")
end
end