projects
/
prosody.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
85c6fd1
)
util.iterators: Add ripairs() (ipairs() in reverse) (thanks Maranda)
author
Matthew Wild
<mwild1@gmail.com>
Thu, 11 Apr 2013 23:44:49 +0000
(
00:44
+0100)
committer
Matthew Wild
<mwild1@gmail.com>
Thu, 11 Apr 2013 23:44:49 +0000
(
00:44
+0100)
util/iterators.lua
patch
|
blob
|
history
diff --git
a/util/iterators.lua
b/util/iterators.lua
index fb89f4a55b796db4fd91ff7ab4c4b90cab519920..1f6aacb81a4d36e77ba23429ff2001f6cdf14ad3 100644
(file)
--- 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