# HG changeset patch
# User Matthew Wild <mwild1@gmail.com>
# Date 1365723889 -3600
# Node ID 2660407c3b736203d0f3b82ba4b15dbf8ab4b44c
# Parent  e3b9dc9dd9402d9b80b1ff285bb34dd0a5da08fe
util.iterators: Add ripairs() (ipairs() in reverse) (thanks Maranda)

diff -r e3b9dc9dd940 -r 2660407c3b73 util/iterators.lua
--- a/util/iterators.lua	Fri Apr 12 00:31:05 2013 +0100
+++ b/util/iterators.lua	Fri Apr 12 00:44:49 2013 +0100
@@ -122,6 +122,11 @@
 	--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