User:Ganaram inukshuk/Provisional style guide for Lua: Difference between revisions

Ganaram inukshuk (talk | contribs)
No edit summary
Ganaram inukshuk (talk | contribs)
→Specific conventions: add convention to possibly adopt
Line 82: Line 82:
Wikitables should be written with one line per cell instead of one line per row. This is for ease-of-reading when debugging the output of a module-generated table. Add a space between pipes/exclamation points and table entries to avoid accidentally adding new rows, such as when inputting negative numbers. Mediawiki tables generated using Lua code must follow this convention.
Wikitables should be written with one line per cell instead of one line per row. This is for ease-of-reading when debugging the output of a module-generated table. Add a space between pipes/exclamation points and table entries to avoid accidentally adding new rows, such as when inputting negative numbers. Mediawiki tables generated using Lua code must follow this convention.


'''Preferred'''<syntaxhighlight lang="wikitext"><nowiki>{| class="wikitable"
'''Preferred'''<syntaxhighlight lang="wikitext">{| class="wikitable"
|+ Caption text
|+ Caption text
|-
|-
Line 96: Line 96:
| ee
| ee
| ff
| ff
|}</nowiki></syntaxhighlight>'''Avoid'''<syntaxhighlight lang="wikitext">
|}</syntaxhighlight>'''Avoid'''<syntaxhighlight lang="wikitext">
<nowiki>{| class="wikitable"
{| class="wikitable"
|+ Caption text
|+ Caption text
|-
|-
Line 105: Line 105:
|-
|-
| dd || ee || ff
| dd || ee || ff
|}</nowiki>
|}


</syntaxhighlight>
=== Lua code that generates a table ===
'''Experimental; yet to be fully adopted'''
Brought up when trying to make example code; turns out, this is recommended practice for large tables: https://www.lua.org/pil/11.6.html<syntaxhighlight lang="lua">
    table.insert(lines, '{| class="wikitable"')
    table.insert(lines, '|+ Caption text')
    table.insert(lines, '|-')
    table.insert(lines, '! Header 1')
    table.insert(lines, '! Header 2')
    table.insert(lines, '! Header 3')
    table.insert(lines, '|-')
    table.insert(lines, '| aa')
    table.insert(lines, '| bb')
    table.insert(lines, '| cc')
    table.insert(lines, '|-')
    table.insert(lines, '| dd')
    table.insert(lines, '| ee')
    table.insert(lines, '| ff')
    table.insert(lines, '|}')
   
    return table.concat(lines, '\n')
</syntaxhighlight>
</syntaxhighlight>