Skip to content

Commit f70577d

Browse files
authored
Upgrade tstl and make use of language-extensions instead of annotations (#22)
* Add release workflow * Upgraded to tstl language extensions * Add tsconfig to package * Fixed tests * Added 5.4 tests * prettier * Added reference to language extension types * Move language extensions reference to core
1 parent 0cd2a63 commit f70577d

22 files changed

+359
-166
lines changed

.github/workflows/release.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags: '*'
6+
7+
jobs:
8+
release:
9+
name: Release
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- uses: actions/checkout@v2
14+
- name: Use Node.js 12.13.1
15+
uses: actions/setup-node@v1
16+
with:
17+
node-version: 12.13.1
18+
registry-url: 'https://registry.npmjs.org'
19+
- run: npm ci
20+
- run: npm run build
21+
- run: npm publish
22+
env:
23+
NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}

core/coroutine.d.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,11 @@ declare namespace coroutine {
2424
* values passed to yield (when the coroutine yields) or any values returned
2525
* by the body function (when the coroutine terminates). If there is any
2626
* error, resume returns false plus the error message.
27-
* @tupleReturn
2827
*/
29-
function resume(co: LuaThread, ...val: any[]): [true, ...any[]] | [false, string];
28+
function resume(
29+
co: LuaThread,
30+
...val: any[]
31+
): LuaMultiReturn<[true, ...any[]] | [false, string]>;
3032

3133
/**
3234
* Returns the status of coroutine co, as a string: "running", if the
@@ -45,12 +47,11 @@ declare namespace coroutine {
4547
* same values returned by resume, except the first boolean. In case of error,
4648
* propagates the error.
4749
*/
48-
function wrap(f: (...args: any[]) => any): /** @tupleReturn */ (...args: any[]) => any[];
50+
function wrap(f: (...args: any[]) => any): (...args: any[]) => LuaMultiReturn<any[]>;
4951

5052
/**
5153
* Suspends the execution of the calling coroutine. Any arguments to yield are
5254
* passed as extra results to resume.
53-
* @tupleReturn
5455
*/
55-
function yield(...args: any[]): any[];
56+
function yield(...args: any[]): LuaMultiReturn<any[]>;
5657
}

core/debug.d.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,10 @@ declare namespace debug {
3232
* Returns the current hook settings of the thread, as three values: the
3333
* current hook function, the current hook mask, and the current hook count
3434
* (as set by the debug.sethook function).
35-
* @tupleReturn
3635
*/
37-
function gethook(thread?: LuaThread): [undefined, 0] | [Function, number, string?];
36+
function gethook(
37+
thread?: LuaThread
38+
): LuaMultiReturn<[undefined, 0] | [Function, number, string?]>;
3839

3940
interface FunctionInfo<T extends Function = Function> {
4041
/**
@@ -126,9 +127,8 @@ declare namespace debug {
126127
* Variable names starting with '(' (open parenthesis) represent variables
127128
* with no known names (variables from chunks saved without debug
128129
* information).
129-
* @tupleReturn
130130
*/
131-
function getupvalue(f: Function, up: number): [string, any] | [];
131+
function getupvalue(f: Function, up: number): LuaMultiReturn<[string, any] | []>;
132132

133133
/**
134134
* Returns the Lua value associated to u. If u is not a full userdata, returns

core/global.d.ts

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@
66

77
type LuaThread = { readonly __internal__: unique symbol };
88
type LuaUserdata = { readonly __internal__: unique symbol };
9-
/** @luaIterator */
10-
type LuaIterable<T> = Iterable<T> & { readonly __internal__: unique symbol };
11-
/** @luaIterator @tupleReturn */
12-
type LuaTupleIterable<T extends any[]> = Iterable<T> & { readonly __internal__: unique symbol };
139

1410
/**
1511
* A global variable (not a function) that holds a string containing the running
@@ -124,7 +120,7 @@ declare function getmetatable<T extends object>(object: T): LuaMetatable<T> | un
124120
* will iterate over the key–value pairs (1,t[1]), (2,t[2]), ..., up to the
125121
* first nil value.
126122
*/
127-
declare function ipairs<T>(t: Record<number, T>): LuaTupleIterable<[number, T]>;
123+
declare function ipairs<T>(t: Record<number, T>): LuaIterable<LuaMultiReturn<[number, T]>>;
128124

129125
/**
130126
* Allows a program to traverse all fields of a table. Its first argument is a
@@ -142,9 +138,8 @@ declare function ipairs<T>(t: Record<number, T>): LuaTupleIterable<[number, T]>;
142138
* The behavior of next is undefined if, during the traversal, you assign any
143139
* value to a non-existent field in the table. You may however modify existing
144140
* fields. In particular, you may clear existing fields.
145-
* @tupleReturn
146141
*/
147-
declare function next(table: object, index?: any): [any, any] | [];
142+
declare function next(table: object, index?: any): LuaMultiReturn<[any, any] | []>;
148143

149144
/**
150145
* If t has a metamethod __pairs, calls it with t as argument and returns the
@@ -158,7 +153,7 @@ declare function next(table: object, index?: any): [any, any] | [];
158153
* See function next for the caveats of modifying the table during its
159154
* traversal.
160155
*/
161-
declare function pairs<T>(t: T): LuaTupleIterable<[keyof T, T[keyof T]]>;
156+
declare function pairs<T>(t: T): LuaIterable<LuaMultiReturn<[keyof T, T[keyof T]]>>;
162157

163158
/**
164159
* Calls function f with the given arguments in protected mode. This means that
@@ -167,19 +162,17 @@ declare function pairs<T>(t: T): LuaTupleIterable<[keyof T, T[keyof T]]>;
167162
* is true if the call succeeds without errors. In such case, pcall also returns
168163
* all results from the call, after this first result. In case of any error,
169164
* pcall returns false plus the error message.
170-
* @tupleReturn
171165
*/
172166
declare function pcall<This, Args extends any[], R>(
173167
f: (this: This, ...args: Args) => R,
174168
context: This,
175169
...args: Args
176-
): [true, R] | [false, string];
170+
): LuaMultiReturn<[true, R] | [false, string]>;
177171

178-
/** @tupleReturn */
179172
declare function pcall<A extends any[], R>(
180173
f: (this: void, ...args: A) => R,
181174
...args: A
182-
): [true, R] | [false, string];
175+
): LuaMultiReturn<[true, R] | [false, string]>;
183176

