diff options
author | Matthew Wild <mwild1@gmail.com> | 2013-04-12 00:44:49 +0100 |
---|---|---|
committer | Matthew Wild <mwild1@gmail.com> | 2013-04-12 00:44:49 +0100 |
commit | 8d41687872e81d0152fa5d941db022fdaeb60f90 (patch) | |
tree | dcc1a5dc06312b3b80f84e8b40b3e461c3a4005b /util | |
parent | ef9b86202eb5ed42cefe788b01b1f09895d6899e (diff) | |
download | prosody-8d41687872e81d0152fa5d941db022fdaeb60f90.tar.gz prosody-8d41687872e81d0152fa5d941db022fdaeb60f90.zip |
util.iterators: Add ripairs() (ipairs() in reverse) (thanks Maranda)
Diffstat (limited to 'util')
-rw-r--r-- | util/iterators.lua | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/util/iterators.lua b/util/iterators.lua index fb89f4a5..1f6aacb8 100644 --- a/util/iterators.lua +++ b/util/iterators.lua @@ -122,6 +122,11 @@ function it.tail(n, f, s, var) --return reverse(head(n, reverse(f, s, var))); end +local function _ripairs_iter(t, key) if key > 1 then return key-1, t[key-1]; end end +function it.ripairs(t) + return _ripairs_iter, t, #t+1; +end + local function _range_iter(max, curr) if curr < max then return curr + 1; end end function it.range(x, y) if not y then x, y = 1, x; end -- Default to 1..x if y not given |