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.
Dependencies: pl.utils
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, b) | 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 ~ uses string.find |
nop (...) | the null operation. |
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 objectk
: the key
- eq (a, b)
-
returns true if arguments are equal ==
Parameters:
a
: valueb
: value
- neq (a, b)
-
returns true if arguments are not equal ~=
Parameters:
a
: valueb
: value
- lt (a, b)
-
returns true if a is less than b <
Parameters:
a
: valueb
: value
- le (a, b)
-
returns true if a is less or equal to b <=
Parameters:
a
: valueb
: value
- gt (a, b)
-
returns true if a is greater than b >
Parameters:
a
: valueb
: value
- ge (a, b)
-
returns true if a is greater or equal to b >=
Parameters:
a
: valueb
: value
- len (a)
-
returns length of string or table #
Parameters:
a
: a string or a table
- add (a, b)
-
add two values +
Parameters:
a
: valueb
: value
- sub (a, b)
-
subtract b from a –
Parameters:
a
: valueb
: value
- mul (a, b)
-
multiply two values *
Parameters:
a
: valueb
: value
- div (a, b)
-
divide first value by second /
Parameters:
a
: valueb
: value
- pow (a, b)
-
raise first to the power of second ^
Parameters:
a
: valueb
: value
- mod (a, b)
-
modulo; remainder of a divided by b %
Parameters:
a
: valueb
: value
- concat (a, b)
-
concatenate two values (either strings or __concat defined) ..
Parameters:
a
: valueb
: value
- unm (a, b)
-
return the negative of a value –
Parameters:
a
: valueb
: 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
: valueb
: value
- lor (a, b)
-
true if either value evaluate as true or
Parameters:
a
: valueb
: 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