webmcp
diff framework/env/format/boolean.lua @ 0:9fdfb27f8e67
Version 1.0.0
author | jbe/bsw |
---|---|
date | Sun Oct 25 12:00:00 2009 +0100 (2009-10-25) |
parents | |
children |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/framework/env/format/boolean.lua Sun Oct 25 12:00:00 2009 +0100 1.3 @@ -0,0 +1,30 @@ 1.4 +--[[-- 1.5 +text = -- human text representation of the boolean 1.6 +format.boolean( 1.7 + value, -- true, false or nil 1.8 + { 1.9 + true_as = true_text, -- text representing true 1.10 + false_as = false_text, -- text representing false 1.11 + nil_as = nil_text -- text representing nil 1.12 + } 1.13 +) 1.14 + 1.15 +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". 1.16 + 1.17 +--]]-- 1.18 + 1.19 +function format.boolean(value, options) 1.20 + local options = options or {} 1.21 + local true_text = options.true_as or "Yes" -- TODO: localization? 1.22 + local false_text = options.false_as or "No" -- TODO: localization? 1.23 + local nil_text = options.nil_as or "" 1.24 + if value == nil then 1.25 + return nil_text 1.26 + elseif value == false then 1.27 + return false_text 1.28 + elseif value == true then 1.29 + return true_text 1.30 + else 1.31 + error("Value passed to format.boolean(...) is neither a boolean nor nil.") 1.32 + end 1.33 +end