You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/advanced/language-extensions.md
+45-7Lines changed: 45 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -70,10 +70,14 @@ Example:
70
70
<SideBySide>
71
71
72
72
<!-- prettier-ignore -->
73
+
73
74
```ts
74
-
for (const i of$range(1, 5)) {}
75
-
for (const i of$range(1, 10, 2)) {}
76
-
for (const i of$range(5, 1, -1)) {}
75
+
for (const i of$range(1, 5)) {
76
+
}
77
+
for (const i of$range(1, 10, 2)) {
78
+
}
79
+
for (const i of$range(5, 1, -1)) {
80
+
}
77
81
```
78
82
79
83
```lua
@@ -131,7 +135,8 @@ end
131
135
Lua iterators support passing an invisible state object each iteration. If your iterator type does this, you can declare the state type as a second type parameter:
Lua supports overloading operators on types using [metatable methods](https://www.lua.org/manual/5.4/manual.html#2.4) such as `__add`. But, JavaScript and TypeScript do not support this. In order to use overloaded operators on types that support them, you can declare special mapping functions in TS that will translate to those operators in Lua.
@@ -343,6 +371,14 @@ end
343
371
344
372
(Remember that in Lua, `pairs()` returns the keys in a random order.)
345
373
374
+
### `LuaMap` and `LuaSet`
375
+
376
+
Similar to `LuaTable`, the `LuaMap` and `LuaSet` types are provided to represent Lua tables used as a map or set. These are much more performant than the `Set`/`Map` classes, but do not come with all the same features (such as guaranteed insertion order).
377
+
378
+
`LuaMap` has the same methods as `LuaTable`, except that `table.get(key)` may also return `undefined`.
379
+
380
+
`LuaSet`, instead of `table.get/table.set`, has `table.add(value)`, which translates to `table[value] = true`.
381
+
346
382
### Custom Getters and Setters
347
383
348
384
If you have a type that uses non-string keys, you can use `LuaTableGet` and `LuaTableSet` function types to declare your own getters & setters, similar to [Operator Map Types](#operator-map-types).
0 commit comments