summaryrefslogtreecommitdiff
path: root/tex/context/base/l-table.lua
diff options
context:
space:
mode:
authorHans Hagen <pragma@wxs.nl>2014-07-25 12:57:00 +0200
committerHans Hagen <pragma@wxs.nl>2014-07-25 12:57:00 +0200
commit552aceb88e5e5e77a9263144180139a6ac95646c (patch)
tree33053ce46dd12e14505d457f42f29486f16890eb /tex/context/base/l-table.lua
parente80c75029084c0e8a80286f78150b5a2e320e63c (diff)
downloadcontext-552aceb88e5e5e77a9263144180139a6ac95646c.tar.gz
beta 2014.07.25 12:57
Diffstat (limited to 'tex/context/base/l-table.lua')
-rw-r--r--tex/context/base/l-table.lua25
1 files changed, 18 insertions, 7 deletions
diff --git a/tex/context/base/l-table.lua b/tex/context/base/l-table.lua
index ca067fb1e..e642106cc 100644
--- a/tex/context/base/l-table.lua
+++ b/tex/context/base/l-table.lua
@@ -922,16 +922,27 @@ end
table.identical = identical
table.are_equal = are_equal
--- maybe also make a combined one
-
-function table.compact(t) -- remove empty tables, assumes subtables
- if t then
- for k, v in next, t do
- if not next(v) then -- no type checking
- t[k] = nil
+local function sparse(old,nest,keeptables)
+ local new = { }
+ for k, v in next, old do
+ if not (v == "" or v == false) then
+ if nest and type(v) == "table" then
+ v = sparse(v,nest)
+ if keeptables or next(v) then
+ new[k] = v
+ end
+ else
+ new[k] = v
end
end
end
+ return new
+end
+
+table.sparse = sparse
+
+function table.compact(t)
+ return sparse(t,true,true)
end
function table.contains(t, v)