Wed, 22 Apr 2009 17:46:17 +0100
util.array: Add array.collect() to collect results from iterators into an array, and use module() to correctly set the module name
util/array.lua | file | annotate | diff | comparison | revisions |
--- a/util/array.lua Tue Apr 21 22:05:21 2009 +0100 +++ b/util/array.lua Wed Apr 22 17:46:17 2009 +0100 @@ -52,4 +52,17 @@ 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;