File Boolean.lua

Functions

Boolean:booleanFromString (s) Obtain boolean value from string representation.
Boolean:booleanValue (v, dflt) Get boolean equivalent, or default.
Boolean:getAsBoolean (a) Get a boolean from a variable whose type has not been pre-assured.
Boolean:getBoolean (a, nameToThrow, default) Determine if a boolean, and if so, return it's value, otherwise return nil.
Boolean:isBooleanTrue (v) Determine if value is non-nil, boolean, and true.
Boolean:isFalse (v) Determine if the specified boolean is false.
Boolean:isTrue (v) Determine if the specified boolean is true.
Boolean:new (t) Constructor for new instance.
Boolean:newClass (t) Constructor for extending class.


Functions

Boolean:booleanFromString (s)
Obtain boolean value from string representation.

Parameters:

  • s:

Usage:

    the inverse of 'tostring( booleanValue )'. 
Boolean:booleanValue (v, dflt)
Get boolean equivalent, or default.

Parameters:

  • v: (any type, required) value to have returned boolean equivalent of.
  • dflt: (boolean, optional) default in case value is nil.

Usage:

  • always returns boolean true or false, never throws error.
  • example: switch = bool:booleanValue( myVar, true ) -- return true or false if set, and if unset, return true. 
Boolean:getAsBoolean (a)
Get a boolean from a variable whose type has not been pre-assured.

Parameters:

  • a:

Usage:

  • If boolean, then returned verbatim, if string, then attempt to convert to boolean, otherwise returns nil.
  • The intended use is for cases when a boolean is required, but user or legacy code may have left something else where a number is expected, in which case, the old value is to be ignored...
  • never throws an error.
  • myBool = bool:getAsBoolean( something ) or false -- assure boolean true or false from boolean or string, else convert nil to false.
  • myBool = bool:getAsBoolean( something ); if myBool == nil then -- something is not gettable as boolean. 
Boolean:getBoolean (a, nameToThrow, default)
Determine if a boolean, and if so, return it's value, otherwise return nil.

Parameters:

  • a:
  • nameToThrow:
  • default:

Usage:

    throws error if not boolean type. 
Boolean:isBooleanTrue (v)
Determine if value is non-nil, boolean, and true.

Parameters:

  • v:

Usage:

  • Convenience function for times when a value could be boolean true or something else...
  • this function will never throw an error. 

Return value:

    true iff "all of the above".
Boolean:isFalse (v)
Determine if the specified boolean is false.

Parameters:

  • v:

Usage:

    Same as 'not v' except it will throw an error if the value is not a boolean. 
Boolean:isTrue (v)
Determine if the specified boolean is true.

Parameters:

  • v:

Usage:

    Returns the value as is if not nil, else the boolean 'false'. Avoids problem of illegal comparison with nil. 
Boolean:new (t)
Constructor for new instance.

Parameters:

  • t:
Boolean:newClass (t)
Constructor for extending class.

Parameters:

  • t:

Valid XHTML 1.0!