What Are Operators?
Operators⚓︎
Operators are a set of symbols that you can use to do cool and quirky things.
Logical operators⚓︎
The logical operators are and
, or
, not
.
These operators considers false
and nil
as "false" and everything else as "true".
And⚓︎
and
will evaluate as true
if both conditions are true
You can also use and
to check a condition when assigning a value to a variable without using an if statement.
Or⚓︎
or
will evaluate as true
if one of the conditions are true
Just like and
, you can also use or
when assigning values to variables.
Not⚓︎
not
will evaluate as the opposite of the condition. For example, not true --> false
, not false --> true
Relational⚓︎
Relational operators are used to compare 2 values and will return a boolean (true
or false
)
Equal to (==)⚓︎
As the name suggests, this operator checks if one value is equal to another value.
Not equal to (~=)⚓︎
This operator checks if one value does not equal to another value
Greater than (>)⚓︎
This operator checks if one value is greater than to another value
Less than (<)⚓︎
This operator checks if one value is less than to another value
Greater than or equal to (>=)⚓︎
This operator checks if one value is great than or equal to to another value
Less than or equal to (<=)⚓︎
This operator checks if one value is less than or equal to to another value
Arithmetic⚓︎
Lua supports the usual binary operators along with exponentiation (^), modulus (%), and unary negation (-). These are pretty self explanatory, so I won't be providing any explanations.
Addition (+)⚓︎
Subtraction (-)⚓︎
Multiplication (*)⚓︎
Division (/)⚓︎
Exponentiation (^)⚓︎
Modulus (%)⚓︎
Unary negation (-)⚓︎
Miscellaneous⚓︎
Miscellaneous operators include concatenation and length.
Concatenation (..)⚓︎
Concatenates 2 values together. You can only concatenate strings and numbers
Length (#)⚓︎
If used on a table, specifically an array, it will return the number of elements in that array. If used on a string, it will return the amount of characters in that string, spaces are counted too
Thanks for reading !!!⚓︎
If there are any mistakes found in this article, please report the artcile!