diff options
author | Philipp Gesang <phg42.2a@gmail.com> | 2014-07-26 12:46:53 +0200 |
---|---|---|
committer | Philipp Gesang <phg42.2a@gmail.com> | 2014-07-26 12:46:53 +0200 |
commit | f60e809b87c6d9b0ea87ceeb54507d486f2934eb (patch) | |
tree | 9fa52ea13b5e05d2c4a8ce8c81ada454bbf7c470 /lualibs-table.lua | |
parent | cdd478fce0ba30e0a2f7af7604b05bb34e392a88 (diff) | |
download | lualibs-f60e809b87c6d9b0ea87ceeb54507d486f2934eb.tar.gz |
sync with Context as of 2014-07-26
Diffstat (limited to 'lualibs-table.lua')
-rw-r--r-- | lualibs-table.lua | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/lualibs-table.lua b/lualibs-table.lua index ca067fb..e642106 100644 --- a/lualibs-table.lua +++ b/lualibs-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) |