From 0783aa7d6de42ea14b2da12f1bfdcd0711fb7f99 Mon Sep 17 00:00:00 2001 From: ruki Date: Thu, 1 Sep 2016 14:00:04 +0800 Subject: fix pairs filter bug --- xmake/core/sandbox/modules/ipairs.lua | 5 ++++- 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 -- cgit v1.3.1