Skip to content

Commit 2a5cafd

Browse files
authored
Some documentation updates for Lua 5.5 (#1159)
* docs: demonstrate union type inference in else * docs: reflect Lua 5.5 compiler options and variable attributes * docs: 5.5-style named varags (introduced in #1122) * docs: missing word * docs: named varargs should always be read-only (see #1160)
1 parent d0ba265 commit 2a5cafd

4 files changed

Lines changed: 20 additions & 11 deletions

File tree

docs/src/compiler_options.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ return {
2424
| `-I --include-dir` | `include_dir` | `{string}` | `check` `gen` `run` | Prepend this directory to the module search path.
2525
| | `source_dir` | `string` | `check` `gen` `run` | Set the project source directory and add it to the module search path.
2626
| `--gen-compat` | `gen_compat` | `string` | `gen` `run` | Generate compatibility code for targeting different Lua VM versions. See [below](#generated-code) for details.
27-
| `--gen-target` | `gen_target` | `string` | `gen` `run` | Minimum targeted Lua version for generated code. Options are `5.1`, `5.3` and `5.4`. See [below](#generated-code) for details.
27+
| `--gen-target` | `gen_target` | `string` | `gen` `run` | Minimum targeted Lua version for generated code. Options are `5.1`, `5.3`, `5.4` and `5.5`. See [below](#generated-code) for details.
2828
| `--keep-hashbang` | | | `gen` | Preserve hashbang line (`#!`) at the top of file if present.
2929
| `-p --pretend` | | | `gen` | Don't compile/write to any files, but type check and log what files would be written to.
3030
| `--wdisable` | `disable_warnings` | `{string}` | `check` `run` | Disable the given warnings.
@@ -39,7 +39,7 @@ such as `src` without repeating that directory in `include_dir`; any explicit
3939

4040
### Generated code
4141

42-
Teal is a Lua dialect that most closely resembles Lua 5.3-5.4, but it is able
42+
Teal is a Lua dialect that most closely resembles Lua 5.3–5.5, but it is able
4343
to target Lua 5.1 (including LuaJIT) and Lua 5.2 as well. The compiler attempts
4444
to produce code that, given an input `.tl` file, generates the same behavior
4545
on various Lua versions.
@@ -60,7 +60,7 @@ library for bitwise operators.
6060

6161
Using `5.3`, Teal will generate code using the native `//` and bitwise operators.
6262

63-
The option `5.4` is equivalent to `5.3`, but it also allows using the `<close>`
63+
The options `5.4` and `5.5` are equivalent to `5.3`, but also allow using the `<close>`
6464
variable annotation. Since that is incompatible with other Lua versions, using
6565
this option requires using `--gen-compat=off`.
6666

@@ -76,7 +76,7 @@ target implicitly.
7676

7777
If set explicitly via the `--gen-target` flag of the `tl` CLI (or the equivalent
7878
options in the programmatic API), the generated code will target the Lua
79-
version requested: 5.1, 5.3 or 5.4.
79+
version requested: 5.1, 5.3, 5.4 or 5.5.
8080

8181
If the code generation target is not set explicitly via `--gen-target`, Teal
8282
will target the Lua version most compatible with the version of the Lua VM

docs/src/functions.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ argument type itself.
3838

3939
You can declare functions that generate iterators which can be used in
4040
`for` statements: the function needs to produce another function that iterates.
41-
This is an example [taken the book "Programming in Lua"](https://www.lua.org/pil/7.1.html):
41+
This is an example [taken from the book "Programming in Lua"](https://www.lua.org/pil/7.1.html):
4242

4343
```lua
4444
local function allwords(): (function(): string)
@@ -150,6 +150,15 @@ end
150150
test(1, 2, 3)
151151
```
152152

153+
Named vararg tables, as introduced in [Lua 5.5](https://www.lua.org/manual/5.5/manual.html#3.4.11),
154+
are supported by Teal:
155+
156+
```lua
157+
local function test(...args: boolean): integer, boolean
158+
return args.n, args[1]
159+
end
160+
```
161+
153162
In case your function returns a variable amount of values, you may also declare
154163
variadic return types by using the `type...` syntax:
155164

docs/src/tuples.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ local x = p1[my_number] -- => x is a string | number union
2828
if x is string then
2929
print("Name is " .. x .. "!")
3030
else
31-
print("Age is " .. x)
31+
print("Age is " .. x * 12 .. " months.")
3232
end
3333
```
3434

docs/src/variable_attributes.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ from Lua 5.4. They are:
77

88
The `<const>` annotation works in Teal like it does in Lua 5.4 (it works at
99
compile time, even if you're running a different version of Lua). Do note
10-
however that this is annotation for variables, and not values: the contents of a
11-
value set to a const variable are not constant.
10+
however that, just like in Lua, this is annotation for variables, and not values:
11+
the contents of a value set to a const variable are not constant.
1212

1313
```lua
1414
local xs <const> = {1,2,3}
@@ -18,10 +18,10 @@ xs = {} -- Error! can't replace the array in variable xs
1818

1919
### To-be-closed variables
2020

21-
The `<close>` annotation from Lua 5.4 is only supported in Teal if your code
22-
generation target is Lua 5.4 (see the [compiler options](compiler_options.md)
21+
The `<close>` annotation introduced in Lua 5.4 is only supported in Teal if your code
22+
generation target is Lua 5.4 or greater (see the [compiler options](compiler_options.md)
2323
documentation for details on code generation targets). These work just
24-
[like they do in Lua 5.4](https://www.lua.org/manual/5.4/manual.html#3.3.8).
24+
[like they do in Lua 5.4+](https://www.lua.org/manual/5.4/manual.html#3.3.8).
2525

2626
```lua
2727
local contents = {}

0 commit comments

Comments
 (0)