diff options
| author | ruki <[email protected]> | 2022-05-18 00:48:15 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2022-05-18 00:48:15 +0800 |
| commit | ed15fde870e6cdb8d82c55bdcc981d50752f66f4 (patch) | |
| tree | 514d58d143b644a5eb6a50e5d265f9dcb32fcb15 | |
| parent | 886ea9eeac7a3554b229c87de965d43791d5e6e5 (diff) | |
improve pairs
| -rw-r--r-- | xmake/core/sandbox/modules/ipairs.lua | 7 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/pairs.lua | 7 |
2 files changed, 8 insertions, 6 deletions
diff --git a/xmake/core/sandbox/modules/ipairs.lua b/xmake/core/sandbox/modules/ipairs.lua index 14616cea3..6df5d9e93 100644 --- a/xmake/core/sandbox/modules/ipairs.lua +++ b/xmake/core/sandbox/modules/ipairs.lua @@ -25,13 +25,14 @@ local table = require("base/table") function sandbox_ipairs(t) -- exists the custom ipairs? - if type(t) == "table" and t.ipairs then + local is_table = type(t) == "table" + if is_table and t.ipairs then return t:ipairs() end -- wrap table and return iterator - if t == nil then - t = {} + if not is_table then + t = t ~= nil and {t} or {} end return function (t, i) i = i + 1 diff --git a/xmake/core/sandbox/modules/pairs.lua b/xmake/core/sandbox/modules/pairs.lua index a1a5a5588..9494cd3b5 100644 --- a/xmake/core/sandbox/modules/pairs.lua +++ b/xmake/core/sandbox/modules/pairs.lua @@ -25,13 +25,14 @@ local table = require("base/table") function sandbox_pairs(t) -- exists the custom ipairs? - if type(t) == "table" and t.pairs then + local is_table = type(t) == "table" + if is_table and t.pairs then return t:pairs() end -- wrap table and return iterator - if t == nil then - t = {} + if not is_table then + t = t ~= nil and {t} or {} end return function (t, i) return next(t, i) |
