summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOpportunityLiu <[email protected]>2019-08-26 18:24:26 +0800
committerOpportunityLiu <[email protected]>2019-08-26 18:24:26 +0800
commit172076db9fa929c5b6dd20a733d15cf28ef092aa (patch)
treedd72605248ad7b57179dbe3d34ecdb33faba933e
parent4c7f077a102f35428766bb3fddb8a93e30313cc1 (diff)
rename params
-rw-r--r--xmake/core/base/dump.lua1
-rw-r--r--xmake/core/base/serialize.lua50
-rw-r--r--xmake/core/base/utils.lua2
-rw-r--r--xmake/core/sandbox/modules/import/core/sandbox/sandbox.lua2
4 files changed, 25 insertions, 30 deletions
diff --git a/xmake/core/base/dump.lua b/xmake/core/base/dump.lua
index cac43ebf3..987f5491f 100644
--- a/xmake/core/base/dump.lua
+++ b/xmake/core/base/dump.lua
@@ -362,6 +362,7 @@ function dump._print(value, indent, verbose)
io.write(indent)
dump._print_scalar(value)
end
+ io.write("\n")
end
return dump._print
diff --git a/xmake/core/base/serialize.lua b/xmake/core/base/serialize.lua
index 5ffb6b818..423c9dc45 100644
--- a/xmake/core/base/serialize.lua
+++ b/xmake/core/base/serialize.lua
@@ -48,12 +48,12 @@ function serialize._makedefault(val, opt)
return tostring(val)
end
-function serialize._maketable(object, opt, level, path, reftab)
+function serialize._maketable(object, opt, level, pathsegs, reftab)
level = level or 0
reftab = reftab or {}
- path = path or {}
- reftab[object] = table.copy(path)
+ pathsegs = pathsegs or {}
+ reftab[object] = table.copy(pathsegs)
-- serialize child items
local childlevel = level + 1
@@ -85,9 +85,9 @@ function serialize._maketable(object, opt, level, path, reftab)
if reftab[v] then
sval, err = serialize._makeref(reftab[v], opt)
else
- table.insert(path, k)
- sval, err = serialize._maketable(v, opt, childlevel, path, reftab)
- table.remove(path)
+ table.insert(pathsegs, k)
+ sval, err = serialize._maketable(v, opt, childlevel, pathsegs, reftab)
+ table.remove(pathsegs)
end
else
sval, err = serialize._make(v, opt)
@@ -191,36 +191,34 @@ function serialize._resolvefunction(root, fenv, bytecode)
return func
end
-function serialize._makeref(path, opt)
+function serialize._makeref(pathsegs, opt)
-- root reference
- if path[1] == nil then
+ if pathsegs[1] == nil then
return "ref()"
end
- local ppath = {}
- for i, v in ipairs(path) do
- ppath[i] = serialize._make(v, opt)
+ for i, v in ipairs(pathsegs) do
+ pathsegs[i] = serialize._make(v, opt)
end
- return "ref(" .. table.concat(ppath, opt.indentstr and ", " or ",") .. ")"
+ return "ref(" .. table.concat(pathsegs, opt.indentstr and ", " or ",") .. ")"
end
function serialize._resolveref(root, fenv, ...)
+ local pathsegs = table.pack("<root>", ...)
local pos = root
- local path = table.pack(...)
- for i = 1, path.n do
- local v = path[i]
- if type(v) ~= "string" and type(v) ~= "number" then
+ for i = 2, pathsegs.n do
+ local pathseg = pathsegs[i]
+ if type(pathseg) ~= "string" and type(pathseg) ~= "number" then
return nil, "path segments should be string or number"
end
if type(pos) ~= "table" then
- local vpre = serialize._make(v, {})
- table.insert(path, 1, "<root>")
- local pathstr = table.concat(path, "/", 1, i)
+ local vpre = serialize._make(pathseg, {})
+ local pathstr = table.concat(pathsegs, "/", 1, i)
return nil, string.format("unable to resolve [%s] in %s, which is %s", vpre, pathstr, pos)
end
- pos = pos[v]
+ pos = pos[pathseg]
end
return pos
end
@@ -355,8 +353,8 @@ end
-- @param object object to search stubs
-- root root object
-- fenv fenv of deserialzer caller
--- path path key for current item
-function serialize._resolvestub(object, root, fenv, path)
+-- pathseg path key for current item
+function serialize._resolvestub(object, root, fenv, pathseg)
if type(object) ~= "table" then
return object
end
@@ -364,23 +362,23 @@ function serialize._resolvestub(object, root, fenv, path)
if object.isstub == stub.isstub then
local ok, result_or_errors, errors = pcall(object, root, fenv)
if ok and errors == nil then
- return result
+ return result_or_errors
end
-- resolve & concat path only if error occurs
- local pathseg = {}
+ local pathsegs = {}
local level = 1
while true do
if debug.getinfo(level, "f").func ~= serialize._resolvestub then
break
end
local _, p = debug.getlocal(level, 4)
- table.insert(pathseg, 1, p)
+ table.insert(pathsegs, 1, p)
level = level + 1
end
-- make error message
local errmsg = (ok and errors) or result_or_errors or "unspecified error"
- return nil, string.format("failed to resolve stub '%s' at %s: %s", object.name, table.concat(pathseg, "/"), errmsg)
+ return nil, string.format("failed to resolve stub '%s' at %s: %s", object.name, table.concat(pathsegs, "/"), errmsg)
end
for k, v in pairs(object) do
diff --git a/xmake/core/base/utils.lua b/xmake/core/base/utils.lua
index 584af7eb7..58721cc1e 100644
--- a/xmake/core/base/utils.lua
+++ b/xmake/core/base/utils.lua
@@ -61,11 +61,9 @@ function utils.dump(...)
if values_count == 1 then
dump(values[1], indent or "", diagnosis)
- io.write("\n")
else
for i = 1, values_count do
dump(values[i], indent or string.format("%2d: ", i), diagnosis)
- io.write("\n")
end
end
diff --git a/xmake/core/sandbox/modules/import/core/sandbox/sandbox.lua b/xmake/core/sandbox/modules/import/core/sandbox/sandbox.lua
index a6f19f93d..1ae8a1728 100644
--- a/xmake/core/sandbox/modules/import/core/sandbox/sandbox.lua
+++ b/xmake/core/sandbox/modules/import/core/sandbox/sandbox.lua
@@ -40,7 +40,6 @@ function sandbox_core_sandbox._interactive_dump(...)
local n = values.n
if n <= 1 then
dump(values[1], "< ", diagnosis)
- io.write("\n")
else
local fmt = "< %d: "
if n >= 1000 then
@@ -53,7 +52,6 @@ function sandbox_core_sandbox._interactive_dump(...)
end
for i = 1, n do
dump(values[i], string.format(fmt, i), diagnosis)
- io.write("\n")
end
end
end