Module:Yesno/doc: Difference between revisions

m
Adapt for this wiki
(Removed page from translation)
imported>FrozenPlum
m (Adapt for this wiki)
 
(4 intermediate revisions by 3 users not shown)
Line 1:
{{Documentation subpage}}
<noinclude><!--
<!-->{{#ifeq:{{SUBPAGENAME}}|doc||{{ Documentation subpage}}}}<!here -->
 
--><!--
--></noinclude>{{#switch:
| =
<includeonly>{{Languages|Module:Yesno/doc}}</includeonly>
<!-- Add categories where indicated at the bottom of this page and interwikis at Wikidata -->
{{Shared Template Warning}}
{{high-risk}}
{{used in system}}
{{Module rating|release}}
{{Module rating|protected}}
This module provides a consistent interface for processing boolean or boolean-style string input.
While Lua allows the <code>true</code> and <code>false</code> boolean values, wikicode templates can only express boolean values through strings such as "1", "0", "yes", "no", etc.
Line 16 ⟶ 7:
It also returns <code>nil</code> values as <code>nil</code>, to allow for distinctions between <code>nil</code> and <code>false</code>.
The module also accepts other Lua structures as input, i.e. booleans, numbers, tables, and functions.
If it is passed input that it does not recogniserecognize as boolean or <code>nil</code>, it is possible to specify a default value to return.
 
== Syntax ==
<syntaxhighlight lang="lua">
Line 25 ⟶ 17:
Boolean input or boolean-style input (see below) always evaluates to either <code>true</code> or <code>false</code>, and <code>nil</code> always evaluates to <code>nil</code>.
Other values evaluate to <code>default</code>.
 
== Usage ==
First, load the module. Note that it can only be loaded from other Lua modules, not from normal wiki pages.
For normal wiki pages you can use {{tlx|yesno}} instead.
 
<syntaxhighlight lang="lua">
Line 97 ⟶ 89:
yesno(function() return 'This is a function.' end, 'bar')
</syntaxhighlight>
<!--T:26-->
Note that the blank string also functions this way:
<syntaxhighlight lang="lua">
Line 107 ⟶ 100:
This module prefers the Lua behaviour over the wikitext behaviour.
If treating the blank string as <code>false</code> is important for your module, you will need to remove blank arguments at an earlier stage of processing.
<noinclude><!--
<includeonly>{{Sandbox other||
 
<!-- Categories below this line; interwikis at Wikidata -->
<includeonly>{{Sandbox other||
<!-- Template categories/interwikis here -->
[[Category:Modules]]
}}</includeonly><noinclude>
[[Category:Module documentation pages{{#translation:}}]]
</noinclude>
| #default=
{{#invoke:Template translation|renderTranslatedTemplate|template=Module:Yesno/doc|noshift=1|uselang={{int:lang}}}}
}}
Anonymous user