Template:Code:Lua/doc
Appearance
This is a documentation subpage for Template:Code:Lua It may contain usage information, categories and other content that is not part of the original template page. |
This is a template for writing Lua code examples. You can specify introductory text, code, output, and explanatory text. The Lua code is syntax highlighted using the SyntaxHighlight extension, and the output is formatted with <pre>...</pre>
tags, meaning that it uses a monospace font and whitespace is preserved.
Usage
[edit source]- Simple usage
{{Code:Lua | code = | output = }}
- All parameters
{{Code:Lua | before = | code = | output = | after = | border-color = | background-color = | output-color = | width = }}
Parameters
[edit source]before
- the introductory text. This comes before the code and the output.code
- the Lua code.output
- the output.after
- the explanatory text. This comes after the code and the output.border-color
- the hexadecimal color code for the border color, e.g.FF7777
. Do not include a # symbol, as this is added by default.background-color
- the hexadecimal color code for the background color, e.g.FFDDDD
. Do not include a # symbol, as this is added by default.output-color
- the hexadecimal color code for the output text color, e.g.FF0000
. Do not include a # symbol, as this is added by default.width
- an optional width, e.g. "500px".
All parameters are optional.
Note: using a pipe character |
in any of the parameters will break the template. This is because for the MediaWiki software, the pipe character signifies the start of a new parameter. To work around this problem you can use the code {{!}}
.
Examples
[edit source]All parameters
[edit source]{{Code:Lua | before = A hello world program. | code = print('Hello, world!') | output = Hello, world! | after = The <code>print</code> command prints text. }}
A hello world program.
print('Hello, world!')
Hello, world!
The
print
command prints text.Just code and output
[edit source]{{Code:Lua | code = print('Hello, world!') | output = Hello, world! }}
Just code
[edit source]{{Code:Lua | code = for i = 1, 10000 do print('Hello, world!\n') end }}
See also
[edit source]- Template:Code:Lua error, a version of this template with a red background, used for displaying erroneous code.
- Template:Code, an overview of the different code templates.
- Template:Code:Formatted, a version of this template generalised for any language.