User:Ganaram inukshuk/Provisional style guide for Lua: Difference between revisions
No edit summary |
→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" | '''Preferred'''<syntaxhighlight lang="wikitext">{| class="wikitable" | ||
|+ Caption text | |+ Caption text | ||
|- | |- | ||
| Line 96: | Line 96: | ||
| ee | | ee | ||
| ff | | ff | ||
|} | |}</syntaxhighlight>'''Avoid'''<syntaxhighlight lang="wikitext"> | ||
{| class="wikitable" | |||
|+ Caption text | |+ Caption text | ||
|- | |- | ||
| Line 105: | Line 105: | ||
|- | |- | ||
| dd || ee || ff | | dd || ee || ff | ||
|} | |} | ||
</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> | ||