Changeset

4901:05ea6c1ae393

util.multitable: Some fixes for iter()... always match against query, and pass value after path results
author Matthew Wild <mwild1@gmail.com>
date Tue, 22 May 2012 14:31:19 +0100
parents 4900:d885ca14362d
children 4902:a7c799a7a34b
files util/multitable.lua
diffstat 1 files changed, 11 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/util/multitable.lua	Sat May 19 21:57:40 2012 +0100
+++ b/util/multitable.lua	Tue May 22 14:31:19 2012 +0100
@@ -144,18 +144,19 @@
 			keys[depth] = key;
 		end
 		local value = stack[depth][key];
-		if depth == maxdepth then -- Result
-			local result = {}; -- Collect keys forming path to result
-			for i = 1, depth do
-				result[i] = keys[i];
+		if query[depth] == nil or key == query[depth] then
+			if depth == maxdepth then -- Result
+				local result = {}; -- Collect keys forming path to result
+				for i = 1, depth do
+					result[i] = keys[i];
+				end
+				result[depth+1] = value;
+				return unpack(result, 1, depth+1);
+			elseif type(value) == "table" then
+				t_insert(stack, value); -- Descend
 			end
-			return unpack(result, 1, depth);
-		else
-			if (query[depth] == nil or key == query[depth]) and type(value) == "table" then -- Descend
-				t_insert(stack, value);
-			end
-			return it(self);
 		end
+		return it(self);
 	end;
 	return it, self;
 end