Added level to the parameters of the custom function (closes #25).

This commit is contained in:
Paul Kulchenko 2017-08-31 22:20:30 -07:00
parent d304d81c09
commit 049e951ffb
2 changed files with 5 additions and 4 deletions

View File

@ -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, * 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), * 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 * 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). * tail -- a closing table bracket `}` and associated indentation and newline (if any), and
* level -- the current level.
For example, the following call will apply For example, the following call will apply
`Foo{bar} notation to its output (used by Metalua to display ASTs): `Foo{bar} notation to its output (used by Metalua to display ASTs):

View File

@ -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 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 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} 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 head = indent and '{\n'..prefix..indent or '{'
local body = table.concat(out, ','..(indent and '\n'..prefix..indent or space)) local body = table.concat(out, ','..(indent and '\n'..prefix..indent or space))
local tail = indent and "\n"..prefix..'}' or '}' 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 elseif badtype[ttype] then
seen[t] = insref or spath seen[t] = insref or spath
return tag..globerr(t, level) return tag..globerr(t, level)