Skip to content

Commit c04a12e

Browse files
committed
Add lualibImport require-minimal documentation and removed old deprecated annotations list
1 parent a11500f commit c04a12e

File tree

2 files changed

+16
-317
lines changed

2 files changed

+16
-317
lines changed

docs/advanced/compiler-annotations.md

Lines changed: 0 additions & 301 deletions
Original file line numberDiff line numberDiff line change
@@ -247,304 +247,3 @@ Indicates that functions in a file do not take in initial `self` argument when c
247247
This is annotation works the same as [@noSelf](#noself) being applied to a namespace, but affects the entire file.
248248

249249
`@noSelfInFile` must be placed at the top of the file, before the first statement.
250-
251-
## Deprecated
252-
253-
:::warning
254-
Some annotations are deprecated and will be/have been removed.
255-
Below are the deprecated annotations and instructions to recreate their behavior with vanilla TypeScript.
256-
:::
257-
258-
### @tupleReturn
259-
260-
<DeprecatedInVersion deprecated="0.42.0" removed="0.43.0" />
261-
262-
**Target elements:** `(declare) function`
263-
264-
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]> {
282-
return $multi(3, "4");
283-
}
284-
const [a, b] = myFunction();
285-
```
286-
287-
Lua output:
288-
289-
```lua
290-
function myFunction()
291-
return 3, "4"
292-
end
293-
local a, b = myFunction()
294-
```
295-
296-
### @extension
297-
298-
<DeprecatedInVersion deprecated="0.37.0" removed="0.39.0" />
299-
300-
**Target elements:** `class`
301-
302-
The Extension decorator marks a class as an extension of an already existing class.
303-
This causes the class header to not be translated, preventing instantiation and the override of the existing class.
304-
305-
**Upgrade Instructions**
306-
307-
Use an interface to extend your existing class and declare the table of the existing class as variable.
308-
309-
**Example**
310-
311-
<SideBySide>
312-
313-
```typescript
314-
interface ExistingClass {
315-
myFunction(): void;
316-
}
317-
318-
declare const ExistingClassTable: ExistingClass;
319-
320-
ExistingClassTable.myFunction = function () {};
321-
```
322-
323-
```lua
324-
function ExistingClassTable.myFunction(self) end
325-
```
326-
327-
</SideBySide>
328-
329-
### @metaExtension
330-
331-
<DeprecatedInVersion deprecated="0.37.0" removed="0.39.0" />
332-
333-
**Target elements:** `class`
334-
335-
The Extension decorator marks a class as an extension of an already existing meta class/table.
336-
This causes the class header to not be translated, preventing instantiation and the override of the existing class.
337-
338-
**Upgrade Instructions**
339-
340-
Use an interface to extend your existing class and assign the functions to the meta table of the existing class.
341-
342-
<SideBySide>
343-
344-
```typescript
345-
interface MyMetaClass {
346-
myFunction(): void;
347-
}
348-
349-
const MyMetaClassTable: MyMetaClass = debug.getregistry().MyMetaClass as MyMetaExtension;
350-
351-
MyMetaClassTable.myFunction = function () {};
352-
```
353-
354-
```lua
355-
MyMetaClassTable = debug.getregistry().MyMetaClass
356-
MyMetaClassTable.myFunction = function(self)
357-
end
358-
```
359-
360-
</SideBySide>
361-
362-
### @phantom
363-
364-
<DeprecatedInVersion deprecated="0.37.0" removed="0.39.0" />
365-
366-
**Target elements:** `namespace`
367-
368-
This decorator marks a namespace as a phantom namespace.
369-
This means all members of the namespace will be translated as if they were not in that namespace. Primarily used to prevent scoping issues.
370-
371-
**Upgrade instructions**
372-
373-
Use ECMAScript modules and import/export. Alternatively, use a real (non-phantom) namespace.
374-
375-
### @pureAbstract
376-
377-
<DeprecatedInVersion deprecated="0.37.0" removed="0.39.0" />
378-
379-
**Target elements:** `declare class`
380-
381-
This decorator marks a class declaration as purely abstract.
382-
The result is that any class extending the purely abstract class will not extend this class in the resulting Lua.
383-
384-
**Upgrade Instructions**
385-
386-
Try declaring the "classes" of your lua enviroment as interface.
387-
If that is not possible use interface merging as suggested below.
388-
389-
<SideBySide>
390-
391-
```typescript
392-
declare class MyAbstractClass {}
393-
interface MyClass extends MyAbstractClass {}
394-
395-
class MyClass {}
396-
```
397-
398-
```lua
399-
MyClass = __TS__Class()
400-
```
401-
402-
</SideBySide>
403-
404-
### @forRange
405-
406-
<DeprecatedInVersion deprecated="0.38.0" removed="0.40.0" />
407-
408-
**Target elements:** `declare function`
409-
410-
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.
417-
418-
<SideBySide>
419-
420-
<!-- prettier-ignore -->
421-
```typescript
422-
for (const i of $range(1, 10)) {}
423-
for (const i of $range(10, 1, -1)) {}
424-
```
425-
426-
```lua
427-
for i = 1, 10 do end
428-
for i = 10, 1, -1 do end
429-
```
430-
431-
</SideBySide>
432-
433-
### @luaIterator
434-
435-
<DeprecatedInVersion deprecated="0.38.1" removed="0.40.0" />
436-
437-
**Target elements:** `(declare) interface`
438-
439-
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-
declare function myIterator(): LuaIterable<string>;
450-
for (const s of myIterator()) {}
451-
```
452-
453-
```lua
454-
for s in myIterator() do end
455-
```
456-
457-
</SideBySide>
458-
459-
<SideBySide>
460-
461-
<!-- prettier-ignore -->
462-
```typescript
463-
declare namespace string {
464-
function gmatch(s: string, pattern: string): LuaIterable<LuaMultiReturn<string[]>>;
465-
}
466-
467-
for (const [a, b] of string.gmatch("foo", "(.)(.)")) {}
468-
```
469-
470-
```lua
471-
for a, b in string.gmatch("foo", "(.)(.)") do end
472-
```
473-
474-
</SideBySide>
475-
476-
### @luaTable
477-
478-
<DeprecatedInVersion deprecated="0.39.0" removed="0.40.0" />
479-
480-
**Target elements:** `type`
481-
482-
This annotation signals the transpiler to translate a class as a simple lua table for optimization purposes.
483-
484-
**Upgrade Instructions**
485-
486-
Use the [`LuaTable` language extension](language-extensions.md#lua-table-types) instead of a custom annotated type.
487-
488-
```ts
489-
const tbl = new LuaTable(); // local tbl = {}
490-
491-
const foo = {};
492-
tbl.set(foo, "bar"); // tbl[foo] = "bar"
493-
print(tbl.get(foo)); // print(tbl[foo])
494-
495-
tbl.set(1, "baz"); // tbl[1] = "baz"
496-
print(tbl.length()); // print(#tbl)
497-
```
498-
499-
### @vararg
500-
501-
<DeprecatedInVersion deprecated="0.39.0" removed="0.40.0" />
502-
503-
**Target elements:** `(declare) interface or type`
504-
505-
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-
function varargForward(...)
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-
function varargAccess(...)
543-
local args = {...}
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

Comments
 (0)