Operator
From Legacy Roblox Wiki
Jump to navigationJump to search
Operators
Logical
The word "truthy" in the following table refers to anything that isn't nil or false.
Operator | Simple description | Technical Description |
---|---|---|
a and b | Return true only if a and b are true | Return b if a is truthy, otherwise return a |
a or b | Return true if either a or b is true | Return a if a is truthy, otherwise return b |
not a | Return the opposite of a | Return false if a is truthy, else return true |
Comparative
Comparative operators are operators that compare two parameters and return a boolean. There are several operators.
Operator | Name | Associated metamethod |
---|---|---|
== | Equal to | __eq |
~= | Not equal to | |
> | Greater than | |
< | Less than | __lt |
>= | Greater than or equal to | |
<= | Less than or equal to | __lte |
Mathematic
Main article: Arithmetic Operators
Mathematic operators are operators that perform an arithmetic operation on their operands.
Operator | Name | Example | Associated metamethod |
---|---|---|---|
^ | Exponentiation | 2 ^ 4 = 16 | __pow |
- | Unary negation | -2 = 0 - 2 | __unm |
* | Multiplication | 5 * 5 = 25 | __mul |
/ | Division | 10 / 5 = 2 | __div |
% | Modulus | 13 % 7 = 6 | __mod |
+ | Addition | 1 + 1 = 2 | __add |
- | Subtraction | 1 - 1 = 0 | __sub |
Miscellaneous
Miscellaneous operators are operators that perform a task that cannot be categorized as the other three types.
Operator | Name | Associated metamethod |
---|---|---|
= | Assignment | |
x .. y | Concatenation | __concat |
#x | Length of table | __len |
x(...) | Invocation | __call |
x[y] or x.z | Indexing | __index / __newindex |