Renamed ignore option to valignore for consistency.

This commit is contained in:
Paul Kulchenko 2013-01-08 10:09:12 -08:00
parent 87b5d0f376
commit bb73826310
4 changed files with 45 additions and 16 deletions

View File

@ -59,7 +59,7 @@ internal function, but set different options by default:
* nocode (true/False) -- disable bytecode serialization for easy comparison
* nohuge (true/False) -- disable checking numbers against undefined and huge values
* maxlevel (number) -- specify max level up to which to expand nested tables
* ignore (table) -- allows to specify a list of values to ignore (as keys)
* 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)
* valtypeignore (table) -- allows to specify a list of value *types* to ignore (as keys)
* custom (function) -- provide custom output for tables
@ -68,7 +68,7 @@ These options can be provided as a second parameter to Serpent functions.
```lua
block(a, {fatal = true})
line(a, {nocode = true, ignore = {[arrayToIgnore] = true}})
line(a, {nocode = true, valignore = {[arrayToIgnore] = true}})
function todiff(a) return dump(a, {nocode = true, indent = ' '}) end
```
@ -130,44 +130,48 @@ See LICENSE file.
## History
Nov 16 2012 v0.19
### v0.21 (Jan 08 2013)
- Added `keyallow` and `valtypeignore` options (thanks to Jess Telford).
- Renamed `ignore` to `valignore`.
### v0.19 (Nov 16 2012)
- Fixed an issue with serializing shared functions as keys.
- Added serialization of metatables using __tostring (when present).
Sep 13 2012 v0.18
### v0.18 (Sep 13 2012)
- Fixed an issue with serializing data structures with circular references that require emitting temporary variables.
- Fixed an issue with serializing keys pointing to shared references.
- Improved overall serialization logic to inline values when possible.
Sep 12 2012 v0.17
### v0.17 (Sep 12 2012)
- Fixed an issue with serializing userdata that doesn't provide tostring().
Aug 28 2012 v0.16
### v0.16 (Aug 28 2012)
- Removed confusing --[[err]] comment from serialized results.
- Added a short comment to serialized functions when the body is skipped.
Jun 17 2012 v0.15
### v0.15 (Jun 17 2012)
- Added `ignore` option to allow ignoring table values.
- Added `comment=num` option to set the max level up to which add comments.
- Changed all comments (except math.huge) to be controlled by `comment` option.
Jun 13 2012 v0.14
### v0.14 (Jun 13 2012)
- Fixed an issue with string keys with numeric values `['3']` getting mixed
with real numeric keys (only with `sortkeys` option set to `true`).
- Fixed an issue with negative and real value numeric keys being misplaced.
Jun 13 2012 v0.13
### v0.13 (Jun 13 2012)
- Added `maxlevel` option.
- Fixed key sorting such that `true` and `'true'` are always sorted in
the same order (for a more stable output).
- Removed addresses from names of temporary variables (for stable output).
Jun 12 2012 v0.12
### v0.12 (Jun 12 2012)
- Added options to configure serialization process.
- Added `goto` to the list of keywords for Lua 5.2.
- Changed interface to dump/line/block methods.
- Changed `math.huge` to 1/0 for better portability.
- Replaced \010 with \n for better readability.
Jun 03 2012 v0.10
### v0.10 (Jun 03 2012)
- First public release.

View File

@ -0,0 +1,25 @@
package = "serpent"
version = "0.21-1"
source = {
url = "git://github.com/pkulchenko/serpent.git",
tag = "0.21"
}
description = {
summary = "Lua serializer and pretty printer",
homepage = "https://github.com/pkulchenko/serpent",
maintainer = "Paul Kulchenko <paul@kulchenko.com>",
license = "MIT",
}
dependencies = {
"lua >= 5.1",
}
build = {
type = "builtin",
modules = {
["serpent"] = "src/serpent.lua",
},
copy_directories = { "t" },
}

View File

@ -1,4 +1,4 @@
local n, v = "serpent", 0.20 -- (C) 2012 Paul Kulchenko; MIT License
local n, v = "serpent", 0.21 -- (C) 2012 Paul Kulchenko; MIT License
local c, d = "Paul Kulchenko", "Serializer and pretty printer of Lua data types"
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}
@ -66,7 +66,7 @@ local function s(t, opts)
if opts.sortkeys then alphanumsort(o, opts.sortkeys) end
for n, key in ipairs(o) do
local value, ktype, plainindex = t[key], type(key), n <= maxn and not sparse
if opts.ignore and opts.ignore[value] -- skip ignored values; do nothing
if opts.valignore and opts.valignore[value] -- skip ignored values; do nothing
or opts.keyallow and not opts.keyallow[key]
or opts.valtypeignore and opts.valtypeignore[type(value)] -- skipping ignored value types
or sparse and value == nil then -- skipping nils; do nothing

View File

@ -39,9 +39,9 @@ a[1].moreyet = {[{__more = a[1]}] = "moreyet"}
a[2] = {}
a[a[2]] = {more = a[2]}
print("pretty: " .. serpent.block(a, {ignore = {[d] = true}}) .. "\n")
print("line: " .. serpent.line(a, {ignore = {[d] = true}}) .. "\n")
local str = serpent.dump(a, {ignore = {[d] = true}})
print("pretty: " .. serpent.block(a, {valignore = {[d] = true}}) .. "\n")
print("line: " .. serpent.line(a, {valignore = {[d] = true}}) .. "\n")
local str = serpent.dump(a, {valignore = {[d] = true}})
print("full: " .. str .. "\n")
local fun, err = assert(loadstring(str))