diff options
author | ubq323 <ubq323@ubq323.website> | 2025-06-04 15:34:37 +0100 |
---|---|---|
committer | ubq323 <ubq323@ubq323.website> | 2025-06-04 15:34:37 +0100 |
commit | 464255a53558e9b2466b76e37432cafe8e7894c6 (patch) | |
tree | 5e08793f1ce4f9898ecdcc322b09c3567bd92e6d | |
parent | 84d7a078816cc1d7f62ff22f719e4769cf1312b1 (diff) |
add pairs_except
-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 |