Skip to content

Commit bc44fdc

Browse files
committed
feat: add all unfinished TODO types
1 parent 8495765 commit bc44fdc

File tree

7 files changed

+30
-18
lines changed

7 files changed

+30
-18
lines changed

core/debug.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ declare namespace debug {
9797
/**
9898
* Returns the registry table (see §4.5).
9999
*/
100-
function getregistry(): __LUA_TODO__;
100+
function getregistry(): Record<string, any>;
101101

102102
/**
103103
* This function returns the name and the value of the upvalue with index up of the function f. The function returns nil if there is no upvalue with the given index.
@@ -174,10 +174,10 @@ declare namespace debug {
174174
*
175175
* These unique identifiers allow a program to check whether different closures share upvalues. Lua closures that share an upvalue (that is, that access a same external local variable) will return identical ids for those upvalue indices.
176176
*/
177-
function upvalueid(f: Function, n: number): __LUA_TODO__;
177+
function upvalueid(f: Function, n: number): LuaUserdata;
178178

179179
/**
180180
* Make the n1-th upvalue of the Lua closure f1 refer to the n2-th upvalue of the Lua closure f2.
181181
*/
182-
function upvaluejoin(f1: __LUA_TODO__, n1: number, f2: __LUA_TODO__, n2: number): __LUA_TODO__;
182+
function upvaluejoin(f1: Function, n1: number, f2: Function, n2: number): void;
183183
}

core/global.d.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
// Based on https://www.lua.org/manual/5.3/manual.html#6.1
22

3-
type __LUA_TODO__ = any;
43
type LuaThread = { readonly __internal__: unique symbol };
54
type LuaUserdata = { readonly __internal__: unique symbol };
65

76
/**
87
* A global variable (not a function) that holds the global environment (see §2.2). Lua itself does not use this variable; changing its value does not affect any environment, nor vice versa.
98
*/
10-
declare const _G: any;
9+
declare const _G: Record<string, any>;
1110

1211
/**
1312
* Calls error if the value of its argument v is false (i.e., nil or false); otherwise, returns all its arguments. In case of error, message is the error object; when absent, it defaults to "assertion failed!"

core/io.d.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,11 @@ declare namespace io {
3434
*
3535
* In case of errors this function raises the error, instead of returning an error code.
3636
*/
37-
function lines(...filename: string[]): () => __LUA_TODO__;
37+
function lines(): () => string;
38+
function lines<T extends FileReadFormat[]>(
39+
filename: string,
40+
...formats: T
41+
): /** @tupleReturn */ () => { [P in keyof T]?: T[P] extends 'n' ? number : string };
3842

3943
/**
4044
* This function opens a file, in the mode specified in the string mode. In case of success, it returns a new file handle.
@@ -67,8 +71,9 @@ declare namespace io {
6771

6872
/**
6973
* Equivalent to io.input():read(···).
74+
* @tupleReturn
7075
*/
71-
function read(...formats: FileReadFormat[]): __LUA_TODO__;
76+
const read: file['read'];
7277

7378
/**
7479
* In case of success, returns a handle for a temporary file. This file is opened in update mode and it is automatically removed when the program ends.
@@ -111,7 +116,9 @@ interface file {
111116
*
112117
* In case of errors this function raises the error, instead of returning an error code.
113118
*/
114-
lines(...formats: FileReadFormat[]): () => __LUA_TODO__;
119+
lines<T extends FileReadFormat[]>(
120+
...formats: T
121+
): /** @tupleReturn */ () => { [P in keyof T]?: T[P] extends 'n' ? number : string };
115122

116123
/**
117124
* Reads the file file, according to the given formats, which specify what to read. For each format, the function returns a string or a number with the characters read, or nil if it cannot read data with the specified format. (In this latter case, the function does not read subsequent formats.) When called without formats, it uses a default format that reads the next line (see below).
@@ -125,8 +132,11 @@ interface file {
125132
* * number: reads a string with up to this number of bytes, returning nil on end of file. If number is zero, it reads nothing and returns an empty string, or nil on end of file.
126133
*
127134
* The formats "l" and "L" should be used only for text files.
135+
* @tupleReturn
128136
*/
129-
read(...formats: FileReadFormat[]): __LUA_TODO__;
137+
read<T extends FileReadFormat[]>(
138+
...formats: T
139+
): { [P in keyof T]?: T[P] extends 'n' ? number : string };
130140

