diff options
author | Waqas Hussain <waqas20@gmail.com> | 2008-12-27 08:27:26 +0500 |
---|---|---|
committer | Waqas Hussain <waqas20@gmail.com> | 2008-12-27 08:27:26 +0500 |
commit | f71a012a30710a334fefdd3b510de261fb98ff48 (patch) | |
tree | dfcf23ee54dcf1170595e1eca595eb13610620e7 /util/multitable.lua | |
parent | 6061bd797ccde732339153fa5296d3ae2686fa87 (diff) | |
download | prosody-f71a012a30710a334fefdd3b510de261fb98ff48.tar.gz prosody-f71a012a30710a334fefdd3b510de261fb98ff48.zip |
Added util.multitable.set
Diffstat (limited to 'util/multitable.lua')
-rw-r--r-- | util/multitable.lua | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/util/multitable.lua b/util/multitable.lua index ce38e04d..414f6cb5 100644 --- a/util/multitable.lua +++ b/util/multitable.lua @@ -47,14 +47,25 @@ local function add(self, ...) t_insert(t, (select(count, ...))); end +local function set(self, ...) + local t = self.data; + local count = select('#', ...); + for n = 1,count-2 do + local key = select(n, ...); + local tab = t[key]; + if not tab then tab = {}; t[key] = tab; end + t = tab; + end + t[(select(count-1, ...))] = (select(count, ...)); +end + local function r(t, n, _end, ...) if t == nil then return; end - if n > _end then - for key in pairs(t) do - t[key] = nil; - end - end local k = select(n, ...); + if n == _end then + t[k] = nil; + return; + end if k then v = t[k]; if v then @@ -87,6 +98,7 @@ function new() data = {}; get = get; add = add; + set = set; remove = remove; }; end |