Module pl.pretty
Pretty-printing Lua tables.
Functions
read (s) | read a string representation of a Lua table. |
write (tbl, space, not_clever) | Create a string representation of a Lua table. |
dump (t, fname) | Dump a Lua table out to a file or stdout. |
Functions
- read (s)
-
read a string representation of a Lua table.
Uses loadstring, but tries to be cautious about loading arbitrary code!
It is expecting a string of the form '{...}', with perhaps some whitespace
before or after the curly braces. An empty environment is used, and
any occurance of the keyword 'function' will be considered a problem.
Parameters:
s
: {string} string of the form '{...}', with perhaps some whitespace before or after the curly braces.
- write (tbl, space, not_clever)
-
Create a string representation of a Lua table.
This function never fails, but may complain by returning an
extra value. Normally puts out one item per line, using
the provided indent; set the second parameter to '' if
you want output on one line.
Parameters:
tbl
: {table} Table to serialize to a string.space
: {string} (optional) The indent to use. Defaults to two spaces.not_clever
: {bool} (optional) Use for plain output, e.g {['key']=1}. Defaults to false.
Returns:
- a string
- a possible error message
- dump (t, fname)
-
Dump a Lua table out to a file or stdout.
Parameters:
t
: {table} The table to write to a file or stdout.fname
: {string} (optional) File name to write too. Defaults to writing to stdout.