From Minetest Developer Wiki
Jump to navigation Jump to search


<source> dump(obj) dump(obj, indent) </source>


Helper function which dumps a human-readable version of a value. If the value is simple and well-formed, this also produces syntax which could be used directly in Lua source code.


  • obj — The table or other value to print.
  • indent — The indent field specifies a indentation string, it defaults to a tab. Use the empty string to disable indentation.

For tables this performs a recursive deep traversal. Loops (such as the table containing a reference to itself) are detected, keeping the function from looping infinitely. Values that have already been seen are printed as <circular reference>.

For values that cannot be readily printed in Lua syntax, another placeholder such as <userdata> or <function> is printed.

Example 1

<source> local a = {1, 2, 3, message = "hello"} a.a = a print(dump(a)) </source>


<source> {[1] = 1, [2] = 2, [3] = 3, ["message"] = "Hello", ["a"] = <circular reference>} </source>

Example 2

<source> local b = minetest.get_connected_players(); b.f = function() end print(dump(b)) </source>


<source> {[1] = <userdata>, ["f"] = <function>} </source>