Diff

util/array.lua @ 1027:fe2e3d3dba6a

util.array: Add array.collect() to collect results from iterators into an array, and use module() to correctly set the module name
author Matthew Wild <mwild1@gmail.com>
date Wed, 22 Apr 2009 17:46:17 +0100
parent 922:0e45234360cd
child 1371:9e45bdf55353
line wrap: on
line diff
--- 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;