dump

From Minetest Developer Wiki
Jump to: navigation, search

Contents

Syntax

dump(obj)
dump(obj, indent)

Description

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.

Parameters:

  • 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

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

Result:

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

Example 2

local b = minetest.get_connected_players();
b.f = function() end
print(dump(b))

Result:

{[1] = <userdata>, ["f"] = <function>}
Personal tools
Namespaces

Variants
Actions
Navigation
API
Toolbox