Skip to content

operator ​

Lua operators exposed as functions.

Usage ​

lua
operator = require "mods.operator"

print(operator.add(1, 2)) --> 3

Functions ​

Arithmetic:

FunctionDescription
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:

FunctionDescription
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:

FunctionDescription
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:

FunctionDescription
concat(a, b)Concatenate two strings.
len(a)Return the length of a string or table using Lua's # operator.

Tables & Calls:

FunctionDescription
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 of a and b.

Example:

lua
add(1, 2) --> 3

sub(a, b) ​

Subtract b from a.

Parameters:

  • a (number): Left numeric value.
  • b (number): Right numeric value.

Return:

  • difference (number): Difference a - b.

Example:

lua
sub(5, 3) --> 2

mul(a, b) ​

Multiply two numbers.

Parameters:

  • a (number): Left numeric value.
  • b (number): Right numeric value.

Return:

  • product (number): Product a * b.

Example:

lua
mul(3, 4) --> 12

div(a, b) ​

Divide a by b using Lua's floating-point division.

Parameters:

  • a (number): Dividend value.
  • b (number): Divisor value.

Return:

  • quotient (number): Quotient a / b.

Example:

lua
div(10, 4) --> 2.5

idiv(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:

lua
idiv(5, 2) --> 2

mod(a, b) ​

Return the modulo remainder of a divided by b.

Parameters:

  • a (number): Dividend value.
  • b (number): Divisor value.

Return:

  • remainder (number): Remainder of a % b.

Example:

lua
mod(5, 2) --> 1

pow(a, b) ​

Raise a to the power of b.

Parameters:

  • a (number): Base value.
  • b (number): Exponent value.

Return:

  • power (number): Result of a ^ b.

Example:

lua
pow(2, 4) --> 16

unm(a) ​

Negate a number.

Parameters:

  • a (number): Input numeric value.

Return:

  • negated (number): Result of -a.

Example:

lua
unm(3) --> -3

Comparison ​

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 when a == b.

Example:

lua
eq(1, 1) --> true

neq(a, b) ​

Check whether two values are not equal.

Parameters:

  • a (any): Left value.
  • b (any): Right value.

Return:

  • isNotEqual (boolean): True when a ~= b.

Example:

lua
neq(1, 2) --> true

lt(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 when a < b.

Example:

lua
lt(1, 2) --> true

le(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 when a <= b.

Example:

lua
le(2, 2) --> true

gt(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 when a > b.

Example:

lua
gt(3, 2) --> true

ge(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 when a >= b.

Example:

lua
ge(2, 2) --> true

Logical ​

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 of a and b.

Example:

lua
land(true, false) --> false

lor(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 of a or b.

Example:

lua
lor(false, true) --> true

lnot(a) ​

Return the boolean negation of a.

Parameters:

  • a (any): Input value.

Return:

  • isNot (boolean): Result of not a.

Example:

lua
lnot(true) --> false

String & 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 result a .. b.

Example:

lua
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:

lua
len("abc") --> 3

Tables & 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 at t[k].

Example:

lua
index({ a = 1 }, "a") --> 1

setindex(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 value v.

Example:

lua
setindex({}, "a", 1) --> 1

call(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) from f(...).

Example:

lua
call(math.max, 1, 2) --> 2