Software / code / prosody
Comparison
util/multitable.lua @ 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 |
| parent | 4895:36df30395c44 |
| child | 5776:bd0ff8ae98a8 |
comparison
equal
deleted
inserted
replaced
| 4900:d885ca14362d | 4901:05ea6c1ae393 |
|---|---|
| 142 return; -- The end | 142 return; -- The end |
| 143 else | 143 else |
| 144 keys[depth] = key; | 144 keys[depth] = key; |
| 145 end | 145 end |
| 146 local value = stack[depth][key]; | 146 local value = stack[depth][key]; |
| 147 if depth == maxdepth then -- Result | 147 if query[depth] == nil or key == query[depth] then |
| 148 local result = {}; -- Collect keys forming path to result | 148 if depth == maxdepth then -- Result |
| 149 for i = 1, depth do | 149 local result = {}; -- Collect keys forming path to result |
| 150 result[i] = keys[i]; | 150 for i = 1, depth do |
| 151 result[i] = keys[i]; | |
| 152 end | |
| 153 result[depth+1] = value; | |
| 154 return unpack(result, 1, depth+1); | |
| 155 elseif type(value) == "table" then | |
| 156 t_insert(stack, value); -- Descend | |
| 151 end | 157 end |
| 152 return unpack(result, 1, depth); | |
| 153 else | |
| 154 if (query[depth] == nil or key == query[depth]) and type(value) == "table" then -- Descend | |
| 155 t_insert(stack, value); | |
| 156 end | |
| 157 return it(self); | |
| 158 end | 158 end |
| 159 return it(self); | |
| 159 end; | 160 end; |
| 160 return it, self; | 161 return it, self; |
| 161 end | 162 end |
| 162 | 163 |
| 163 function new() | 164 function new() |