aboutsummaryrefslogtreecommitdiffstats
path: root/util
diff options
context:
space:
mode:
authorWaqas Hussain <waqas20@gmail.com>2008-12-05 05:24:10 +0500
committerWaqas Hussain <waqas20@gmail.com>2008-12-05 05:24:10 +0500
commitbd000cf50917ec7570bf70eeda38c259e70a923e (patch)
treeea7a27ffdcc36aea891beb73f777bc9b39d92922 /util
parent15e7a1b4e77742aa48485066dd9b3bf05be23909 (diff)
downloadprosody-bd000cf50917ec7570bf70eeda38c259e70a923e.tar.gz
prosody-bd000cf50917ec7570bf70eeda38c259e70a923e.zip
MultiTable: Remove all empty sub-tables when elements are removed
Diffstat (limited to 'util')
-rw-r--r--util/multitable.lua12
1 files changed, 11 insertions, 1 deletions
diff --git a/util/multitable.lua b/util/multitable.lua
index f586330e..a3bfe946 100644
--- a/util/multitable.lua
+++ b/util/multitable.lua
@@ -22,6 +22,7 @@
local select = select;
local t_insert = table.insert;
local pairs = pairs;
+local next = next;
module "multitable"
@@ -55,10 +56,19 @@ local function r(t, n, _end, ...)
end
local k = select(n, ...);
if k then
- r(t[k], n+1, _end, ...);
+ v = t[k];
+ if v then
+ r(v, n+1, _end, ...);
+ if not next(v) then
+ t[k] = nil;
+ end
+ end
else
for _,b in pairs(t) do
r(b, n+1, _end, ...);
+ if not next(b) then
+ t[_] = nil;
+ end
end
end
end