Remove warning of already-loaded modules at startup
[prosody.git] / util / multitable.lua
index a3bfe946314daf4512c9fc442227c5061c745dc1..414f6cb532d2de267c5c0edcd4411731dfed99ae 100644 (file)
@@ -1,4 +1,4 @@
--- Prosody IM v0.1
+-- Prosody IM v0.2
 -- Copyright (C) 2008 Matthew Wild
 -- Copyright (C) 2008 Waqas Hussain
 -- 
@@ -44,17 +44,28 @@ local function add(self, ...)
                if not tab then tab = {}; t[key] = tab; end
                t = tab;
        end
-       t_insert(t, select(count, ...));
+       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