From bb738263106f1c1eb0c91e094f5043c37447a18b Mon Sep 17 00:00:00 2001 From: Paul Kulchenko Date: Tue, 8 Jan 2013 10:09:12 -0800 Subject: [PATCH] Renamed `ignore` option to `valignore` for consistency. --- README.md | 26 +++++++++++++++----------- misc/serpent-0.21-1.rockspec | 25 +++++++++++++++++++++++++ src/serpent.lua | 4 ++-- t/test.lua | 6 +++--- 4 files changed, 45 insertions(+), 16 deletions(-) create mode 100644 misc/serpent-0.21-1.rockspec diff --git a/README.md b/README.md index 23afd9e..a233f60 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/misc/serpent-0.21-1.rockspec b/misc/serpent-0.21-1.rockspec new file mode 100644 index 0000000..851a51c --- /dev/null +++ b/misc/serpent-0.21-1.rockspec @@ -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 ", + license = "MIT", +} + +dependencies = { + "lua >= 5.1", +} + +build = { + type = "builtin", + modules = { + ["serpent"] = "src/serpent.lua", + }, + copy_directories = { "t" }, +} diff --git a/src/serpent.lua b/src/serpent.lua index 5f4c9d0..e005e5d 100644 --- a/src/serpent.lua +++ b/src/serpent.lua @@ -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 diff --git a/t/test.lua b/t/test.lua index 5f3a41f..46afb15 100644 --- a/t/test.lua +++ b/t/test.lua @@ -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))