diff options
author | Matthew Wild <mwild1@gmail.com> | 2009-04-22 17:46:17 +0100 |
---|---|---|
committer | Matthew Wild <mwild1@gmail.com> | 2009-04-22 17:46:17 +0100 |
commit | 1ce9466289eaa1843e503b951078fc4432ce96c4 (patch) | |
tree | 70be0b5bfafc7608dd2dab2b7908c1d31fd77566 /util | |
parent | 995524ab1700f21a26c84f14e4d239f0f629a001 (diff) | |
download | prosody-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
Diffstat (limited to 'util')
-rw-r--r-- | util/array.lua | 15 |
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; |