184177
/**
185178
* Receives any number of arguments and prints their values to stdout, using the
@@ -222,9 +215,8 @@ declare function rawset<T extends object, K extends keyof T>(table: T, index: K,
222215
* negative number indexes from the end (-1 is the last argument). Otherwise,
223216
* index must be the string "#", and select returns the total number of extra
224217
* arguments it received.
225-
* @tupleReturn
226218
*/
227-
declare function select<T>(index: number, ...args: T[]): T[];
219+
declare function select<T>(index: number, ...args: T[]): LuaMultiReturn<T[]>;
228220

229221
/**
230222
* If index is a number, returns all arguments after argument number index; a

core/index.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/// <reference types="typescript-to-lua/language-extensions" />
2+
13
/// <reference path="./coroutine.d.ts" />
24
/// <reference path="./debug.d.ts" />
35
/// <reference path="./global.d.ts" />

core/io.d.ts

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,10 @@ declare namespace io {
6060
function lines<T extends FileReadFormat[]>(
6161
filename?: string,
6262
...formats: T
63-
): LuaTupleIterable<
64-
[] extends T ? [string] : { [P in keyof T]: T[P] extends 'n' ? number : string }
63+
): LuaIterable<
64+
LuaMultiReturn<
65+
[] extends T ? [string] : { [P in keyof T]: T[P] extends 'n' ? number : string }
66+
>
6567
>;
6668

6769
/**
@@ -80,9 +82,11 @@ declare namespace io {
8082
*
8183
* The mode string can also have a 'b' at the end, which is needed in some
8284
* systems to open the file in binary mode.
83-
* @tupleReturn
8485
*/
85-
function open(filename: string, mode?: string): [LuaFile] | [undefined, string, number];
86+
function open(
87+
filename: string,
88+
mode?: string
89+
): LuaMultiReturn<[LuaFile] | [undefined, string, number]>;
8690

8791
/**
8892
* Similar to io.input, but operates over the default output file.
@@ -100,7 +104,6 @@ declare namespace io {
100104

101105
/**
102106
* Equivalent to io.input():read(···).
103-
* @tupleReturn
104107
*/
105108
const read: LuaFile['read'];
106109

@@ -120,9 +123,8 @@ declare namespace io {
120123

121124
/**
122125
* Equivalent to io.output():write(···).
123-
* @tupleReturn
124126
*/
125-
function write(...args: (string | number)[]): [LuaFile] | [undefined, string];
127+
function write(...args: (string | number)[]): LuaMultiReturn<[LuaFile] | [undefined, string]>;
126128
}
127129

128130
interface LuaFile {
@@ -157,8 +159,10 @@ interface LuaFile {
157159
*/
158160
lines<T extends FileReadFormat[]>(
159161
...formats: T
160-
): LuaTupleIterable<
161-
[] extends T ? [string] : { [P in keyof T]: T[P] extends 'n' ? number : string }
162+
): LuaIterable<
163+
LuaMultiReturn<
164+
[] extends T ? [string] : { [P in keyof T]: T[P] extends 'n' ? number : string }
165+
>
162166
>;
163167

164168
/**
@@ -188,11 +192,10 @@ interface LuaFile {
188192
* string, or nil on end of file.
189193
*
190194
* The formats "l" and "L" should be used only for text files.
191-
* @tupleReturn
192195
*/
193196
read<T extends FileReadFormat[]>(
194197
...formats: T
195-
): { [P in keyof T]?: T[P] extends 'n' ? number : string };
198+
): LuaMultiReturn<{ [P in keyof T]?: T[P] extends 'n' ? number : string }>;
196199

