operator ​
Lua operators exposed as functions.
Usage ​
operator = require "mods.operator"
print(operator.add(1, 2)) --> 3Functions ​
Arithmetic:
| Function | Description |
|---|---|
add(a, b) | Add two numbers. |
sub(a, b) | Subtract b from a. |
mul(a, b) | Multiply two numbers. |
div(a, b) | Divide a by b using Lua's floating-point division. |
idiv(a, b) | Divide a by b and return the floor-division quotient. |
mod(a, b) | Return the modulo remainder of a divided by b. |
pow(a, b) | Raise a to the power of b. |
unm(a) | Negate a number. |
Comparison:
| Function | Description |
|---|---|
eq(a, b) | Check whether two values are equal. |
neq(a, b) | Check whether two values are not equal. |
lt(a, b) | Check whether a is strictly less than b. |
le(a, b) | Check whether a is less than or equal to b. |
gt(a, b) | Check whether a is strictly greater than b. |
ge(a, b) | Check whether a is greater than or equal to b. |
Logical:
| Function | Description |
|---|---|
land(a, b) | Evaluate a and b with Lua short-circuit semantics. |
lor(a, b) | Evaluate a or b with Lua short-circuit semantics. |
lnot(a) | Return the boolean negation of a. |
String & Length:
| Function | Description |
|---|---|
concat(a, b) | Concatenate two strings. |
len(a) | Return the length of a string or table using Lua's # operator. |
Tables & Calls:
| Function | Description |
|---|---|
index(t, k) | Return the value at key/index k in table t. |
setindex(t, k, v) | Set t[k] = v and return the assigned value. |
call(f, ...) | Call a function with variadic arguments and return its result. |
Arithmetic ​
Numeric arithmetic operators as functions.
add(a, b) ​
Add two numbers.
Parameters:
a(number): Left numeric value.b(number): Right numeric value.
Return:
sum(number): Sum ofaandb.
Example:
add(1, 2) --> 3sub(a, b) ​
Subtract b from a.
Parameters:
a(number): Left numeric value.b(number): Right numeric value.
Return:
difference(number): Differencea - b.
Example:
sub(5, 3) --> 2mul(a, b) ​
Multiply two numbers.
Parameters:
a(number): Left numeric value.b(number): Right numeric value.
Return:
product(number): Producta * b.
Example:
mul(3, 4) --> 12div(a, b) ​
Divide a by b using Lua's floating-point division.
Parameters:
a(number): Dividend value.b(number): Divisor value.
Return:
quotient(number): Quotienta / b.
Example:
div(10, 4) --> 2.5idiv(a, b) ​
Divide a by b and return the floor-division quotient.
Parameters:
a(number): Dividend value.b(number): Divisor value.
Return:
quotient(integer): Floor-division result.
Example:
idiv(5, 2) --> 2mod(a, b) ​
Return the modulo remainder of a divided by b.
Parameters:
a(number): Dividend value.b(number): Divisor value.
Return:
remainder(number): Remainder ofa % b.
Example:
mod(5, 2) --> 1pow(a, b) ​
Raise a to the power of b.
Parameters:
a(number): Base value.b(number): Exponent value.
Return:
power(number): Result ofa ^ b.
Example:
pow(2, 4) --> 16unm(a) ​
Negate a number.
Parameters:
a(number): Input numeric value.
Return:
negated(number): Result of-a.
Example:
unm(3) --> -3Comparison ​
Equality and ordering comparison operators.
eq(a, b) ​
Check whether two values are equal.
Parameters:
a(any): Left value.b(any): Right value.
Return:
isEqual(boolean): True whena == b.
Example:
eq(1, 1) --> trueneq(a, b) ​
Check whether two values are not equal.
Parameters:
a(any): Left value.b(any): Right value.
Return:
isNotEqual(boolean): True whena ~= b.
Example:
neq(1, 2) --> truelt(a, b) ​
Check whether a is strictly less than b.
Parameters:
a(number): Left numeric value.b(number): Right numeric value.
Return:
isLess(boolean): True whena < b.
Example:
lt(1, 2) --> truele(a, b) ​
Check whether a is less than or equal to b.
Parameters:
a(number): Left numeric value.b(number): Right numeric value.
Return:
isLessOrEqual(boolean): True whena <= b.
Example:
le(2, 2) --> truegt(a, b) ​
Check whether a is strictly greater than b.
Parameters:
a(number): Left numeric value.b(number): Right numeric value.
Return:
isGreater(boolean): True whena > b.
Example:
gt(3, 2) --> truege(a, b) ​
Check whether a is greater than or equal to b.
Parameters:
a(number): Left numeric value.b(number): Right numeric value.
Return:
isGreaterOrEqual(boolean): True whena >= b.
Example:
ge(2, 2) --> trueLogical ​
Boolean logic operators with Lua truthiness semantics.
land(a, b) ​
Evaluate a and b with Lua short-circuit semantics.
Parameters:
a(T1): First operand.b(T2): Second operand.
Return:
andValue(T1|T2): Result ofa and b.
Example:
land(true, false) --> falselor(a, b) ​
Evaluate a or b with Lua short-circuit semantics.
Parameters:
a(T1): First operand.b(T2): Second operand.
Return:
orValue(T1|T2): Result ofa or b.
Example:
lor(false, true) --> truelnot(a) ​
Return the boolean negation of a.
Parameters:
a(any): Input value.
Return:
isNot(boolean): Result ofnot a.
Example:
lnot(true) --> falseString & Length ​
String concatenation and length operators.
concat(a, b) ​
Concatenate two strings.
Parameters:
a(string): Left string.b(string): Right string.
Return:
concatenated(string): Concatenated resulta .. b.
Example:
concat("a", "b") --> "ab"len(a) ​
Return the length of a string or table using Lua's # operator.
Parameters:
a(string|table): Value supporting Lua's#operator.
Return:
length(integer): Length computed by#a.
Example:
len("abc") --> 3Tables & Calls ​
Table indexing helpers and function invocation.
index(t, k) ​
Return the value at key/index k in table t.
Parameters:
t(table): Source table.k(T): Key/index value.
Return:
indexedValue(T): Value stored att[k].
Example:
index({ a = 1 }, "a") --> 1setindex(t, k, v) ​
Set t[k] = v and return the assigned value.
Parameters:
t(table): Target table.k(any): Key/index value.v(T): Value to set.
Return:
assignedValue(T): Assigned valuev.
Example:
setindex({}, "a", 1) --> 1call(f, ...) ​
Call a function with variadic arguments and return its result.
Parameters:
f(fun(...:T1):T2): Function to call....(T1): Additional arguments.
Return:
callResult(T2): Return value(s) fromf(...).
Example:
call(math.max, 1, 2) --> 2