Anonymous user
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><!--▼
<!--
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
== 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.
<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.
<includeonly>{{Sandbox other||▼
<!-- Template categories/interwikis here -->
[[Category:Modules]]
|