How to dump a table to console?

The Solution to How to dump a table to console? is

I know this question has already been marked as answered, but let me plug my own library here. It's called inspect.lua, and you can find it here:

It's just a single file that you can require from any other file. It returns a function that transforms any Lua value into a human-readable string:

local inspect = require('inspect')

print(inspect({1,2,3})) -- {1, 2, 3}
-- {
--   a = 1
--   b = 2
-- }

It indents subtables properly, and handles "recursive tables" (tables that contain references to themselves) correctly, so it doesn't get into infinite loops. It sorts values in a sensible way. It also prints metatable information.


~ Answered on 2012-02-07 08:58:53

Most Viewed Questions: