summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2016-09-01 14:00:04 +0800
committerruki <[email protected]>2016-09-01 14:00:04 +0800
commit0783aa7d6de42ea14b2da12f1bfdcd0711fb7f99 (patch)
treecf9d25283da3e2a1f6b47903c44be9403edac41a
parent98041add2635b07c13f6016cf2c2f6e8aa81e8db (diff)
fix pairs filter bug
-rw-r--r--xmake/core/sandbox/modules/ipairs.lua5
-rw-r--r--xmake/core/sandbox/modules/pairs.lua5
2 files changed, 8 insertions, 2 deletions
diff --git a/xmake/core/sandbox/modules/ipairs.lua b/xmake/core/sandbox/modules/ipairs.lua
index 7538b8e4f..72ae63f24 100644
--- a/xmake/core/sandbox/modules/ipairs.lua
+++ b/xmake/core/sandbox/modules/ipairs.lua
@@ -44,13 +44,16 @@ local table = require("base/table")
-- @endcode
function sandbox_ipairs(t, filter, ...)
+ -- has filter?
+ local has_filter = type(filter) == "function"
+
-- init iterator
local args = {...}
local iter = function (t, i)
i = i + 1
local v = t[i]
if v then
- if filter ~= nil then
+ if has_filter then
v = filter(v, unpack(args))
end
return i, v
diff --git a/xmake/core/sandbox/modules/pairs.lua b/xmake/core/sandbox/modules/pairs.lua
index d8adb98ef..17e6fd952 100644
--- a/xmake/core/sandbox/modules/pairs.lua
+++ b/xmake/core/sandbox/modules/pairs.lua
@@ -47,11 +47,14 @@ local table = require("base/table")
--
function sandbox_pairs(t, filter, ...)
+ -- has filter?
+ local has_filter = type(filter) == "function"
+
-- init iterator
local args = {...}
local iter = function (t, i)
local k, v = next(t, i)
- if v and filter ~= nil then
+ if v and has_filter then
v = filter(v, unpack(args))
end
return k, v