Module tch.tableprint

A convenience function to prettyprint a table.

Load the module via require; it returns the prettyprint function. Then simply call it with a table argument. It will also work with non-table arguments.

It uses the standard print function to output everything. If you want to use a different output function the simplest solution is to reassign the global print function to your logging function, then load this module and restore it afterwards.

By default the output function is invoked with one string argument that contains newlines. This ensures a readable output with the standard print function and the override used in the nginx Lua module. If you use a different output function that doesn't cope well with these newlines (syslog for example) then you can set the environment variable TABLEPRINT\NO\NEWLINES. In that case the output function is called for every line in the output.

Warning: the prettyprinter doesn't check for loops in a table!

Usage:

    -- Use a custom print function, namely log(),
    -- by temporarily changing the global print() function.
    local _print = print
    print = log
    local tprint = require("tch.tableprint")
    print = _print  -- restore print()
    local t = { some = "table", 4, 3 }
    tprint(t)
    tprint("some string")  -- also works
    tprint(43)  -- also works
    tprint(true)  -- again, this works as well
    


generated by LDoc 1.4.5 Last updated 2017-05-04 22:24:31