131141
/**
132142
* Sets and geionts the file position, measured from the beginning of the file, to the posit given by offset plus a base specified by the string whence, as follows:
@@ -158,5 +168,5 @@ interface file {
158168
* In case of success, this function returns file. Otherwise it returns nil plus a string describing the error.
159169
* @tupleReturn
160170
*/
161-
write(...args: (string | number)[]): [file] | [null, string];
171+
write(...args: (string | number)[]): [file] | [undefined, string];
162172
}

core/modules.d.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,17 @@ declare namespace package {
4343

4444
/**
4545
* Dynamically links the host program with the C library libname.
46-
46+
*
4747
* If funcname is "*", then it only links with the library, making the symbols exported by the library available to other dynamically linked libraries. Otherwise, it looks for a function funcname inside the library and returns this function as a C function. So, funcname must follow the lua_CFunction prototype (see lua_CFunction).
4848
*
4949
* This is a low-level function. It completely bypasses the package and module system. Unlike require, it does not perform any path searching and does not automatically adds extensions. libname must be the complete file name of the C library, including if necessary a path and an extension. funcname must be the exact name exported by the C library (which may depend on the C compiler and linker used).
5050
*
5151
* This function is not supported by Standard C. As such, it is only available on some platforms (Windows, Linux, Mac OS X, Solaris, BSD, plus other Unix systems that support the dlfcn standard).
5252
*/
53-
function loadlib(libname: string, funcname: string): __LUA_TODO__;
53+
function loadlib(
54+
libname: string,
55+
funcname: string,
56+
): [Function] | [undefined, string, 'open' | 'init'];
5457

5558
/**
5659
* The path used by require to search for a Lua loader.

core/string.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ declare namespace string {
7676
*
7777
* For this function, a caret '^' at the start of a pattern does not work as an anchor, as this would prevent the iteration.
7878
*/
79-
function gmatch(s: string, pattern: string): __LUA_TODO__;
79+
function gmatch(s: string, pattern: string): /** @tupleReturn */ () => string[];
8080

8181
/**
8282
* Returns a copy of s in which all (or the first n, if given) occurrences of the pattern (see §6.4.1) have been replaced by a replacement string specified by repl, which can be a string, a table, or a function. gsub also returns, as its second value, the total number of matches that occurred. The name gsub comes from Global SUBstitution.
@@ -106,7 +106,7 @@ declare namespace string {
106106
/**
107107
* Looks for the first match of pattern (see §6.4.1) in the string s. If it finds one, then match returns the captures from the pattern; otherwise it returns nil. If pattern specifies no captures, then the whole match is returned. A third, optional numeric argument init specifies where to start the search; its default value is 1 and can be negative.
108108
*/
109-
function match(s: string, pattern: string, init?: __LUA_TODO__): string | null;
109+
function match(s: string, pattern: string, init?: number): string | null;
110110

111111
/**
112112
* Returns a string that is the concatenation of n copies of the string s separated by the string sep. The default value for sep is the empty string (that is, no separator). Returns the empty string if n is not positive.

special/5.2-plus.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
declare var _ENV: any;
1+
declare let _ENV: Record<string, any>;
22

33
/**
44
* This function is a generic interface to the garbage collector. It performs different functions according to its first argument, opt.
@@ -27,7 +27,7 @@ declare function load(
2727
chunk: string | (() => string | null | undefined),
2828
chunkname?: string,
2929
mode?: 'b' | 't' | 'bt',
30-
env?: __LUA_TODO__,
30+
env?: object,
3131
): [() => any] | [undefined, string];
3232

3333
/**
@@ -37,7 +37,7 @@ declare function load(
3737
declare function loadfile(
3838
filename?: string,
3939
mode?: 'b' | 't' | 'bt',
40-
env?: __LUA_TODO__,
40+
env?: object,
4141
): [() => any] | [undefined, string];
4242

4343
/**

special/5.3-plus.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ declare namespace utf8 {
8484
*
8585
* will iterate over all characters in string s, with p being the position (in bytes) and c the code point of each character. It raises an error if it meets any invalid byte sequence.
8686
*/
87-
function codes(s: string): __LUA_TODO__;
87+
function codes<S extends string>(s: S): [(s: S, index?: number) => [number, number], S, 0];
8888

8989
/**
9090
* Returns the codepoints (as integers) from all characters in s that start between byte position i and j (both included). The default for i is 1 and for j is i. It raises an error if it meets any invalid byte sequence.

0 commit comments

Comments
 (0)