diff options
| -rw-r--r-- | xmake/core/sandbox/modules/ipairs.lua | 5 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/pairs.lua | 5 |
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 |
