Added operator docs

This commit is contained in:
CPunch 2021-01-24 12:28:53 -06:00
parent c82a01c968
commit e38e8f335f
1 changed files with 34 additions and 0 deletions

34
docs/operators.md Normal file
View File

@ -0,0 +1,34 @@
# Operators
## Arithmetic
| Operator | Description | Example |
| -------- | ---------------------------- | -------------------------------------- |
| `+` | Adds two numerical values together | `print(2 + 2)` -> `3 ;)` |
| `-` | Subtracts two numerical values together | `print(2 - 1)` -> `1` |
| `*` | Multiplies two numerical values together | `print(3 * 3)` -> `9` |
| `/` | Divides two numerical values together | `print(5 / 2)` -> `2.5` |
| `%` | performs a modulus operator on two numerical values | `print(5 % 2)` -> `1` |
> -> means 'outputs'
## Unary
| Operator | Description | Example |
| -------- | ---------------------------- | -------------------------------------- |
| `!` | "Not" logical operator, flips the logical polarity. | `print(!true)` -> `false` |
| `#` | "Count" calls '__count' metamethod on objects or gives the count of entries in tables | `print(#[1,2,3])` -> `3`, `print(#{__count = function(self) return self.x end, x = 1337})` -> `1337` |
> -> means 'outputs'
## Logical
| Operator | Description | Example |
| -------- | ---------------------------- | -------------------------------------- |
| `and` | Logical 'and' operation | `print(true and 1337)` -> `1337` |
| `or` | Logical 'or' operation | `print(nil or false or 1337)` -> `1337` |
| `==` | Logical equality operation | `print(1337 == 1337)` -> `true` |
| `!=` | Logical not equality operation | `print(1337 != 1337)` -> `false` |
| `>=` | Greater than or equals too | `print(1337 >= 2000)` -> `false` |
| `<=` | Less than or equals too | `print(1337 <= 2000)` -> `true` |
| `>` | Greater than | `print(1337 > 2000)` -> `false` |
| `<` | Less than | `print(1337 < 2000)` -> `true` |
> -> means 'outputs'