Skip to content

Commit

Permalink
Copyedit syntax.md (#12)
Browse files Browse the repository at this point in the history
Co-authored-by: Alexander McCord <[email protected]>
  • Loading branch information
deviaze and alexmccord authored Oct 22, 2024
1 parent 17a01b5 commit 1318d7f
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions _pages/syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -270,19 +270,29 @@ print(`Welcome to {
The sequence of two opening braces {{"`{{`"}} is rejected with a parse error.
This restriction is made to prevent developers using other programming languages with a similar feature from trying to attempt that as a way to escape a single `{` and getting unexpected results in Luau.

Luau currently does not support backtick string literals as type annotations, therefore `` type Foo = `Foo` `` is invalid syntax.
Luau currently does not support backtick string literals in type annotations, therefore `` type Foo = `Foo` `` is invalid syntax.

Unlike single and double-quoted string literals, backtick string literals must always be wrapped in parentheses for function calls:
```lua
print`hello` -- invalid syntax
print "hello" -- valid
print`hello` -- invalid syntax
print(`hello`) -- valid
```

## Floor division (`//`)

Luau supports the floor division operator (`//`) and its compound assignment operator (`//=`) as ergonomic alternatives to `math.floor`.
Luau supports floor division, including its operator (`//`), its compound assignment operator (`//=`), and overloading metamethod (`__idiv`), as an ergonomic alternative to `math.floor`.

For numbers, `a // b` is equal to `math.floor(a / b)`:
```lua
local n = 6.72
print(n // 2) --> 3
n //= 3
print(n) --> 2
```

Note that it's possible to get `inf`, `-inf`, or `NaN` with floor division; when `b` is `0`, `a // b` results in positive or negative infinity, and when both `a` and `b` are `0`, `a // b` results in NaN.

For numbers, `a // b` is equal to `math.floor(a / b)`. When `b` is 0, `a // b` results in infinity or NaN as appropriate.
The `__idiv` metamethod may be used to overload the `//` and `//=` operators.
For native vectors, `c // d` applies `math.floor` to each component of the vector `c`. Therefore `c // d` is equivalent to `vector.create(math.floor(c.x / d), math.floor(c.y / b), math.floor(c.z / b))`.

Floor division syntax and semantics follow from [Lua 5.3](https://www.lua.org/manual/5.3/manual.html#3.4.1).
Floor division syntax and semantics follow from [Lua 5.3](https://www.lua.org/manual/5.3/manual.html#3.4.1) where applicable.

0 comments on commit 1318d7f

Please sign in to comment.