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
This decorator indicates a function returns a lua tuple instead of a table. It influences both destructing assignments of calls of that function, as well as changing the format of returns inside the function body.
265
-
266
-
**Upgrade Instructions**
267
-
268
-
Use the [`LuaMultiReturn` language extensions](language-extensions.md#luamultireturn-type) instead of a custom annotated types. This makes multi return usage type-safe and more obvious.
269
-
270
-
```typescript
271
-
/**@tupleReturn*/
272
-
function myFunction(): [number, string] {
273
-
return [3, "4"];
274
-
}
275
-
const [a, b] =myFunction();
276
-
```
277
-
278
-
Becomes:
279
-
280
-
```typescript
281
-
function myFunction():LuaMultiReturn<[number, string]> {
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.
411
-
412
-
The function should not be a real function and an error will be thrown if it is used in any other way.
413
-
414
-
**Upgrade Instructions**
415
-
416
-
Use the [`$range` language extension](language-extensions.md#$range-iterator-function) instead of a custom annotated type.
Denotes a type is a Lua iterator. When an object of a type with this annotation is used in a for...of statement, it will transpile directly as a lua iterator in a for...in statement, instead of being treated as a TypeScript iterable. Typically, this is used on an interface that extends `Iterable` or `Array` so that TypeScript will allow it to be used in a for...of statement.
440
-
441
-
**Upgrade Instructions**
442
-
443
-
Use the [`LuaIterable` and `LuaMultiReturn` language extensions](language-extensions.md#luaiterable-type) instead of a custom annotated types.
444
-
445
-
<SideBySide>
446
-
447
-
<!-- prettier-ignore -->
448
-
```typescript
449
-
declarefunction myIterator():LuaIterable<string>;
450
-
for (const s ofmyIterator()) {}
451
-
```
452
-
453
-
```lua
454
-
forsinmyIterator() doend
455
-
```
456
-
457
-
</SideBySide>
458
-
459
-
<SideBySide>
460
-
461
-
<!-- prettier-ignore -->
462
-
```typescript
463
-
declarenamespacestring {
464
-
function gmatch(s:string, pattern:string):LuaIterable<LuaMultiReturn<string[]>>;
465
-
}
466
-
467
-
for (const [a, b] ofstring.gmatch("foo", "(.)(.)")) {}
Indicates that an array-like type represents a Lua vararg expression (`...`) and should be transpiled to that when used in a spread expression. This is useful for forwarding varargs instead of wrapping them in a table and unpacking them.
506
-
507
-
**Upgrade Instructions**
508
-
509
-
`@vararg` is no longer required to prevent vararg parameters from being wrapped in a table. The ellipsis operator will now automatically be used if the parameter is used in a spread expression.
510
-
511
-
Example:
512
-
513
-
<SideBySide>
514
-
515
-
```ts
516
-
function varargForward(...args:string[]) {
517
-
console.log(...args);
518
-
}
519
-
```
520
-
521
-
```lua
522
-
functionvarargForward(...)
523
-
print(...)
524
-
end
525
-
```
526
-
527
-
</SideBySide>
528
-
529
-
However, if the parameter is accessed as an array or tuple, it will be wrapped in a table.
530
-
531
-
Example:
532
-
533
-
<SideBySide>
534
-
535
-
```ts
536
-
function varargAccess(...args:string[]) {
537
-
console.log(args[0]);
538
-
}
539
-
```
540
-
541
-
```lua
542
-
functionvarargAccess(...)
543
-
localargs= {...}
544
-
print(args[1])
545
-
end
546
-
```
547
-
548
-
</SideBySide>
549
-
550
-
Note that are a few cases where the parameter will still be wrapped in a table, even if a spread expression is used, in order to generate correctly functioning Lua.
0 commit comments