X-Git-Url: https://git.enpas.org/?a=blobdiff_plain;f=util%2Fmultitable.lua;h=caf25118e3f622ecd66dbea06b5c24de7abba968;hb=95dfe4b0aaaf26ee4651c09eb9757c56210a135a;hp=299eecb13f73b15b1ab25881bd72a798239b6f03;hpb=227896bcc1fbb2b0a4ebf82830786d461576ab44;p=prosody.git diff --git a/util/multitable.lua b/util/multitable.lua index 299eecb1..caf25118 100644 --- a/util/multitable.lua +++ b/util/multitable.lua @@ -1,7 +1,7 @@ -- Prosody IM -- Copyright (C) 2008-2010 Matthew Wild -- Copyright (C) 2008-2010 Waqas Hussain --- +-- -- This project is MIT/X11 licensed. Please see the -- COPYING file in the source package for more information. -- @@ -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]; - 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); + 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 it(self); end + return it(self); end; return it, self; end