197200
/**
198201
* Sets and geionts the file position, measured from the beginning of the
@@ -212,9 +215,11 @@ interface LuaFile {
212215
* the call file:seek("set") sets the position to the beginning of the file
213216
* (and returns 0); and the call file:seek("end") sets the position to the end
214217
* of the file, and returns its size.
215-
* @tupleReturn
216218
*/
217-
seek(whence?: 'set' | 'cur' | 'end', offset?: number): [number] | [undefined, string];
219+
seek(
220+
whence?: 'set' | 'cur' | 'end',
221+
offset?: number
222+
): LuaMultiReturn<[number] | [undefined, string]>;
218223

219224
/**
220225
* Sets the buffering mode for an output file. There are three available
@@ -237,7 +242,6 @@ interface LuaFile {
237242
*
238243
* In case of success, this function returns file. Otherwise it returns nil
239244
* plus a string describing the error.
240-
* @tupleReturn
241245
*/
242-
write(...args: (string | number)[]): [LuaFile] | [undefined, string];
246+
write(...args: (string | number)[]): LuaMultiReturn<[LuaFile] | [undefined, string]>;
243247
}

core/math.d.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,8 @@ declare namespace math {
7777
/**
7878
* Returns the integral part of x and the fractional part of x. Its second
7979
* result is always a float.
80-
* @tupleReturn
8180
*/
82-
function modf(x: number): [number, number];
81+
function modf(x: number): LuaMultiReturn<[number, number]>;
8382

8483
/**
8584
* The value of π.

core/os.d.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,17 +107,15 @@ declare namespace os {
107107
* Deletes the file (or empty directory, on POSIX systems) with the given
108108
* name. If this function fails, it returns nil, plus a string describing the
109109
* error and the error code. Otherwise, it returns true.
110-
* @tupleReturn
111110
*/
112-
function remove(filename: string): [true] | [undefined, string];
111+
function remove(filename: string): LuaMultiReturn<[true] | [undefined, string]>;
113112

114113
/**
115114
* Renames the file or directory named oldname to newname. If this function
116115
* fails, it returns nil, plus a string describing the error and the error
117116
* code. Otherwise, it returns true.
118-
* @tupleReturn
119117
*/
120-
function rename(oldname: string, newname: string): [true] | [undefined, string];
118+
function rename(oldname: string, newname: string): LuaMultiReturn<[true] | [undefined, string]>;
121119

122120
/**
123121
* Sets the current locale of the program. locale is a system-dependent string

core/string.d.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ declare namespace string {
2626
* Numeric codes are not necessarily portable across platforms.
2727
*/
2828
function byte(s: string, i?: number): number;
29-
/** @tupleReturn */
30-
function byte(s: string, i?: number, j?: number): number[];
29+
function byte(s: string, i?: number, j?: number): LuaMultiReturn<number[]>;
3130

3231
/**
3332
* Receives zero or more integers. Returns a string with length equal to the
@@ -57,14 +56,13 @@ declare namespace string {
5756
*
5857
* If the pattern has captures, then in a successful match the captured values
5958
* are also returned, after the two indices.
60-
* @tupleReturn
6159
*/
6260
function find(
6361
s: string,
6462
pattern: string,
6563
init?: number,
6664
plain?: boolean
67-
): [number, number, ...string[]] | [];
65+
): LuaMultiReturn<[number, number, ...string[]] | []>;
6866

6967
/**
7068
* Returns a formatted version of its variable number of arguments following
@@ -123,7 +121,7 @@ declare namespace string {
123121
* For this function, a caret '^' at the start of a pattern does not work as
124122
* an anchor, as this would prevent the iteration.
125123
*/
126-
function gmatch(s: string, pattern: string): LuaTupleIterable<string[]>;
124+
function gmatch(s: string, pattern: string): LuaIterable<LuaMultiReturn<string[]>>;
127125

128126
/**
129127
* Returns a copy of s in which all (or the first n, if given) occurrences of
@@ -151,14 +149,13 @@ declare namespace string {
151149
* string or a number, then it is used as the replacement string; otherwise,
152150
* if it is false or nil, then there is no replacement (that is, the original
153151
* match is kept in the string).
154-
* @tupleReturn
155152
*/
156153
function gsub(
157154
s: string,
158155
pattern: string,
159156
repl: string | Record<string, string> | ((...matches: string[]) => string),
160157
n?: number
161-
): [string, number];
158+
): LuaMultiReturn<[string, number]>;
162159

163160
/**
164161
* Receives a string and returns its length. The empty string "" has length 0.
@@ -179,9 +176,8 @@ declare namespace string {
179176
* returns nil. If pattern specifies no captures, then the whole match is
180177
* returned. A third, optional numeric argument init specifies where to start
181178
* the search; its default value is 1 and can be negative.
182-
* @tupleReturn
183179
*/
184-
function match(s: string, pattern: string, init?: number): string[];
180+
function match(s: string, pattern: string, init?: number): LuaMultiReturn<string[]>;
185181

186182
/**
187183
* Returns a string that is the string s reversed.

0 commit comments

Comments
 (0)