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/compiler-annotations.md
+47-28Lines changed: 47 additions & 28 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -137,34 +137,6 @@ local inst = MyConstructor(3)
137
137
138
138
</SideBySide>
139
139
140
-
## @forRange
141
-
142
-
**Target elements:**`declare function`
143
-
144
-
Denotes a function declaration is a Lua numerical iterator. When used in a TypeScript `for...of` loop, the resulting Lua will use a numerical for loop.
145
-
146
-
The function should not be a real function and an error will be thrown if it is used in any other way.
Denotes a function declaration is a Lua numerical iterator. When used in a TypeScript `for...of` loop, the resulting Lua will use a numerical for loop.
757
+
758
+
The function should not be a real function and an error will be thrown if it is used in any other way.
Copy file name to clipboardExpand all lines: docs/advanced/language-extensions.md
+23Lines changed: 23 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -61,6 +61,29 @@ end
61
61
foo, four=myFunc(nil)
62
62
```
63
63
64
+
## $range Iterator Function
65
+
66
+
Typescript's numeric for loops are less restrictive than Lua's, so they are transpiled into while loops instead. To create a Lua-style numeric for loop, you can use the `$range` language extension in a for...of loop.
67
+
68
+
Example:
69
+
70
+
<SideBySide>
71
+
72
+
<!-- prettier-ignore -->
73
+
```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)) {}
77
+
```
78
+
79
+
```lua
80
+
fori=1, 5doend
81
+
fori=1, 10, 2doend
82
+
fori=5, 1, -1doend
83
+
```
84
+
85
+
</SideBySide>
86
+
64
87
## Operator Map Types
65
88
66
89
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.
0 commit comments