webmcp
view framework/env/format/boolean.lua @ 244:10275e753a22
Added missing local declaration in ui.list{...} implementation
| author | jbe | 
|---|---|
| date | Sun Mar 01 20:55:01 2015 +0100 (2015-03-01) | 
| 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
