diff options
author | Tobias Markmann <tm@ayena.de> | 2009-03-03 17:48:04 +0100 |
---|---|---|
committer | Tobias Markmann <tm@ayena.de> | 2009-03-03 17:48:04 +0100 |
commit | 7a7a89844a038b071f02fd1af309ba9ebbcda7de (patch) | |
tree | 73946c977be10a965d59de85b3ce6ba3743bc771 /util/multitable.lua | |
parent | 3d1e7adbbc0afb8395f02ecd42fe3c38ce6a8d36 (diff) | |
parent | b6b9906c3c653935b55ad79ad4a2c41118f0a0e3 (diff) | |
download | prosody-7a7a89844a038b071f02fd1af309ba9ebbcda7de.tar.gz prosody-7a7a89844a038b071f02fd1af309ba9ebbcda7de.zip |
Merged with main tip.
Diffstat (limited to 'util/multitable.lua')
-rw-r--r-- | util/multitable.lua | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/util/multitable.lua b/util/multitable.lua index e5e87521..397f9ebe 100644 --- a/util/multitable.lua +++ b/util/multitable.lua @@ -82,6 +82,53 @@ local function remove(self, ...) end +local function s(t, n, results, _end, ...) + if t == nil then return; end + local k = select(n, ...); + if n == _end then + if k == nil then + for _, v in pairs(t) do + t_insert(results, v); + end + else + t_insert(results, t[k]); + end + return; + end + if k then + v = t[k]; + if v then + s(v, n+1, results, _end, ...); + end + else + for _,b in pairs(t) do + s(b, n+1, results, _end, ...); + end + end +end + +-- Search for keys, nil == wildcard +local function search(self, ...) + local _end = select('#', ...); + for n = _end,1 do + if select(n, ...) then _end = n; break; end + end + local results = {}; + s(self.data, 1, results, _end, ...); + return results; +end + +-- Append results to an existing list +local function search_add(self, results, ...) + if not results then results = {}; end + local _end = select('#', ...); + for n = _end,1 do + if select(n, ...) then _end = n; break; end + end + s(self.data, 1, results, _end, ...); + return results; +end + function new() return { data = {}; @@ -89,6 +136,8 @@ function new() add = add; set = set; remove = remove; + search = search; + search_add = search_add; }; end |