Module:Yesno/doc

From The Kodiak Republic Wiki

Revision as of 14:10, 20 September 2013 by wikipedia>Mr. Stradivarius (create)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

This is the documentation page for Module:Yesno

This module provides a consistent interface for processing boolean or boolean-style string input. While Lua allows the true and false boolean values, wikicode templates can only express boolean values through strings such as "yes", "no", etc. This module processes these kinds of strings and turns them into boolean input for Lua to process. It also accepts other Lua structures as input, i.e. booleans, numbers, tables, and functions. If it is passed input that it does not recognise as boolean, it allows the return of a default value.

Usage

First, load the module.

local yesno = require('Module:Yesno')

Some input values always return true, and some always return false.

-- These always return true:
yesno('yes')
yesno('y')
yesno('true')
yesno('1')
yesno(1)
yesno(true)

-- These always return false:
yesno('no')
yesno('n')
yesno('false')
yesno('0')
yesno(0)
yesno(false)
yesno(nil)

You can specify a default value for input other than the types above. If you don't supply a default, the module will return true.

-- These return true:
yesno('foo')
yesno({})
yesno(5)
yesno(function() return 'This is a function.' end)

-- These return "bar":
yesno('foo', 'bar')
yesno({}, 'bar')
yesno(5, 'bar')
yesno(function() return 'This is a function.' end, 'bar')

Note that the blank string also functions this way:

yesno('')        -- Returns true.
yesno('', 'bar') -- Returns "bar".

Although the blank string usually evaluates to false in wikitext, it evaluates to true in Lua. This module prefers the Lua behaviour over the wikitext behaviour. If treating the blank string as false is important for your module, you will need to remove blank arguments at an earlier stage of processing.

Cookies help us deliver our services. By using our services, you agree to our use of cookies.