From 049e951ffbcf1815beb918586f04e3aa39b40560 Mon Sep 17 00:00:00 2001 From: Paul Kulchenko Date: Thu, 31 Aug 2017 22:20:30 -0700 Subject: [PATCH] Added `level` to the parameters of the custom function (closes #25). --- README.md | 5 +++-- src/serpent.lua | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index b8e3f4b..890265b 100644 --- a/README.md +++ b/README.md @@ -132,8 +132,9 @@ customize the output. The formatter takes four values: * tag -- the name of the current element with '=' or an empty string in case of array index, * head -- an opening table bracket `{` and associated indentation and newline (if any), -* body -- table elements concatenated into a string using commas and indentation/newlines (if any), and -* tail -- a closing table bracket `}` and associated indentation and newline (if any). +* body -- table elements concatenated into a string using commas and indentation/newlines (if any), +* tail -- a closing table bracket `}` and associated indentation and newline (if any), and +* level -- the current level. For example, the following call will apply `Foo{bar} notation to its output (used by Metalua to display ASTs): diff --git a/src/serpent.lua b/src/serpent.lua index 297cec7..c5e862b 100644 --- a/src/serpent.lua +++ b/src/serpent.lua @@ -1,4 +1,4 @@ -local n, v = "serpent", 0.288 -- (C) 2012-17 Paul Kulchenko; MIT License +local n, v = "serpent", 0.289 -- (C) 2012-17 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} @@ -99,7 +99,7 @@ local function s(t, opts) local head = indent and '{\n'..prefix..indent or '{' local body = table.concat(out, ','..(indent and '\n'..prefix..indent or space)) local tail = indent and "\n"..prefix..'}' or '}' - return (custom and custom(tag,head,body,tail) or tag..head..body..tail)..comment(t, level) + return (custom and custom(tag,head,body,tail,level) or tag..head..body..tail)..comment(t, level) elseif badtype[ttype] then seen[t] = insref or spath return tag..globerr(t, level)