Added keyignore option for the serializer.

This commit is contained in:
Paul Kulchenko 2015-07-24 21:40:43 -07:00
parent 2d845adb49
commit 545c8fc8a6
2 changed files with 3 additions and 1 deletions

View File

@ -76,6 +76,7 @@ Similar to `pcall` and `loadstring` calls, `load` returns status as the first va
* numformat (string; "%.17g") -- specify format for numeric values (shortest possible round-trippable double)
* valignore (table) -- allows to specify a list of values to ignore (as keys)
* keyallow (table) -- allows to specify the list of keys to be serialized. Any keys not in this list are not included in final output (as keys)
* keyignore (table) -- allows to specity the list of keys to ignore in serialization.
* valtypeignore (table) -- allows to specify a list of value *types* to ignore (as keys)
* custom (function) -- provide custom output for tables
* name (string) -- name; triggers full serialization with self-ref section

View File

@ -1,4 +1,4 @@
local n, v = "serpent", 0.284 -- (C) 2012-15 Paul Kulchenko; MIT License
local n, v = "serpent", 0.285 -- (C) 2012-15 Paul Kulchenko; MIT License
local c, d = "Paul Kulchenko", "Lua serializer and pretty printer"
local snum = {[tostring(1/0)]='1/0 --[[math.huge]]',[tostring(-1/0)]='-1/0 --[[-math.huge]]',[tostring(0/0)]='0/0'}
local badtype = {thread = true, userdata = true, cdata = true}
@ -70,6 +70,7 @@ local function s(t, opts)
local value, ktype, plainindex = t[key], type(key), n <= maxn and not sparse
if opts.valignore and opts.valignore[value] -- skip ignored values; do nothing
or opts.keyallow and not opts.keyallow[key]
or opts.keyignore and opts.keyignore[key]
or opts.valtypeignore and opts.valtypeignore[type(value)] -- skipping ignored value types
or sparse and value == nil then -- skipping nils; do nothing
elseif ktype == 'table' or ktype == 'function' or badtype[ktype] then