aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2009-04-22 17:46:17 +0100
committerMatthew Wild <mwild1@gmail.com>2009-04-22 17:46:17 +0100
commit1ce9466289eaa1843e503b951078fc4432ce96c4 (patch)
tree70be0b5bfafc7608dd2dab2b7908c1d31fd77566
parent995524ab1700f21a26c84f14e4d239f0f629a001 (diff)
downloadprosody-1ce9466289eaa1843e503b951078fc4432ce96c4.tar.gz
prosody-1ce9466289eaa1843e503b951078fc4432ce96c4.zip
util.array: Add array.collect() to collect results from iterators into an array, and use module() to correctly set the module name
-rw-r--r--util/array.lua15
1 files changed, 14 insertions, 1 deletions
diff --git a/util/array.lua b/util/array.lua
index 9e99a3ec..072b24a7 100644
--- a/util/array.lua
+++ b/util/array.lua
@@ -52,4 +52,17 @@ function array:reverse()
end
end
-_G.array = array
+function array.collect(f, s, var)
+ local t, var = {};
+ while true do
+ var = f(s, var);
+ if var == nil then break; end
+ table.insert(t, var);
+ end
+ return setmetatable(t, array_mt);
+end
+
+_G.array = array;
+module("array");
+
+return array;