mirror of
https://github.com/pkulchenko/serpent.git
synced 2024-11-21 23:24:24 +00:00
Added keyignore
option for the serializer.
This commit is contained in:
parent
2d845adb49
commit
545c8fc8a6
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user