From 733476db7b1b6094cc60196cd6f8cdc633e5694a Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Fri, 12 Apr 2013 00:44:49 +0100 Subject: util.iterators: Add ripairs() (ipairs() in reverse) (thanks Maranda) --- util/iterators.lua | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'util/iterators.lua') 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 -- cgit v1.2.3