webmcp

view framework/env/format/boolean.lua @ 412:7d43be9afa56

Improved memory cleanup in case of out-of-memory errors (PQnotifies and PQunescapeBytea)
author jbe
date Fri Jan 08 03:10:33 2016 +0100 (2016-01-08)
parents 9fdfb27f8e67
children
line source
1 --[[--
2 text = -- human text representation of the boolean
3 format.boolean(
4 value, -- true, false or nil
5 {
6 true_as = true_text, -- text representing true
7 false_as = false_text, -- text representing false
8 nil_as = nil_text -- text representing nil
9 }
10 )
12 Returns a human readable text representation of a boolean value. Additional parameters should be given, unless you like the defaults for false and true, which are "0" and "1".
14 --]]--
16 function format.boolean(value, options)
17 local options = options or {}
18 local true_text = options.true_as or "Yes" -- TODO: localization?
19 local false_text = options.false_as or "No" -- TODO: localization?
20 local nil_text = options.nil_as or ""
21 if value == nil then
22 return nil_text
23 elseif value == false then
24 return false_text
25 elseif value == true then
26 return true_text
27 else
28 error("Value passed to format.boolean(...) is neither a boolean nor nil.")
29 end
30 end

Impressum / About Us