From 532d3ba7156e0e614bceef4f8477da878e4340b5 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Tue, 22 May 2012 14:31:19 +0100 Subject: util.multitable: Some fixes for iter()... always match against query, and pass value after path results --- util/multitable.lua | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/util/multitable.lua b/util/multitable.lua index 299eecb1..dbf34d28 100644 --- a/util/multitable.lua +++ b/util/multitable.lua @@ -144,18 +144,19 @@ function iter(self, ...) 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 -- cgit v1.2.3