mirror of
https://github.com/pkulchenko/serpent.git
synced 2024-11-21 23:24:24 +00:00
Added level
to the parameters of the custom function (closes #25).
This commit is contained in:
parent
d304d81c09
commit
049e951ffb
@ -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):
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user