diff options
-rw-r--r-- | pairs_except.lua | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/pairs_except.lua b/pairs_except.lua new file mode 100644 index 0000000..1f808ec --- /dev/null +++ b/pairs_except.lua @@ -0,0 +1,8 @@ +-- pairs_except(t, k) is the same as pairs(t), but with t[k] skipped +return function(t,exception) + if exception == nil then return pairs(t) end + local function next_except(t,k) + local k2,v2 = next(t,k) + if k2 == exception then k2,v2 = next(t,k2) end + return k2,v2 end + return next_except, t, nil end |