summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2019-07-05 22:23:31 +0800
committerGitHub <[email protected]>2019-07-05 22:23:31 +0800
commitc43290bea303900e334243e4b38a8f4f72b8cf9d (patch)
tree3d244ec48ff1f6e90f575d7cf4b38ccf9a3f8828
parent3bb195602e6c30c0e18a77223e9903f7752c94f7 (diff)
parent639552074da609025ca6609350c90263ebe684e7 (diff)
Merge pull request #476 from OpportunityLiu/dev
use table.pack to fix some hidden bug
-rw-r--r--xmake/core/sandbox/modules/ipairs.lua6
-rw-r--r--xmake/core/sandbox/modules/irpairs.lua12
-rw-r--r--xmake/core/sandbox/modules/try.lua9
3 files changed, 14 insertions, 13 deletions
diff --git a/xmake/core/sandbox/modules/ipairs.lua b/xmake/core/sandbox/modules/ipairs.lua
index 931a1776a..10e8b0f85 100644
--- a/xmake/core/sandbox/modules/ipairs.lua
+++ b/xmake/core/sandbox/modules/ipairs.lua
@@ -46,13 +46,13 @@ function sandbox_ipairs(t, filter, ...)
local has_filter = type(filter) == "function"
-- init iterator
- local args = {...}
+ local args = table.pack(...)
local iter = function (t, i)
i = i + 1
local v = t[i]
- if v then
+ if v ~= nil then
if has_filter then
- v = filter(v, unpack(args))
+ v = filter(v, table.unpack(args, 1, args.n))
end
return i, v
end
diff --git a/xmake/core/sandbox/modules/irpairs.lua b/xmake/core/sandbox/modules/irpairs.lua
index fdc76824d..7f837ed07 100644
--- a/xmake/core/sandbox/modules/irpairs.lua
+++ b/xmake/core/sandbox/modules/irpairs.lua
@@ -46,13 +46,13 @@ function sandbox_irpairs(t, filter, ...)
local has_filter = type(filter) == "function"
-- init iterator
- local args = {...}
+ local args = table.pack(...)
local iter = function (t, i)
- if i > 1 then
- i = i - 1
- local v = t[i]
+ i = i - 1
+ local v = t[i]
+ if v ~= nil then
if has_filter then
- v = filter(v, unpack(args))
+ v = filter(v, table.unpack(args, 1, args.n))
end
return i, v
end
@@ -60,7 +60,7 @@ function sandbox_irpairs(t, filter, ...)
-- return iterator and initialized state
t = table.wrap(t)
- return iter, t, #t + 1
+ return iter, t, table.maxn(t) + 1
end
-- load module
diff --git a/xmake/core/sandbox/modules/try.lua b/xmake/core/sandbox/modules/try.lua
index b0b940be2..cff830098 100644
--- a/xmake/core/sandbox/modules/try.lua
+++ b/xmake/core/sandbox/modules/try.lua
@@ -118,23 +118,24 @@ function sandbox_try.try(block)
local funcs = table.join(block[2] or {}, block[3] or {})
-- try to call it
- local ok, errors_or_r1, r2, r3, r4, r5, r6 = utils.trycall(try, sandbox_try._traceback)
+ local results = table.pack(utils.trycall(try, sandbox_try._traceback))
+ local ok = results[1]
if not ok then
-- run the catch function
if funcs and funcs.catch then
- funcs.catch(errors_or_r1)
+ funcs.catch(results[2])
end
end
-- run the finally function
if funcs and funcs.finally then
- funcs.finally(ok, errors_or_r1, r2, r3, r4, r5, r6)
+ funcs.finally(ok, table.unpack(results, 2, results.n))
end
-- ok?
if ok then
- return errors_or_r1, r2, r3, r4, r5, r6
+ return table.unpack(results, 2, results.n)
end
end