Penlight Documentation

# Module `pl.operator`

Lua operators available as functions.

(similar to the Python module of the same name)

There is a module field optable which maps the operator strings onto these functions, e.g. `operator.optable['()']==operator.call`

Operator strings like '>' and '{}' can be passed to most Penlight functions expecting a function argument.

## Functions

call (fn, ...) | apply function to some arguments ()
index (t, k) | get the indexed value from a table []
eq (a, b) | returns true if arguments are equal ==
neq (a, b) | returns true if arguments are not equal ~=
lt (a, b) | returns true if a is less than b <
le (a, b) | returns true if a is less or equal to b <=
gt (a, b) | returns true if a is greater than b >
ge (a, b) | returns true if a is greater or equal to b >=
len (a) | returns length of string or table #
add (a, b) | add two values +
sub (a, b) | subtract b from a -
mul (a, b) | multiply two values *
div (a, b) | divide first value by second /
pow (a, b) | raise first to the power of second ^
mod (a, b) | modulo; remainder of a divided by b %
concat (a, b) | concatenate two values (either strings or `__concat` defined) ..
unm (a) | return the negative of a value -
lnot (a) | false if value evaluates as true not
land (a, b) | true if both values evaluate as true and
lor (a, b) | true if either value evaluate as true or
table (...) | make a table from the arguments {}
match (a, b) | match two strings ~.
nop (...) | the null operation.

## Tables

optable | Map from operator symbol to function.

## Functions

call (fn, ...)
  apply function to some arguments ()

  ### Parameters:

  - fn a function or callable object
  - ... arguments
index (t, k)
  get the indexed value from a table []

  ### Parameters:

  - t a table or any indexable object
  - k the key
eq (a, b)
  returns true if arguments are equal ==

  ### Parameters:

  - a value
  - b value
neq (a, b)
  returns true if arguments are not equal ~=

  ### Parameters:

  - a value
  - b value
lt (a, b)
  returns true if a is less than b <

  ### Parameters:

  - a value
  - b value
le (a, b)
  returns true if a is less or equal to b <=

  ### Parameters:

  - a value
  - b value
gt (a, b)
  returns true if a is greater than b >

  ### Parameters:

  - a value
  - b value
ge (a, b)
  returns true if a is greater or equal to b >=

  ### Parameters:

  - a value
  - b value
len (a)
  returns length of string or table #

  ### Parameters:

  - a a string or a table
add (a, b)
  add two values +

  ### Parameters:

  - a value
  - b value
sub (a, b)
  subtract b from a -

  ### Parameters:

  - a value
  - b value
mul (a, b)
  multiply two values *

  ### Parameters:

  - a value
  - b value
div (a, b)
  divide first value by second /

  ### Parameters:

  - a value
  - b value
pow (a, b)
  raise first to the power of second ^

  ### Parameters:

  - a value
  - b value
mod (a, b)
  modulo; remainder of a divided by b %

  ### Parameters:

  - a value
  - b value
concat (a, b)
  concatenate two values (either strings or `__concat` defined) ..

  ### Parameters:

  - a value
  - b value
unm (a)
  return the negative of a value -

  ### Parameters:

  - a value
lnot (a)
  false if value evaluates as true not

  ### Parameters:

  - a value
land (a, b)
  true if both values evaluate as true and

  ### Parameters:

  - a value
  - b value
lor (a, b)
  true if either value evaluate as true or

  ### Parameters:

  - a value
  - b value
table (...)
  make a table from the arguments {}

  ### Parameters:

  - ... non-nil arguments

  ### Returns:

  a table
match (a, b)
  match two strings ~. uses string.find

  ### Parameters:

  - a
  - b
nop (...)
  the null operation.

  ### Parameters:

  - ... arguments

  ### Returns:

  the arguments

## Tables

optable

  Map from operator symbol to function. Most of these map directly from operators; But note these extras

  - '()' call
  - '[]' index
  - '{}' table
  - '~' match

  ### Fields:

  - operator

generated by LDoc 1.5.0