Software /
code /
prosody
Changeset
554:9a695724681d
MultiTable: Remove all empty sub-tables when elements are removed
author | Waqas Hussain <waqas20@gmail.com> |
---|---|
date | Fri, 05 Dec 2008 05:24:10 +0500 (2008-12-05) |
parents | 552:6db1f41e475a |
children | 555:1c29c0b22022 |
files | util/multitable.lua |
diffstat | 1 files changed, 11 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/util/multitable.lua Fri Dec 05 04:56:04 2008 +0500 +++ b/util/multitable.lua Fri Dec 05 05:24:10 2008 +0500 @@ -22,6 +22,7 @@ local select = select; local t_insert = table.insert; local pairs = pairs; +local next = next; module "multitable" @@ -55,10 +56,19 @@ 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