Penlight Documentation

# Module `pl.types`

Dealing with Detailed Type Information

## Functions

is_callable (obj) | is the object either a function or a callable object?.
is_type (obj, tp) | is the object of the specified type?.
type (obj) | a string representation of a type.
is_integer (x) | is this number an integer?
is_empty (o, ignore_spaces) | Check if the object is "empty".
is_indexable (val) | is an object 'array-like'?
is_iterable (val) | can an object be iterated over with pairs?
is_writeable (val) | can an object accept new key/pair values?
to_bool (o[, true_strs[, check_objs]]) | Convert to a boolean value.

## Functions

is_callable (obj)
  is the object either a function or a callable object?.

  ### Parameters:

  - obj Object to check.
is_type (obj, tp)
  is the object of the specified type?. If the type is a string, then use type, otherwise compare with metatable.

  NOTE: this function is imported from utils.is_type.

  ### Parameters:

  - obj An object to check
  - tp The expected type

  ### See also:

  utils.is_type
type (obj)
  a string representation of a type. For tables and userdata with metatables, we assume that the metatable has a `_name` field. If the field is not present it will return 'unknown table' or 'unknown userdata'. Lua file objects return the type 'file'.

  ### Parameters:

  - obj an object

  ### Returns:

  a string like 'number', 'table', 'file' or 'List'
is_integer (x)
  is this number an integer?

  ### Parameters:

  - x a number

  ### Returns:

  boolean

  ### Raises:

  error if x is not a number
is_empty (o, ignore_spaces)

  Check if the object is "empty". An object is considered empty if it is:

  - `nil`
  - a table with out any items (key-value pairs or indexes)
  - a string with no content ("")
  - not a nil/table/string

  ### Parameters:

  - o The object to check if it is empty.
  - ignore_spaces If the object is a string and this is true the string is considered empty if it only contains spaces.

  ### Returns:

  `true` if the object is empty, otherwise a falsy value.
is_indexable (val)
  is an object 'array-like'? An object is array like if:
  - it is a table, or
  - it has a metatable with `__len` and `__index` methods

  NOTE: since `__len` is 5.2+, on 5.1 is usually returns `false` for userdata

  ### Parameters:

  - val any value.

  ### Returns:

  `true` if the object is array-like, otherwise a falsy value.
is_iterable (val)
  can an object be iterated over with pairs? An object is iterable if:
  - it is a table, or
  - it has a metatable with a `__pairs` meta method

  NOTE: since `__pairs` is 5.2+, on 5.1 is usually returns `false` for userdata

  ### Parameters:

  - val any value.

  ### Returns:

  `true` if the object is iterable, otherwise a falsy value.
is_writeable (val)

  can an object accept new key/pair values? An object is iterable if:

  - it is a table, or
  - it has a metatable with a `__newindex` meta method

  ### Parameters:

  - val any value.

  ### Returns:

  `true` if the object is writeable, otherwise a falsy value.
to_bool (o[, true_strs[, check_objs]])

  Convert to a boolean value. True values are:

  - boolean: true.
  - string: 'yes', 'y', 'true', 't', '1' or additional strings specified by `true_strs`.
  - number: Any non-zero value.
  - table: Is not empty and `check_objs` is true.
  - everything else: Is not `nil` and `check_objs` is true.

  ### Parameters:

  - o The object to evaluate.
  - true_strs optional Additional strings that when matched should evaluate to true. Comparison is case insensitive. This should be a List of strings. E.g. "ja" to support German. (optional)
  - check_objs True if objects should be evaluated. (optional)

  ### Returns:

  true if the input evaluates to true, otherwise false.

generated by LDoc 1.4.6