Module:Dump/doc: Difference between revisions
bold needed |
most usage details |
||
Line 1: | Line 1: | ||
This module can dump a table by displaying its contents as text. That may help develop other modules. |
|||
'''See [[Module talk:Dump]] for an example which displays the Lua table for a Wikidata entity.''' |
|||
An alternative is to use <code>mw.dumpObject()</code> 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 [[d:Q833639]]. That entity can be viewed as a Lua table by previewing: |
|||
:<code><nowiki>{{#invoke:dump|wikidata|Q833639}}</nowiki></code> |
|||
To do that, edit [[Special:MyPage/sandbox|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 2 spaces: |
|||
:<code><nowiki>{{#invoke:dump|wikidata|Q833639|indent=2}}</nowiki></code> |
|||
== Complex table example == |
|||
The module contains a complex table for testing. The table can be displayed by previewing: |
|||
:<code><nowiki>{{#invoke:dump|testcase}}</nowiki></code> |
|||
== Global table _G == |
|||
In Lua, <code>_G</code> is a global variable which is a table holding information about all global variables. The <code>_G</code> table can be displayed by previewing (both <code>G</code> and <code>_G</code> work): |
|||
:<code><nowiki>{{#invoke:dump|testcase|G}}</nowiki></code> |
|||
If wanted, the width of each indented column can be set, for example to 2 spaces: |
|||
:<code><nowiki>{{#invoke:dump|testcase|G|indent=2}}</nowiki></code> |
Revision as of 02:50, 24 May 2016
This module can dump a table by displaying its contents as text. That may help develop other modules.
An alternative is to use mw.dumpObject()
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 d:Q833639. That entity can be viewed as a Lua table by previewing:
{{#invoke:dump|wikidata|Q833639}}
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 2 spaces:
{{#invoke:dump|wikidata|Q833639|indent=2}}
Complex table example
The module contains a complex table for testing. The table can be displayed by previewing:
{{#invoke:dump|testcase}}
Global table _G
In Lua, _G
is a global variable which is a table holding information about all global variables. The _G
table can be displayed by previewing (both G
and _G
work):
{{#invoke:dump|testcase|G}}
If wanted, the width of each indented column can be set, for example to 2 spaces:
{{#invoke:dump|testcase|G|indent=2}}