Module:Dump/doc

This module can dump a table by displaying its contents as text. It can also display formatted html text. That may help develop other modules.

An alternative is to use  but the result from this module is clearer and is close to valid Lua source.

Dump of a Wikidata entity
When working with Wikidata, it can be useful to examine a table representing an entity.

For example, Southern African Large Telescope is Q833639. That entity can be viewed as a Lua table by previewing:

To do that, edit your sandbox and replace its contents with the above line, then click Show preview. Module talk:Dump shows this example.

If wanted, the width of each indented column can be set, for example to two spaces or to use tab characters:

A property such as can also be displayed:

Dump of a table for another module
If there is a problem debugging a module, it can be helpful to use a sandbox copy of the module to display the contents of a table to confirm that it contains expected data. The following shows how a module can dump a table.

With the above code in Module:Example, the result could be displayed by previewing:

The module contains a complex table for testing. The table can be displayed by previewing:

Dump of a formatted html string
A module can use mw.html to generate html. For testing, it may be useful to display the formatted result. The following shows how a module can create and dump html text.

With the above code in Module:Example, the result could be displayed by previewing:

The result is:

The  function in the code above could be modified to return the html table by replacing the last two lines with:

In that case, the result could be displayed by previewing the following (the  is needed if the text contains " "):

Dumping a navbox
Previewing the following examples in a sandbox may be useful to examine the results of a template, such as navbox, that generates html.

The dumphtml procedure only works reliably with valid html. In the following example, extra text is inserted at the start because the output from a subgroup (child) navbox starts with.

Dump of arguments
Special:ExpandTemplates is useful if there is a need to view the wikitext returned by a template or module. However, ExpandTemplates does not always show exactly what a module would receive. For example, the following template gives the output shown in ExpandTemplates, but the wikitext passed to a module would actually contains strip markers.
 * ExpandTemplates output, rearranged on multiple lines for clarity:
 * ExpandTemplates output, rearranged on multiple lines for clarity:

The  function shows what a module receives in its arguments.

The output follows. For clarity, it has been rearranged on multiple lines and each delete character has been replaced with.

Dump of parameters
A template might invoke the  function in the example above. Any parameters passed to the template or the module can be displayed for debugging. That would be to investigate an unexpected result in a page, for example, Albedo. To see what parameters are received by a module used in that article, edit the module and insert the following line at the start of the main function: Do not save the changes. Instead, enter the name of the article (for example, Albedo) in the box under "Preview page with this module", then click Show preview. Any parameters passed to the module in its frame and parent frame are displayed where the result from the module would normally appear.

Dump of structured data
A Lua program could execute to read a table of data from c:Data:Wikipedia statistics/data.tab.

An edit in a sandbox can be previewed to see what data the program would receive. To do that, preview the following wikitext:

The dump module accepts any text as the parameter and will apply special processing if the text is recognized. Structured data is identified as text ending with.

Global table _G
In Lua,  is a global variable which is a table holding information about all global variables. The  table can be displayed by previewing (both   and   work):

If wanted, the width of each indented column can be set, for example to 2 spaces: