Module:debug/doc

E Victionario

This is the documentation page for Module:debug

Purpose[+/-]

This module is used to debug templates and other modules, and to help track down problems or incorrect usage.

dump[+/-]

dump(value)

Converts any value (except for functions) into a string representation. The string is formatted as Lua syntax, so you should be able to take the output of this function and insert it back into a Lua module. Tables are processed recursively. Tabs are converted into spaces.

highlight_dump[+/-]

highlight_dump(value)

Does the same as dump, except it adds Lua syntax highlighting, and tabs are preserved.

error[+/-]

{{#invoke:debug|error|message}}

This function is invoked from templates, and simply triggers a script error with a message. This is useful if you want to trigger a script error but don't have the time or knowledge to convert a template to Lua.

track[+/-]

track(key)

Convenience function which transcludes a tracking subtemplate. The key is a string or a list of strings: track("key") or track{ "key1", "key2", "key3", ... }.

Usually invocations of this functions should look like this: require('Module:debug').track(key). Loading this module on the spot instead of ahead of time may prevent unnecessary transclusion list overload.

highlight[+/-]

This function creates the equivalent of a <source> or <syntaxhighlight> tag using the frame:extensionTag() function from Scribunto. Depending on the arguments, it behaves in two different ways:

highlight(content, options)
Highlight the given content (which should be a string) using the table of options.
require("Module:debug").highlight('<span class="Latn" lang="en">word</span>', { lang = "html" }) -- generate syntax-highlighted HTML code
highlight(options)
Returns a highlighting function that uses the given table of options. This is useful when a given set of options are used multiple times in a module. The highlighting function receives a string as argument.
local highlight_HTML = require("Module:debug").highlight{ lang = "html" } -- generate syntax-highlighting function for HTML
highlight_HTML('<span class="Latn" lang="en">word</span>') -- generates syntax-highlighted HTML code

The function recognizes two fields in the table of options:

lang
Language or file format. (See the full list.) Defaults to "lua".
inline
Display the code inline, rather than as a block.