diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 90ad7fc..ee3ee5d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,10 +9,10 @@ jobs: steps: - uses: actions/checkout@v2 - - name: Use Node.js 12 + - name: Use Node.js 16 uses: actions/setup-node@v1 with: - node-version: 12 + node-version: 16 - run: npm ci - run: npm run lint @@ -22,9 +22,9 @@ jobs: steps: - uses: actions/checkout@v2 - - name: Use Node.js 12 + - name: Use Node.js 16 uses: actions/setup-node@v1 with: - node-version: 12 + node-version: 16 - run: npm ci - run: npm test diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index d4f55c0..7536a34 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -11,10 +11,10 @@ jobs: steps: - uses: actions/checkout@v2 - - name: Use Node.js 12.13.1 + - name: Use Node.js 16 uses: actions/setup-node@v1 with: - node-version: 12.13.1 + node-version: 16 registry-url: 'https://registry.npmjs.org' - run: npm ci - run: npm test diff --git a/.gitignore b/.gitignore index 1bbe32a..041b062 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ node_modules .vscode *.log +*.js +test/testproject/*.lua diff --git a/5.0.d.ts b/5.0.d.ts new file mode 100644 index 0000000..e67711d --- /dev/null +++ b/5.0.d.ts @@ -0,0 +1,2 @@ +/// +/// diff --git a/core/5.0/debug.d.ts b/core/5.0/debug.d.ts new file mode 100644 index 0000000..a0772a1 --- /dev/null +++ b/core/5.0/debug.d.ts @@ -0,0 +1,183 @@ +// Based on https://www.lua.org/manual/5.0/manual.html#5.8 + +/** @noSelfInFile */ + +/** + * This library provides the functionality of the debug interface (§4.9) to Lua + * programs. You should exert care when using this library. Several of its + * functions violate basic assumptions about Lua code (e.g., that variables + * local to a function cannot be accessed from outside; that userdata metatables + * cannot be changed by Lua code; that Lua programs do not crash) and therefore + * can compromise otherwise secure code. Moreover, some functions in this + * library may be slow. + * + * All functions in this library are provided inside the debug table. All + * functions that operate over a thread have an optional first argument which is + * the thread to operate over. The default is always the current thread. + */ +declare namespace debug { + /** + * Enters an interactive mode with the user, running each string that the user + * enters. Using simple commands and other debug facilities, the user can + * inspect global and local variables, change their values, evaluate + * expressions, and so on. A line containing only the word cont finishes this + * function, so that the caller continues its execution. + * + * Note that commands for debug.debug are not lexically nested within any + * function and so have no direct access to local variables. + */ + function debug(): void; + + interface FunctionInfo { + /** + * The function itself. + */ + func: T; + + /** + * A reasonable name for the function. + */ + name?: string; + /** + * What the `name` field means. The empty string means that Lua did not find + * a name for the function. + */ + namewhat: 'global' | 'local' | 'method' | 'field' | ''; + + source: string; + /** + * A short version of source (up to 60 characters), useful for error + * messages. + */ + short_src: string; + linedefined: number; + lastlinedefined: number; + /** + * What this function is. + */ + what: 'Lua' | 'C' | 'main'; + + currentline: number; + + /** + * Number of upvalues of that function. + */ + nups: number; + } + + /** + * Returns the current hook settings of the thread, as three values: the + * current hook function, the current hook mask, and the current hook count + * (as set by the debug.sethook function). + */ + function gethook(): LuaMultiReturn<[undefined, 0] | [Function, number, string?]>; + + /** + * Returns a table with information about a function. You can give the + * function directly or you can give a number as the value of f, which means + * the function running at level f of the call stack of the given thread: + * level 0 is the current function (getinfo itself); level 1 is the function + * that called getinfo (except for tail calls, which do not count on the + * stack); and so on. If f is a number larger than the number of active + * functions, then getinfo returns nil. + * + * The returned table can contain all the fields returned by lua_getinfo, with + * the string what describing which fields to fill in. The default for what is + * to get all information available, except the table of valid lines. If + * present, the option 'f' adds a field named func with the function itself. + * If present, the option 'L' adds a field named activelines with the table of + * valid lines. + * + * For instance, the expression debug.getinfo(1,"n").name returns a name for + * the current function, if a reasonable name can be found, and the expression + * debug.getinfo(print) returns a table with all available information about + * the print function. + */ + function getinfo(f: T): FunctionInfo; + function getinfo(f: T, what: string): Partial>; + function getinfo(f: number): FunctionInfo | undefined; + function getinfo(f: number, what: string): Partial | undefined; + + /** + * This function returns the name and the value of the local variable with + * index local of the function at level level of the stack. (The first + * parameter or local variable has index 1, and so on, until the last active + * local variable.) The function returns nil if there is no local variable + * with the given index, and raises an error when called with a level out of + * range. (You can call debug.getinfo to check whether the level is valid.) + */ + function getlocal(level: number, local: number): LuaMultiReturn<[string, any]>; + + /** + * 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. + * + * Variable names starting with '(' (open parenthesis) represent variables + * with no known names (variables from chunks saved without debug + * information). + */ + function getupvalue(f: Function, up: number): LuaMultiReturn<[string, any] | []>; + + /** + * Sets the given function as a hook. The string mask and the number count + * describe when the hook will be called. The string mask may have any + * combination of the following characters, with the given meaning: + * + * * 'c': the hook is called every time Lua calls a function; + * * 'r': the hook is called every time Lua returns from a function; + * * 'l': the hook is called every time Lua enters a new line of code. + * + * Moreover, with a count different from zero, the hook is called also after + * every count instructions. + * + * When called without arguments, debug.sethook turns off the hook. + * + * When the hook is called, its first parameter is a string describing the + * event that has triggered its call: "call" (or "tail call"), "return", + * "line", and "count". For line events, the hook also gets the new line + * number as its second parameter. Inside a hook, you can call getinfo with + * level 2 to get more information about the running function (level 0 is the + * getinfo function, and level 1 is the hook function). + */ + function sethook(): void; + function sethook( + hook: (event: 'call' | 'return' | 'line' | 'count', line?: number) => any, + mask: string, + count?: number + ): void; + + /** + * This function assigns the value value to the local variable with index + * local of the function at level level of the stack. The function returns nil + * if there is no local variable with the given index, and raises an error + * when called with a level out of range. (You can call getinfo to check + * whether the level is valid.) Otherwise, it returns the name of the local + * variable. + * + * See debug.getlocal for more information about variable indices and names. + */ + function setlocal(level: number, local: number, value: any): string | undefined; + + /** + * This function assigns the value value to the upvalue with index up of the + * function f. The function returns nil if there is no upvalue with the given + * index. Otherwise, it returns the name of the upvalue. + */ + function setupvalue(f: Function, up: number, value: any): string | undefined; + + /** + * Sets the given value as the Lua value associated to the given udata. udata + * must be a full userdata. + * + * Returns udata. + */ + function setuservalue(udata: LuaUserdata, value: any): LuaUserdata; + + /** + * Returns a string with a traceback of the call stack. An optional message + * string is appended at the beginning of the traceback. This function is + * typically used with xpcall to produce better error messages. + */ + function traceback(message?: string | null): string; +} diff --git a/core/5.0/global.d.ts b/core/5.0/global.d.ts new file mode 100644 index 0000000..b93aa0b --- /dev/null +++ b/core/5.0/global.d.ts @@ -0,0 +1,213 @@ +// Based on https://www.lua.org/manual/5.0/manual.html#5.1 + +/** @noSelfInFile */ + +type LuaThread = { readonly __internal__: unique symbol }; +type LuaUserdata = { readonly __internal__: unique symbol }; + +/** + * A global variable (not a function) that holds a string containing the running + * Lua version. + */ +declare const _VERSION: 'Lua 5.0' | 'Lua 5.0.1' | 'Lua 5.0.2' | 'Lua 5.0.3'; + +/** + * 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. + */ +declare const _G: typeof globalThis; + +/** + * 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!" + */ +declare function assert(v: V): Exclude; +declare function assert( + v: V, + ...args: A +): LuaMultiReturn<[Exclude, ...A]>; + +/** + * Opens the named file and executes its contents as a Lua chunk. When called + * without arguments, dofile executes the contents of the standard input + * (stdin). Returns all values returned by the chunk. In case of errors, dofile + * propagates the error to its caller (that is, dofile does not run in protected + * mode). + */ +declare function dofile(filename?: string): any; + +/** + * Terminates the last protected function called and returns message as the + * error object. Function error never returns. + * + * Usually, error adds some information about the error position at the + * beginning of the message, if the message is a string. The level argument + * specifies how to get the error position. With level 1 (the default), the + * error position is where the error function was called. Level 2 points the + * error to where the function that called error was called; and so on. Passing + * a level 0 avoids the addition of error position information to the message. + */ +declare function error(message: string, level?: number): never; + +/** + * If object does not have a metatable, returns nil. Otherwise, if the object's + * metatable has a __metatable field, returns the associated value. Otherwise, + * returns the metatable of the given object. + */ +declare function getmetatable(object: T): LuaMetatable | undefined; + +/** + * Returns three values (an iterator function, the table t, and 0) so that the + * construction + * + * `for i,v in ipairs(t) do body end` + * + * will iterate over the key–value pairs (1,t[1]), (2,t[2]), ..., up to the + * first nil value. + */ +declare function ipairs( + t: Record +): LuaIterable]>>; + +/** + * Allows a program to traverse all fields of a table. Its first argument is a + * table and its second argument is an index in this table. next returns the + * next index of the table and its associated value. When called with nil as its + * second argument, next returns an initial index and its associated value. When + * called with the last index, or with nil in an empty table, next returns nil. + * If the second argument is absent, then it is interpreted as nil. In + * particular, you can use next(t) to check whether a table is empty. + * + * The order in which the indices are enumerated is not specified, even for + * numeric indices. (To traverse a table in numerical order, use a numerical + * for.) + * + * The behavior of next is undefined if, during the traversal, you assign any + * value to a non-existent field in the table. You may however modify existing + * fields. In particular, you may clear existing fields. + */ +declare function next(table: object, index?: any): LuaMultiReturn<[any, any] | []>; + +/** + * If t has a metamethod __pairs, calls it with t as argument and returns the + * first three results from the call. Otherwise, returns three values: the next + * function, the table t, and nil, so that the construction + * + * `for k,v in pairs(t) do body end` + * + * will iterate over all key–value pairs of table t. + * + * See function next for the caveats of modifying the table during its + * traversal. + */ +declare function pairs( + t: LuaTable +): LuaIterable]>>; +declare function pairs(t: T): LuaIterable]>>; + +/** + * Calls function f with the given arguments in protected mode. This means that + * any error inside f is not propagated; instead, pcall catches the error and + * returns a status code. Its first result is the status code (a boolean), which + * is true if the call succeeds without errors. In such case, pcall also returns + * all results from the call, after this first result. In case of any error, + * pcall returns false plus the error message. + */ +declare function pcall( + f: (this: This, ...args: Args) => R, + context: This, + ...args: Args +): LuaMultiReturn<[true, R] | [false, string]>; + +declare function pcall( + f: (this: void, ...args: A) => R, + ...args: A +): LuaMultiReturn<[true, R] | [false, string]>; + +/** + * Receives any number of arguments and prints their values to stdout, using the + * tostring function to convert each argument to a string. print is not intended + * for formatted output, but only as a quick way to show a value, for instance + * for debugging. For complete control over the output, use string.format and + * io.write. + */ +declare function print(...args: any[]): void; + +/** + * Checks whether v1 is equal to v2, without invoking the __eq metamethod. + * Returns a boolean. + */ +declare function rawequal(v1: T, v2: T): boolean; + +/** + * Gets the real value of table[index], without invoking the __index metamethod. + * table must be a table; index may be any value. + */ +declare function rawget(table: T, index: K): T[K]; + +/** + * Sets the real value of table[index] to value, without invoking the __newindex + * metamethod. table must be a table, index any value different from nil and + * NaN, and value any Lua value. + * + * This function returns table. + */ +declare function rawset(table: T, index: K, value: T[K]): T; + +/** + * Sets the metatable for the given table. (To change the metatable of other + * types from Lua code, you must use the debug library (§6.10).) If metatable is + * nil, removes the metatable of the given table. If the original metatable has + * a __metatable field, raises an error. + * + * This function returns table. + */ +declare function setmetatable< + T extends object, + TIndex extends object | ((this: T, key: any) => any) | undefined = undefined +>( + table: T, + metatable?: LuaMetatable | null +): TIndex extends (this: T, key: infer TKey) => infer TValue + ? T & { [K in TKey & string]: TValue } + : TIndex extends object + ? T & TIndex + : T; + +/** + * When called with no base, tonumber tries to convert its argument to a number. + * If the argument is already a number or a string convertible to a number, then + * tonumber returns this number; otherwise, it returns nil. + * + * The conversion of strings can result in integers or floats, according to the + * lexical conventions of Lua (see §3.1). (The string may have leading and + * trailing spaces and a sign.) + * + * When called with base, then e must be a string to be interpreted as an + * integer numeral in that base. The base may be any integer between 2 and 36, + * inclusive. In bases above 10, the letter 'A' (in either upper or lower case) + * represents 10, 'B' represents 11, and so forth, with 'Z' representing 35. If + * the string e is not a valid numeral in the given base, the function returns + * nil. + */ +declare function tonumber(e: any, base?: number): number | undefined; + +/** + * Receives a value of any type and converts it to a string in a human-readable + * format. (For complete control of how numbers are converted, use + * string.format.) + * + * If the metatable of v has a __tostring field, then tostring calls the + * corresponding value with v as argument, and uses the result of the call as + * its result. + */ +declare function tostring(v: any): string; + +/** + * Returns the type of its only argument, coded as a string. + */ +declare function type( + v: any +): 'nil' | 'number' | 'string' | 'boolean' | 'table' | 'function' | 'thread' | 'userdata'; diff --git a/core/5.0/io.d.ts b/core/5.0/io.d.ts new file mode 100644 index 0000000..6109d6f --- /dev/null +++ b/core/5.0/io.d.ts @@ -0,0 +1,242 @@ +// Based on https://www.lua.org/manual/5.0/manual.html#5.6 + +/** @noSelfInFile */ + +/** + * The I/O library provides two different styles for file manipulation. The + * first one uses implicit file handles; that is, there are operations to set a + * default input file and a default output file, and all input/output operations + * are over these default files. The second style uses explicit file handles. + * + * When using implicit file handles, all operations are supplied by table io. + * When using explicit file handles, the operation io.open returns a file handle + * and then all operations are supplied as methods of the file handle. + * + * The table io also provides three predefined file handles with their usual + * meanings from C: io.stdin, io.stdout, and io.stderr. The I/O library never + * closes these files. + * + * Unless otherwise stated, all I/O functions return nil on failure (plus an + * error message as a second result and a system-dependent error code as a third + * result) and some value different from nil on success. On non-POSIX systems, + * the computation of the error message and error code in case of errors may be + * not thread safe, because they rely on the global C variable errno. + */ +declare namespace io { + /** + * Equivalent to file:close(). Without a file, closes the default output file. + */ + function close(file?: LuaFile): boolean; + + /** + * Equivalent to io.output():flush(). + */ + function flush(): boolean; + + /** + * When called with a file name, it opens the named file (in text mode), and + * sets its handle as the default input file. When called with a file handle, + * it simply sets this file handle as the default input file. When called + * without parameters, it returns the current default input file. + * + * In case of errors this function raises the error, instead of returning an + * error code. + */ + function input(file?: string | LuaFile): LuaFile; + + /** + * Opens the given file name in read mode and returns an iterator function + * that works like file:lines(···) over the opened file. When the iterator + * function detects the end of file, it returns no values (to finish the loop) + * and automatically closes the file. + * + * The call io.lines() (with no file name) is equivalent to + * io.input():lines("*l"); that is, it iterates over the lines of the default + * input file. In this case it does not close the file when the loop ends. + * + * In case of errors this function raises the error, instead of returning an + * error code. + */ + function lines( + filename?: string, + ...formats: T + ): LuaIterable< + LuaMultiReturn<[] extends T ? [string] : { [P in keyof T]: FileReadFormatToType }> + >; + + /** + * This function opens a file, in the mode specified in the string mode. In + * case of success, it returns a new file handle. + * + * The mode string can be any of the following: + * + * * "r": read mode (the default); + * * "w": write mode; + * * "a": append mode; + * * "r+": update mode, all previous data is preserved; + * * "w+": update mode, all previous data is erased; + * * "a+": append update mode, previous data is preserved, writing is only + * allowed at the end of file. + * + * The mode string can also have a 'b' at the end, which is needed in some + * systems to open the file in binary mode. + */ + function open( + filename: string, + mode?: string + ): LuaMultiReturn<[LuaFile] | [undefined, string, number]>; + + /** + * Similar to io.input, but operates over the default output file. + */ + function output(file?: string | LuaFile): LuaFile; + + /** + * Equivalent to io.input():read(···). + */ + function read(): io.FileReadFormatToType | undefined; + function read(format: T): io.FileReadFormatToType | undefined; + function read( + ...formats: T + ): LuaMultiReturn<{ [P in keyof T]?: io.FileReadFormatToType }>; + + /** + * Predefined file handle for standard error stream. The I/O library never closes this file. + */ + const stderr: LuaFile; + + /** + * Predefined file handle for standard input stream. The I/O library never closes this file. + */ + const stdin: LuaFile; + + /** + * Predefined file handle for standard output stream. The I/O library never closes this file. + */ + const stdout: LuaFile; + + /** + * 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. + */ + function tmpfile(): LuaFile; + + /** + * Checks whether obj is a valid file handle. Returns the string "file" if obj + * is an open file handle, "closed file" if obj is a closed file handle, or + * nil if obj is not a file handle. + */ + function type(obj: any): 'file' | 'closed file' | undefined; + + /** + * Equivalent to io.output():write(···). + */ + function write(...args: (string | number)[]): LuaMultiReturn<[LuaFile] | [undefined, string]>; + + type FileReadFormatToType = T extends FileReadNumberFormat ? number : string; +} + +interface LuaFile { + /** + * Closes file. Note that files are automatically closed when their handles + * are garbage collected, but that takes an unpredictable amount of time to + * happen. + * + * When closing a file handle created with io.popen, file:close returns the + * same values returned by os.execute. + */ + close(): boolean; + + /** + * Saves any written data to file. + */ + flush(): boolean; + + /** + * Returns an iterator function that, each time it is called, reads the file + * according to the given formats. When no format is given, uses "l" as a + * default. As an example, the construction + * + * `for c in file:lines(1) do body end` + * + * will iterate over all characters of the file, starting at the current + * position. Unlike io.lines, this function does not close the file when the + * loop ends. + * + * In case of errors this function raises the error, instead of returning an + * error code. + */ + lines( + ...formats: T + ): LuaIterable< + LuaMultiReturn<[] extends T ? [string] : { [P in keyof T]: io.FileReadFormatToType }> + >; + + /** + * 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). + * + * The available formats are + * + * * "n": reads a numeral and returns it as a float or an integer, following + * the lexical conventions of Lua. (The numeral may have leading spaces and + * a sign.) This format always reads the longest input sequence that is a + * valid prefix for a numeral; if that prefix does not form a valid numeral + * (e.g., an empty string, "0x", or "3.4e-"), it is discarded and the + * function returns nil. + * * "a": reads the whole file, starting at the current position. On end of + * file, it returns the empty string. + * * "l": reads the next line skipping the end of line, returning nil on end + * of file. This is the default format. + * * "L": reads the next line keeping the end-of-line character (if present), + * returning nil on end of file. + * * 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. + * + * The formats "l" and "L" should be used only for text files. + */ + read(): io.FileReadFormatToType | undefined; + read(format: T): io.FileReadFormatToType | undefined; + read( + ...formats: T + ): LuaMultiReturn<{ [P in keyof T]?: io.FileReadFormatToType }>; + + /** + * 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: + * + * * "set": base is position 0 (beginning of the file); + * * "cur": base is current position; + * * "end": base is end of file; + * + * In case of success, seek returns the final file position, measured in bytes + * from the beginning of the file. If seek fails, it returns nil, plus a + * string describing the error. + * + * The default value for whence is "cur", and for offset is 0. Therefore, the + * call file:seek() returns the current file position, without changing it; + * the call file:seek("set") sets the position to the beginning of the file + * (and returns 0); and the call file:seek("end") sets the position to the end + * of the file, and returns its size. + */ + seek( + whence?: 'set' | 'cur' | 'end', + offset?: number + ): LuaMultiReturn<[number] | [undefined, string]>; + + /** + * Writes the value of each of its arguments to file. The arguments must be + * strings or numbers. + * + * In case of success, this function returns file. Otherwise it returns nil + * plus a string describing the error. + */ + write(...args: (string | number)[]): LuaMultiReturn<[LuaFile] | [undefined, string]>; +} diff --git a/core/5.0/math.d.ts b/core/5.0/math.d.ts new file mode 100644 index 0000000..f52893b --- /dev/null +++ b/core/5.0/math.d.ts @@ -0,0 +1,152 @@ +// Based on https://www.lua.org/manual/5.0/manual.html#5.5 + +/** @noSelfInFile */ + +/** + * This library provides basic mathematical functions. It provides all its + * functions and constants inside the table math. Functions with the annotation + * "integer/float" give integer results for integer arguments and float results + * for float (or mixed) arguments. Rounding functions (math.ceil, math.floor, + * and math.modf) return an integer when the result fits in the range of an + * integer, or a float otherwise. + */ +declare namespace math { + /** + * Returns the absolute value of x. (integer/float) + */ + function abs(x: number): number; + + /** + * Returns the arc cosine of x (in radians). + */ + function acos(x: number): number; + + /** + * Returns the arc sine of x (in radians). + */ + function asin(x: number): number; + + /** + * Returns the arc tangent of x (in radians). + */ + function atan(x: number): number; + + /** + * Returns the arc tangent of y/x (in radians), but uses the signs of both + * parameters to find the quadrant of the result. (It also handles correctly + * the case of x being zero.) + */ + function atan2(y: number, x: number): number; + + /** + * Returns the smallest integral value larger than or equal to x. + */ + function ceil(x: number): number; + + /** + * Returns the cosine of x (assumed to be in radians). + */ + function cos(x: number): number; + + /** + * Converts the angle x from radians to degrees. + */ + function deg(x: number): number; + + /** + * Returns the value ex (where e is the base of natural logarithms). + */ + function exp(x: number): number; + + /** + * Returns the largest integral value smaller than or equal to x. + */ + function floor(x: number): number; + + /** + * Returns m and e such that x = m2e, e is an integer and the absolute value + * of m is in the range [0.5, 1) (or zero when x is zero). + */ + function frexp(x: number): number; + /** + * Returns m2e (e should be an integer). + */ + function ldexp(m: number, e: number): number; + + /** + * Returns the logarithm of x. + */ + function log(x: number): number; + + /** + * Returns the base-10 logarithm of x. + */ + function log10(x: number): number; + + /** + * Returns the argument with the maximum value, according to the Lua operator + * <. (integer/float) + */ + function max(x: number, ...numbers: number[]): number; + + /** + * Returns the argument with the minimum value, according to the Lua operator + * <. (integer/float) + */ + function min(x: number, ...numbers: number[]): number; + + /** + * Returns the remainder of the division of x by y that rounds the quotient + * towards zero. (integer/float) + */ + function mod(x: number, y: number): number; + + /** + * The value of π. + */ + const pi: number; + + /** + * Returns xy. (You can also use the expression x^y to compute this value.) + */ + function pow(x: number, y: number): number; + + /** + * Converts the angle x from degrees to radians. + */ + function rad(x: number): number; + + /** + * When called without arguments, returns a pseudo-random float with uniform + * distribution in the range [0,1). When called with two integers m and n, + * math.random returns a pseudo-random integer with uniform distribution in + * the range [m, n]. (The value n-m cannot be negative and must fit in a Lua + * integer.) The call math.random(n) is equivalent to math.random(1,n). + * + * This function is an interface to the underling pseudo-random generator + * function provided by C. + */ + function random(m?: number, n?: number): number; + + /** + * Sets x as the "seed" for the pseudo-random generator: equal seeds produce + * equal sequences of numbers. + */ + function randomseed(x: number): number; + + /** + * Returns the sine of x (assumed to be in radians). + */ + function sin(x: number): number; + + /** + * Returns the square root of x. (You can also use the expression x^0.5 to + * compute this value.) + */ + function sqrt(x: number): number; + + /** + * Returns the tangent of x (assumed to be in radians). + */ + function tan(x: number): number; +} diff --git a/core/5.0/metatable.d.ts b/core/5.0/metatable.d.ts new file mode 100644 index 0000000..f7a8a5b --- /dev/null +++ b/core/5.0/metatable.d.ts @@ -0,0 +1,151 @@ +// Based on https://www.lua.org/manual/5.0/manual.html#2.8 + +interface LuaMetatable< + T, + TIndex extends object | ((this: T, key: any) => any) | undefined = + | object + | ((this: T, key: any) => any) + | undefined +> { + /** + * the addition (+) operation. If any operand for an addition is not a number + * (nor a string coercible to a number), Lua will try to call a metamethod. + * First, Lua will check the first operand (even if it is valid). If that + * operand does not define a metamethod for __add, then Lua will check the + * second operand. If Lua can find a metamethod, it calls the metamethod with + * the two operands as arguments, and the result of the call (adjusted to one + * value) is the result of the operation. Otherwise, it raises an error. + */ + __add?(this: T, operand: any): any; + + /** + * the subtraction (-) operation. Behavior similar to the addition operation. + */ + __sub?(this: T, operand: any): any; + + /** + * the multiplication (*) operation. Behavior similar to the addition + * operation. + */ + __mul?(this: T, operand: any): any; + + /** + * the division (/) operation. Behavior similar to the addition operation. + */ + __div?(this: T, operand: any): any; + + /** + * the exponentiation (^) operation. Behavior similar to the addition + * operation. + */ + __pow?(this: T, operand: any): any; + + /** + * the negation (unary -) operation. Behavior similar to the addition + * operation. + */ + __unm?(this: T, operand: any): any; + + /** + * the concatenation (..) operation. Behavior similar to the addition + * operation, except that Lua will try a metamethod if any operand is neither + * a string nor a number (which is always coercible to a string). + */ + __concat?(this: T, operand: any): any; + + /** + * the equal (==) operation. Behavior similar to the addition operation, + * except that Lua will try a metamethod only when the values being compared + * are either both tables or both full userdata and they are not primitively + * equal. The result of the call is always converted to a boolean. + */ + __eq?(this: T, operand: any): boolean; + + /** + * the less than (<) operation. Behavior similar to the addition operation, + * except that Lua will try a metamethod only when the values being compared + * are neither both numbers nor both strings. The result of the call is always + * converted to a boolean. + */ + __lt?(this: T, operand: any): boolean; + + /** + * the less equal (<=) operation. Unlike other operations, the less-equal + * operation can use two different events. First, Lua looks for the __le + * metamethod in both operands, like in the less than operation. If it cannot + * find such a metamethod, then it will try the __lt metamethod, assuming that + * a <= b is equivalent to not (b < a). As with the other comparison + * operators, the result is always a boolean. (This use of the __lt event can + * be removed in future versions; it is also slower than a real __le + * metamethod.) + */ + __le?(this: T, operand: any): boolean; + + /** + * The indexing access table[key]. This event happens when table is not a + * table or when key is not present in table. The metamethod is looked up in + * table. + * + * Despite the name, the metamethod for this event can be either a function or + * a table. If it is a function, it is called with table and key as arguments, + * and the result of the call (adjusted to one value) is the result of the + * operation. If it is a table, the final result is the result of indexing + * this table with key. (This indexing is regular, not raw, and therefore can + * trigger another metamethod.) + */ + __index?: TIndex; + + /** + * The indexing assignment table[key] = value. Like the index event, this + * event happens when table is not a table or when key is not present in + * table. The metamethod is looked up in table. + * + * Like with indexing, the metamethod for this event can be either a function + * or a table. If it is a function, it is called with table, key, and value as + * arguments. If it is a table, Lua does an indexing assignment to this table + * with the same key and value. (This assignment is regular, not raw, and + * therefore can trigger another metamethod.) + * + * Whenever there is a __newindex metamethod, Lua does not perform the + * primitive assignment. (If necessary, the metamethod itself can call rawset + * to do the assignment.) + */ + __newindex?: object | ((this: T, key: any, value: any) => void); + + /** + * The call operation func(args). This event happens when Lua tries to call a + * non-function value (that is, func is not a function). The metamethod is + * looked up in func. If present, the metamethod is called with func as its + * first argument, followed by the arguments of the original call (args). All + * results of the call are the result of the operation. (This is the only + * metamethod that allows multiple results.) + */ + __call?(this: T, ...args: any[]): any; + + /** + * If the metatable of v has a __tostring field, then tostring calls the + * corresponding value with v as argument, and uses the result of the call as + * its result. + */ + __tostring?(this: T): string; + + /** + * If this field is a string containing the character 'k', the keys in the + * table are weak. If it contains 'v', the values in the table are weak. + */ + __mode?: 'k' | 'v' | 'kv'; + + /** + * If the object's metatable has this field, `getmetatable` returns the + * associated value. + */ + __metatable?: any; + + /** + * Userdata finalizer code. When userdata is set to be garbage collected, if + * the metatable has a __gc field pointing to a function, that function is + * first invoked, passing the userdata to it. The __gc metamethod is not + * called for tables. + */ + __gc?(this: T): void; +} diff --git a/core/5.0/modules.d.ts b/core/5.0/modules.d.ts new file mode 100644 index 0000000..dfadafa --- /dev/null +++ b/core/5.0/modules.d.ts @@ -0,0 +1,46 @@ +// Based on https://www.lua.org/manual/5.0/manual.html#5.1 + +/** @noSelfInFile */ + +/** + * Links the program with the dynamic C library libname. Inside this library, + * looks for a function funcname and returns this function as a C function. + * + * libname must be the complete file name of the C library, including any + * eventual path and extension. + * + * This function is not supported by ANSI C. As such, it is only available on + * some platforms (Windows, Linux, Solaris, BSD, plus other Unix systems that + * support the dlfcn standard). + */ +declare function loadlib(libname: string, funcname: string): undefined | Function; + +/** + * Loads the given module. The function starts by looking into the + * package.loaded table to determine whether modname is already loaded. If it + * is, then require returns the value stored at package.loaded[modname]. + * Otherwise, it tries to find a loader for the module. + * + * To find a loader, require is guided by the package.searchers sequence. By + * changing this sequence, we can change how require looks for a module. The + * following explanation is based on the default configuration for + * package.searchers. + * + * First require queries package.preload[modname]. If it has a value, this value + * (which must be a function) is the loader. Otherwise require searches for a + * Lua loader using the path stored in package.path. If that also fails, it + * searches for a C loader using the path stored in package.cpath. If that also + * fails, it tries an all-in-one loader (see package.searchers). + * + * Once a loader is found, require calls the loader with two arguments: modname + * and an extra value dependent on how it got the loader. (If the loader came + * from a file, this extra value is the file name.) If the loader returns any + * non-nil value, require assigns the returned value to package.loaded[modname]. + * If the loader does not return a non-nil value and has not assigned any value + * to package.loaded[modname], then require assigns true to this entry. In any + * case, require returns the final value of package.loaded[modname]. + * + * If there is any error loading or running the module, or if it cannot find any + * loader for the module, then require raises an error. + */ +declare function require(modname: string): any; diff --git a/core/5.0/os.d.ts b/core/5.0/os.d.ts new file mode 100644 index 0000000..3508daa --- /dev/null +++ b/core/5.0/os.d.ts @@ -0,0 +1,213 @@ +// Based on https://www.lua.org/manual/5.0/manual.html#5.7 + +/** @noSelfInFile */ + +interface LuaDateInfo { + year: number; + month: number; + day: number; + hour?: number; + min?: number; + sec?: number; + isdst?: boolean; +} + +interface LuaDateInfoResult { + year: number; + month: number; + day: number; + hour: number; + min: number; + sec: number; + isdst: boolean; + yday: number; + wday: number; +} + +/** + * Operating System Facilities + */ +declare namespace os { + /** + * Returns an approximation of the amount in seconds of CPU time used by the + * program. + */ + function clock(): number; + + /** + * Returns a string or a table containing date and time, formatted according + * to the given string format. + * + * If the time argument is present, this is the time to be formatted (see the + * os.time function for a description of this value). Otherwise, date formats + * the current time. + * + * If format starts with '!', then the date is formatted in Coordinated + * Universal Time. After this optional character, if format is the string + * "*t", then date returns a table with the following fields: year, month + * (1–12), day (1–31), hour (0–23), min (0–59), sec (0–61), wday (weekday, + * 1–7, Sunday is 1), yday (day of the year, 1–366), and isdst (daylight + * saving flag, a boolean). This last field may be absent if the information + * is not available. + * + * If format is not "*t", then date returns the date as a string, formatted + * according to the same rules as the ISO C function strftime. + * + * When called without arguments, date returns a reasonable date and time + * representation that depends on the host system and on the current locale. + * (More specifically, os.date() is equivalent to os.date("%c").) + * + * On non-POSIX systems, this function may be not thread safe because of its + * reliance on C function gmtime and C function localtime. + */ + function date(format?: string, time?: number): string; + + /** + * Returns a string or a table containing date and time, formatted according + * to the given string format. + * + * If the time argument is present, this is the time to be formatted (see the + * os.time function for a description of this value). Otherwise, date formats + * the current time. + * + * If format starts with '!', then the date is formatted in Coordinated + * Universal Time. After this optional character, if format is the string + * "*t", then date returns a table with the following fields: year, month + * (1–12), day (1–31), hour (0–23), min (0–59), sec (0–61), wday (weekday, + * 1–7, Sunday is 1), yday (day of the year, 1–366), and isdst (daylight + * saving flag, a boolean). This last field may be absent if the information + * is not available. + * + * If format is not "*t", then date returns the date as a string, formatted + * according to the same rules as the ISO C function strftime. + * + * When called without arguments, date returns a reasonable date and time + * representation that depends on the host system and on the current locale. + * (More specifically, os.date() is equivalent to os.date("%c").) + * + * On non-POSIX systems, this function may be not thread safe because of its + * reliance on C function gmtime and C function localtime. + */ + function date(format: '*t', time?: number): LuaDateInfoResult; + + /** + * Returns the difference, in seconds, from time t1 to time t2 (where the + * times are values returned by os.time). In POSIX, Windows, and some other + * systems, this value is exactly t2-t1. + */ + function difftime(t1: number, t2: number): number; + + /** + * This function is equivalent to the C function system. It passes command to + * be executed by an operating system shell. It returns a status code, which + * is system-dependent. If command is absent, then it returns nonzero if a + * shell is available and zero otherwise. + */ + function execute(command?: string): number; + + /** + * Calls the C function exit, with an optional code, to terminate the host + * program. The default value for code is the success code. + */ + function exit(code?: number): never; + + /** + * Returns the value of the process environment variable varname, or nil if + * the variable is not defined. + */ + function getenv(varname: string): string | undefined; + + /** + * Deletes the file (or empty directory, on POSIX systems) with the given + * name. If this function fails, it returns nil, plus a string describing the + * error and the error code. Otherwise, it returns true. + */ + function remove(filename: string): LuaMultiReturn<[true] | [undefined, string]>; + + /** + * Renames the file or directory named oldname to newname. If this function + * fails, it returns nil, plus a string describing the error and the error + * code. Otherwise, it returns true. + */ + function rename(oldname: string, newname: string): LuaMultiReturn<[true] | [undefined, string]>; + + /** + * Sets the current locale of the program. locale is a system-dependent string + * specifying a locale; category is an optional string describing which + * category to change: "all", "collate", "ctype", "monetary", "numeric", or + * "time"; the default category is "all". The function returns the name of the + * new locale, or nil if the request cannot be honored. + * + * If locale is the empty string, the current locale is set to an + * implementation-defined native locale. If locale is the string "C", the + * current locale is set to the standard C locale. + * + * When called with nil as the first argument, this function only returns the + * name of the current locale for the given category. + * + * This function may be not thread safe because of its reliance on C function + * setlocale. + */ + function setlocale( + locale?: string, + category?: 'all' | 'collate' | 'ctype' | 'monetary' | 'numeric' | 'time' + ): string | undefined; + + /** + * Returns the current time when called without arguments, or a time + * representing the local date and time specified by the given table. This + * table must have fields year, month, and day, and may have fields hour + * (default is 12), min (default is 0), sec (default is 0), and isdst (default + * is nil). Other fields are ignored. For a description of these fields, see + * the os.date function. + * + * The values in these fields do not need to be inside their valid ranges. For + * instance, if sec is -10, it means -10 seconds from the time specified by + * the other fields; if hour is 1000, it means +1000 hours from the time + * specified by the other fields. + * + * The returned value is a number, whose meaning depends on your system. In + * POSIX, Windows, and some other systems, this number counts the number of + * seconds since some given start time (the "epoch"). In other systems, the + * meaning is not specified, and the number returned by time can be used only + * as an argument to os.date and os.difftime. + */ + function time(): number; + + /** + * Returns the current time when called without arguments, or a time + * representing the local date and time specified by the given table. This + * table must have fields year, month, and day, and may have fields hour + * (default is 12), min (default is 0), sec (default is 0), and isdst (default + * is nil). Other fields are ignored. For a description of these fields, see + * the os.date function. + * + * The values in these fields do not need to be inside their valid ranges. For + * instance, if sec is -10, it means -10 seconds from the time specified by + * the other fields; if hour is 1000, it means +1000 hours from the time + * specified by the other fields. + * + * The returned value is a number, whose meaning depends on your system. In + * POSIX, Windows, and some other systems, this number counts the number of + * seconds since some given start time (the "epoch"). In other systems, the + * meaning is not specified, and the number returned by time can be used only + * as an argument to os.date and os.difftime. + */ + function time(table: LuaDateInfo): number; + + /** + * Returns a string with a file name that can be used for a temporary file. + * The file must be explicitly opened before its use and explicitly removed + * when no longer needed. + * + * On POSIX systems, this function also creates a file with that name, to + * avoid security risks. (Someone else might create the file with wrong + * permissions in the time between getting the name and creating the file.) + * You still have to open the file to use it and to remove it (even if you do + * not use it). + * + * When possible, you may prefer to use io.tmpfile, which automatically + * removes the file when the program ends. + */ + function tmpname(): string; +} diff --git a/core/5.0/string.d.ts b/core/5.0/string.d.ts new file mode 100644 index 0000000..c46a756 --- /dev/null +++ b/core/5.0/string.d.ts @@ -0,0 +1,196 @@ +// Based on https://www.lua.org/manual/5.0/manual.html#5.3 + +/** @noSelfInFile */ + +/** + * This library provides generic functions for string manipulation, such as + * finding and extracting substrings, and pattern matching. When indexing a + * string in Lua, the first character is at position 1 (not at 0, as in C). + * Indices are allowed to be negative and are interpreted as indexing backwards, + * from the end of the string. Thus, the last character is at position -1, and + * so on. + * + * The string library provides all its functions inside the table string. It + * also sets a metatable for strings where the __index field points to the + * string table. Therefore, you can use the string functions in object-oriented + * style. For instance, string.byte(s,i) can be written as s:byte(i). + * + * The string library assumes one-byte character encodings. + */ +declare namespace string { + /** + * Returns the internal numerical code of the i-th character of s, or nil if + * the index is out of range. If i is absent, then it is assumed to be 1. i + * may be negative. + * + * Note that numerical codes are not necessarily portable across platforms. + */ + function byte(s: string, i?: number): number; + + /** + * Receives zero or more integers. Returns a string with length equal to the + * number of arguments, in which each character has the internal numeric code + * equal to its corresponding argument. + * + * Numeric codes are not necessarily portable across platforms. + */ + function char(...args: number[]): string; + + /** + * Returns a string containing a binary representation of the given function, + * so that a later load on this string returns a copy of the function (but + * with new upvalues). + */ + function dump(func: Function): string; + + /** + * Looks for the first match of pattern (see §6.4.1) in the string s. If it + * finds a match, then find returns the indices of s where this occurrence + * starts and ends; otherwise, it returns nil. A third, optional numeric + * argument init specifies where to start the search; its default value is 1 + * and can be negative. A value of true as a fourth, optional argument plain + * turns off the pattern matching facilities, so the function does a plain + * "find substring" operation, with no characters in pattern being considered + * magic. Note that if plain is given, then init must be given as well. + * + * If the pattern has captures, then in a successful match the captured values + * are also returned, after the two indices. + */ + function find( + s: string, + pattern: string, + init?: number, + plain?: boolean + ): LuaMultiReturn<[number, number, ...string[]] | []>; + + /** + * Returns a formatted version of its variable number of arguments following + * the description given in its first argument (which must be a string). The + * format string follows the same rules as the ISO C function sprintf. The + * only differences are that the options/modifiers *, h, L, l, n, and p are + * not supported and that there is an extra option, q. + * + * The q option formats a string between double quotes, using escape sequences + * when necessary to ensure that it can safely be read back by the Lua + * interpreter. For instance, the call + * + * `string.format('%q', 'a string with "quotes" and \n new line')` + * + * may produce the string: + * + * `"a string with \"quotes\" and \ + * new line"` Options A, a, E, e, f, G, and g all expect a number as + * argument. Options c, d, i, o, u, X, and x expect an integer. When Lua is + * compiled with a C89 compiler, options A and a (hexadecimal floats) do not + * support any modifier (flags, width, length). + * + * Option s expects a string; if its argument is not a string, it is converted + * to one following the same rules of tostring. If the option has any modifier + * (flags, width, length), the string argument should not contain embedded + * zeros. + */ + function format(formatstring: string, ...args: any[]): string; + + /** + * Returns an iterator function that, each time it is called, returns the + * next captures from pattern pat over string s. + * + * If pat specifies no captures, then the whole match is produced in each + * call. + * + * As an example, the following loop + * + * ``` + * s = "hello world from Lua" + * for w in string.gfind(s, "%a+") do + * print(w) + * end + * ``` + * + * will iterate over all the words from string s, printing one per line. The + * next example collects all pairs key=value from the given string into a + * table: + * + * ``` + * t = {} + * s = "from=world, to=Lua" + * for k, v in string.gfind(s, "(%w+)=(%w+)") do + * t[k] = v + * end + * ``` + */ + function gfind(s: string, pattern: string): LuaIterable>; + + /** + * 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. + * + * If repl is a string, then its value is used for replacement. The character + * % works as an escape character: any sequence in repl of the form %d, with d + * between 1 and 9, stands for the value of the d-th captured substring. The + * sequence %0 stands for the whole match. The sequence %% stands for a single + * %. + * + * If repl is a table, then the table is queried for every match, using the + * first capture as the key. + * + * If repl is a function, then this function is called every time a match + * occurs, with all captured substrings passed as arguments, in order. + * + * In any case, if the pattern specifies no captures, then it behaves as if + * the whole pattern was inside a capture. + * + * If the value returned by the table query or by the function call is a + * string or a number, then it is used as the replacement string; otherwise, + * if it is false or nil, then there is no replacement (that is, the original + * match is kept in the string). + */ + function gsub( + s: string, + pattern: string, + repl: string | Record | ((...matches: string[]) => string), + n?: number + ): LuaMultiReturn<[string, number]>; + + /** + * Receives a string and returns its length. The empty string "" has length 0. + * Embedded zeros are counted, so "a\000bc\000" has length 5. + */ + function len(s: string): number; + + /** + * Receives a string and returns a copy of this string with all uppercase + * letters changed to lowercase. All other characters are left unchanged. The + * definition of what an uppercase letter is depends on the current locale. + */ + function lower(s: string): string; + + /** + * Returns a string that is the concatenation of `n` copies of the string `s`. + */ + function rep(s: string, n: number): string; + + /** + * Returns the substring of s that starts at i and continues until j; i and j + * can be negative. If j is absent, then it is assumed to be equal to -1 + * (which is the same as the string length). In particular, the call + * string.sub(s,1,j) returns a prefix of s with length j, and string.sub(s, + * -i) (for a positive i) returns a suffix of s with length i. + * + * If, after the translation of negative indices, i is less than 1, it is + * corrected to 1. If j is greater than the string length, it is corrected to + * that length. If, after these corrections, i is greater than j, the function + * returns the empty string. + */ + function sub(s: string, i: number, j?: number): string; + + /** + * Receives a string and returns a copy of this string with all lowercase + * letters changed to uppercase. All other characters are left unchanged. The + * definition of what a lowercase letter is depends on the current locale. + */ + function upper(s: string): string; +} diff --git a/core/5.0/table.d.ts b/core/5.0/table.d.ts new file mode 100644 index 0000000..e367f1e --- /dev/null +++ b/core/5.0/table.d.ts @@ -0,0 +1,94 @@ +// Based on https://www.lua.org/manual/5.0/manual.html#5.4 + +/** @noSelfInFile */ + +/** + * This library provides generic functions for table manipulation. It provides + * all its functions inside the table table. + * + * Remember that, whenever an operation needs the length of a table, all caveats + * about the length operator apply (see §3.4.7). All functions ignore + * non-numeric keys in the tables given as arguments. + */ +declare namespace table { + /** + * Given a list where all elements are strings or numbers, returns the string + * list[i]..sep..list[i+1] ··· sep..list[j]. The default value for sep is the + * empty string, the default for i is 1, and the default for j is #list. If i + * is greater than j, returns the empty string. + */ + function concat(list: (string | number)[], sep?: string, i?: number, j?: number): string; + + /** + * Executes the given f over all elements of table. For each element, f is + * called with the index and respective value as arguments. If f returns a + * non-nil value, then the loop is broken, and this value is returned as the + * final value of foreach. + * + * See the next function for extra information about table traversals. + */ + function foreach(table: object, f: (index: any, value: any) => any): any; + + /** + * Executes the given f over the numerical indices of table. For each index, + * f is called with the index and respective value as arguments. Indices are + * visited in sequential order, from 1 to n, where n is the size of the + * table (see 5.4). If f returns a non-nil value, then the loop is broken + * and this value is returned as the result of foreachi. + */ + function foreachi(table: object, f: (index: number, value: any) => any): any; + + /** + * Returns the size of a table, when seen as a list. If the table has an n + * field with a numeric value, this value is the size of the table. + * Otherwise, if there was a previous call to table.setn over this table, + * the respective value is returned. Otherwise, the size is one less the + * first integer index with a nil value. + */ + function getn(table: object): number; + + /** + * Inserts element value at position pos in list, shifting up the elements + * list[pos], list[pos+1], ···, list[#list]. The default value for pos is + * #list+1, so that a call table.insert(t,x) inserts x at the end of list t. + */ + function insert(list: T[], value: T): void; + function insert(list: T[], pos: number, value: T): void; + + /** + * Removes from list the element at position pos, returning the value of the + * removed element. When pos is an integer between 1 and #list, it shifts down + * the elements list[pos+1], list[pos+2], ···, list[#list] and erases element + * list[#list]; The index pos can also be 0 when #list is 0, or #list + 1; in + * those cases, the function erases the element list[pos]. + * + * The default value for pos is #list, so that a call table.remove(l) removes + * the last element of list l. + */ + function remove(list: T[], pos?: number): T | undefined; + + /** + * Updates the size of a table. If the table has a field "n" with a + * numerical value, that value is changed to the given n. Otherwise, it + * updates an internal state so that subsequent calls to table.getn(table) + * return n. + */ + function setn(table: object, n: number): void; + + /** + * Sorts list elements in a given order, in-place, from list[1] to + * list[#list]. If comp is given, then it must be a function that receives two + * list elements and returns true when the first element must come before the + * second in the final order (so that, after the sort, i < j implies not + * comp(list[j],list[i])). If comp is not given, then the standard Lua + * operator < is used instead. + * + * Note that the comp function must define a strict partial order over the + * elements in the list; that is, it must be asymmetric and transitive. + * Otherwise, no valid sort may be possible. + * + * The sort algorithm is not stable: elements considered equal by the given + * order may have their relative positions changed by the sort. + */ + function sort(list: T[], comp?: (a: T, b: T) => boolean): void; +} diff --git a/core/global.d.ts b/core/global.d.ts index e8652c1..f80de47 100644 --- a/core/global.d.ts +++ b/core/global.d.ts @@ -11,7 +11,12 @@ type LuaUserdata = { readonly __internal__: unique symbol }; * A global variable (not a function) that holds a string containing the running * Lua version. */ -declare const _VERSION: 'Lua 5.1' | 'Lua 5.2' | 'Lua 5.3' | 'Lua 5.4'; +declare const _VERSION: + | ('Lua 5.0' | 'Lua 5.0.1' | 'Lua 5.0.2' | 'Lua 5.0.3') + | 'Lua 5.1' + | 'Lua 5.2' + | 'Lua 5.3' + | 'Lua 5.4'; /** * A global variable (not a function) that holds the global environment (see @@ -159,7 +164,7 @@ declare function next(table: object, index?: any): LuaMultiReturn<[any, any] | [ * See function next for the caveats of modifying the table during its * traversal. */ -declare function pairs( +declare function pairs( t: LuaTable ): LuaIterable]>>; declare function pairs(t: T): LuaIterable]>>; diff --git a/core/index-5.0.d.ts b/core/index-5.0.d.ts new file mode 100644 index 0000000..0cc083b --- /dev/null +++ b/core/index-5.0.d.ts @@ -0,0 +1,12 @@ +/// + +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// diff --git a/core/index.d.ts b/core/index.d.ts index 6d73c6a..96d49da 100644 --- a/core/index.d.ts +++ b/core/index.d.ts @@ -1,4 +1,4 @@ -/// +/// /// /// diff --git a/package-lock.json b/package-lock.json index e8f967b..a823693 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,23 +1,23 @@ { "name": "lua-types", - "version": "2.11.0", + "version": "2.13.1", "lockfileVersion": 2, "requires": true, "packages": { "": { - "version": "2.11.0", + "name": "lua-types", + "version": "2.13.1", "license": "MIT", "devDependencies": { "@types/jest": "^26.0.20", "@types/node": "^14.14.34", + "@typescript-to-lua/language-extensions": "^1.0.0", "jest": "^26.6.3", "jest-circus": "^26.6.3", "prettier": "^2.0.5", "ts-jest": "^26.5.3", - "typescript-to-lua": "^1.0.1" - }, - "peerDependencies": { - "typescript-to-lua": "^1.0.0" + "typescript": "4.7.3", + "typescript-to-lua": "^1.9.0" } }, "node_modules/@babel/code-frame": { @@ -952,6 +952,12 @@ "integrity": "sha512-37RSHht+gzzgYeobbG+KWryeAW8J33Nhr69cjTqSYymXVZEN9NbRYWoYlRtDhHKPVT1FyNKwaTPC1NynKZpzRA==", "dev": true }, + "node_modules/@typescript-to-lua/language-extensions": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/@typescript-to-lua/language-extensions/-/language-extensions-1.0.0.tgz", + "integrity": "sha512-GtmhFqyg+txpGgGLM3mlS3R6AEG9MQhKALxxcbr6SBzg9u7YAXcPKqUBaBYd6nH+Pi/eQLcWz4BNOLhz8v4TjQ==", + "dev": true + }, "node_modules/abab": { "version": "2.0.5", "resolved": "https://registry.npmjs.org/abab/-/abab-2.0.5.tgz", @@ -1033,9 +1039,9 @@ } }, "node_modules/ansi-regex": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.0.tgz", - "integrity": "sha512-bY6fj56OUQ0hU1KjFNDQuJFezqKdrAyFdIevADiqrWHwSlbmBNMHp5ak2f40Pm8JTFyM2mqxkG6ngkHO11f/lg==", + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", + "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", "dev": true, "engines": { "node": ">=8" @@ -1933,9 +1939,9 @@ } }, "node_modules/enhanced-resolve": { - "version": "5.8.2", - "resolved": "https://registry.npmjs.org/enhanced-resolve/-/enhanced-resolve-5.8.2.tgz", - "integrity": "sha512-F27oB3WuHDzvR2DOGNTaYy0D5o0cnrv8TeI482VM4kYgQd/FT9lUQwuNsJ0oOHtBUq7eiW5ytqzp7nBFknL+GA==", + "version": "5.10.0", + "resolved": "https://registry.npmjs.org/enhanced-resolve/-/enhanced-resolve-5.10.0.tgz", + "integrity": "sha512-T0yTFjdpldGY8PmuXXR0PyQ1ufZpEGiHVrp7zHKB7jdR4qlmZHhONVM5AQOAWXuF/w3dnHbEQVrNptJgt7F+cQ==", "dev": true, "dependencies": { "graceful-fs": "^4.2.4", @@ -3708,9 +3714,9 @@ "dev": true }, "node_modules/json-schema": { - "version": "0.2.3", - "resolved": "https://registry.npmjs.org/json-schema/-/json-schema-0.2.3.tgz", - "integrity": "sha1-tIDIkuWaLwWVTOcnvT8qTogvnhM=", + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/json-schema/-/json-schema-0.4.0.tgz", + "integrity": "sha512-es94M3nTIfsEPisRafak+HDLfHXnKBhV3vU5eqPcS3flIWqcxJWgXHXiey3YrpaNsanY5ei1VoYEbOzijuq9BA==", "dev": true }, "node_modules/json-schema-traverse": { @@ -3741,18 +3747,18 @@ } }, "node_modules/jsprim": { - "version": "1.4.1", - "resolved": "https://registry.npmjs.org/jsprim/-/jsprim-1.4.1.tgz", - "integrity": "sha1-MT5mvB5cwG5Di8G3SZwuXFastqI=", + "version": "1.4.2", + "resolved": "https://registry.npmjs.org/jsprim/-/jsprim-1.4.2.tgz", + "integrity": "sha512-P2bSOMAc/ciLz6DzgjVlGJP9+BrJWu5UDGK70C2iweC5QBIeFf0ZXRvGjEj2uYgrY2MkAAhsSWHDWlFtEroZWw==", "dev": true, - "engines": [ - "node >=0.6.0" - ], "dependencies": { "assert-plus": "1.0.0", "extsprintf": "1.3.0", - "json-schema": "0.2.3", + "json-schema": "0.4.0", "verror": "1.10.0" + }, + "engines": { + "node": ">=0.6.0" } }, "node_modules/kind-of": { @@ -3950,9 +3956,9 @@ } }, "node_modules/minimist": { - "version": "1.2.5", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz", - "integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==", + "version": "1.2.6", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.6.tgz", + "integrity": "sha512-Jsjnk4bw3YJqYzbdyBiNsPWHPfO++UGG749Cxs6peCu5Xg4nrena6OVxOYxrQTqww0Jmwt+Ref8rggumkTLz9Q==", "dev": true }, "node_modules/mixin-deep": { @@ -5823,9 +5829,9 @@ "dev": true }, "node_modules/tmpl": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/tmpl/-/tmpl-1.0.4.tgz", - "integrity": "sha1-I2QN17QtAEM5ERQIIOXPRA5SHdE=", + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/tmpl/-/tmpl-1.0.5.tgz", + "integrity": "sha512-3f0uOEAQwIqGuWW2MVzYg8fV/QNnc/IpuJNG837rLuczAaLVHslWHZQj4IGiEl5Hs3kkbhwL9Ab7Hrsmuj+Smw==", "dev": true }, "node_modules/to-fast-properties": { @@ -6018,9 +6024,9 @@ } }, "node_modules/typescript": { - "version": "4.3.5", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.3.5.tgz", - "integrity": "sha512-DqQgihaQ9cUrskJo9kIyW/+g0Vxsk8cDtZ52a3NGh0YNTfpUSArXSohyUGnvbPazEPLu398C0UxmKSOrPumUzA==", + "version": "4.7.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.7.3.tgz", + "integrity": "sha512-WOkT3XYvrpXx4vMMqlD+8R8R37fZkjyLGlxavMc4iB8lrl8L0DeTcHbYgw/v0N/z9wAFsgBhcsF0ruoySS22mA==", "dev": true, "bin": { "tsc": "bin/tsc", @@ -6031,22 +6037,23 @@ } }, "node_modules/typescript-to-lua": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/typescript-to-lua/-/typescript-to-lua-1.0.1.tgz", - "integrity": "sha512-j5mb+8HgUUY8hhAKoNy6KUMeamEN1fsTtMvSbPaxmVkWw40pHdLi3umsQG+Qo7wM6IK+RQffFxbIWEjleF+xpw==", + "version": "1.9.0", + "resolved": "https://registry.npmjs.org/typescript-to-lua/-/typescript-to-lua-1.9.0.tgz", + "integrity": "sha512-Oj8kutP1u/TSjN9oGUuESfOL+feHMSs7CCxl90C60jWTH+4ZXLtrXlRJTalA3Z2/aHjQXXgPaXQStSXBzAYLow==", "dev": true, - "license": "MIT", "dependencies": { "enhanced-resolve": "^5.8.2", "resolve": "^1.15.1", - "source-map": "^0.7.3", - "typescript": "~4.3.5" + "source-map": "^0.7.3" }, "bin": { "tstl": "dist/tstl.js" }, "engines": { "node": ">=12.13.0" + }, + "peerDependencies": { + "typescript": "~4.7.3" } }, "node_modules/union-value": { @@ -7239,6 +7246,12 @@ "integrity": "sha512-37RSHht+gzzgYeobbG+KWryeAW8J33Nhr69cjTqSYymXVZEN9NbRYWoYlRtDhHKPVT1FyNKwaTPC1NynKZpzRA==", "dev": true }, + "@typescript-to-lua/language-extensions": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/@typescript-to-lua/language-extensions/-/language-extensions-1.0.0.tgz", + "integrity": "sha512-GtmhFqyg+txpGgGLM3mlS3R6AEG9MQhKALxxcbr6SBzg9u7YAXcPKqUBaBYd6nH+Pi/eQLcWz4BNOLhz8v4TjQ==", + "dev": true + }, "abab": { "version": "2.0.5", "resolved": "https://registry.npmjs.org/abab/-/abab-2.0.5.tgz", @@ -7297,9 +7310,9 @@ } }, "ansi-regex": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.0.tgz", - "integrity": "sha512-bY6fj56OUQ0hU1KjFNDQuJFezqKdrAyFdIevADiqrWHwSlbmBNMHp5ak2f40Pm8JTFyM2mqxkG6ngkHO11f/lg==", + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", + "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", "dev": true }, "ansi-styles": { @@ -8009,9 +8022,9 @@ } }, "enhanced-resolve": { - "version": "5.8.2", - "resolved": "https://registry.npmjs.org/enhanced-resolve/-/enhanced-resolve-5.8.2.tgz", - "integrity": "sha512-F27oB3WuHDzvR2DOGNTaYy0D5o0cnrv8TeI482VM4kYgQd/FT9lUQwuNsJ0oOHtBUq7eiW5ytqzp7nBFknL+GA==", + "version": "5.10.0", + "resolved": "https://registry.npmjs.org/enhanced-resolve/-/enhanced-resolve-5.10.0.tgz", + "integrity": "sha512-T0yTFjdpldGY8PmuXXR0PyQ1ufZpEGiHVrp7zHKB7jdR4qlmZHhONVM5AQOAWXuF/w3dnHbEQVrNptJgt7F+cQ==", "dev": true, "requires": { "graceful-fs": "^4.2.4", @@ -9394,9 +9407,9 @@ "dev": true }, "json-schema": { - "version": "0.2.3", - "resolved": "https://registry.npmjs.org/json-schema/-/json-schema-0.2.3.tgz", - "integrity": "sha1-tIDIkuWaLwWVTOcnvT8qTogvnhM=", + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/json-schema/-/json-schema-0.4.0.tgz", + "integrity": "sha512-es94M3nTIfsEPisRafak+HDLfHXnKBhV3vU5eqPcS3flIWqcxJWgXHXiey3YrpaNsanY5ei1VoYEbOzijuq9BA==", "dev": true }, "json-schema-traverse": { @@ -9421,14 +9434,14 @@ } }, "jsprim": { - "version": "1.4.1", - "resolved": "https://registry.npmjs.org/jsprim/-/jsprim-1.4.1.tgz", - "integrity": "sha1-MT5mvB5cwG5Di8G3SZwuXFastqI=", + "version": "1.4.2", + "resolved": "https://registry.npmjs.org/jsprim/-/jsprim-1.4.2.tgz", + "integrity": "sha512-P2bSOMAc/ciLz6DzgjVlGJP9+BrJWu5UDGK70C2iweC5QBIeFf0ZXRvGjEj2uYgrY2MkAAhsSWHDWlFtEroZWw==", "dev": true, "requires": { "assert-plus": "1.0.0", "extsprintf": "1.3.0", - "json-schema": "0.2.3", + "json-schema": "0.4.0", "verror": "1.10.0" } }, @@ -9582,9 +9595,9 @@ } }, "minimist": { - "version": "1.2.5", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz", - "integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==", + "version": "1.2.6", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.6.tgz", + "integrity": "sha512-Jsjnk4bw3YJqYzbdyBiNsPWHPfO++UGG749Cxs6peCu5Xg4nrena6OVxOYxrQTqww0Jmwt+Ref8rggumkTLz9Q==", "dev": true }, "mixin-deep": { @@ -11062,9 +11075,9 @@ "dev": true }, "tmpl": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/tmpl/-/tmpl-1.0.4.tgz", - "integrity": "sha1-I2QN17QtAEM5ERQIIOXPRA5SHdE=", + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/tmpl/-/tmpl-1.0.5.tgz", + "integrity": "sha512-3f0uOEAQwIqGuWW2MVzYg8fV/QNnc/IpuJNG837rLuczAaLVHslWHZQj4IGiEl5Hs3kkbhwL9Ab7Hrsmuj+Smw==", "dev": true }, "to-fast-properties": { @@ -11209,21 +11222,20 @@ } }, "typescript": { - "version": "4.3.5", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.3.5.tgz", - "integrity": "sha512-DqQgihaQ9cUrskJo9kIyW/+g0Vxsk8cDtZ52a3NGh0YNTfpUSArXSohyUGnvbPazEPLu398C0UxmKSOrPumUzA==", + "version": "4.7.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.7.3.tgz", + "integrity": "sha512-WOkT3XYvrpXx4vMMqlD+8R8R37fZkjyLGlxavMc4iB8lrl8L0DeTcHbYgw/v0N/z9wAFsgBhcsF0ruoySS22mA==", "dev": true }, "typescript-to-lua": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/typescript-to-lua/-/typescript-to-lua-1.0.1.tgz", - "integrity": "sha512-j5mb+8HgUUY8hhAKoNy6KUMeamEN1fsTtMvSbPaxmVkWw40pHdLi3umsQG+Qo7wM6IK+RQffFxbIWEjleF+xpw==", + "version": "1.9.0", + "resolved": "https://registry.npmjs.org/typescript-to-lua/-/typescript-to-lua-1.9.0.tgz", + "integrity": "sha512-Oj8kutP1u/TSjN9oGUuESfOL+feHMSs7CCxl90C60jWTH+4ZXLtrXlRJTalA3Z2/aHjQXXgPaXQStSXBzAYLow==", "dev": true, "requires": { "enhanced-resolve": "^5.8.2", "resolve": "^1.15.1", - "source-map": "^0.7.3", - "typescript": "~4.3.5" + "source-map": "^0.7.3" } }, "union-value": { diff --git a/package.json b/package.json index d6c3c3b..8b8472d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "lua-types", - "version": "2.11.0", + "version": "2.13.1", "description": "TypeScript definitions for Lua standard library", "keywords": [ "lua", @@ -14,7 +14,8 @@ "**/*.d.ts" ], "scripts": { - "test": "jest", + "test": "jest && npm run test:test-project", + "test:test-project": "npm --prefix test/testproject ci && npm --prefix test/testproject run build", "lint": "prettier --check ." }, "prettier": { @@ -23,9 +24,6 @@ "proseWrap": "never", "singleQuote": true }, - "peerDependencies": { - "typescript-to-lua": "^1.0.0" - }, "devDependencies": { "@types/jest": "^26.0.20", "@types/node": "^14.14.34", @@ -33,6 +31,11 @@ "jest-circus": "^26.6.3", "prettier": "^2.0.5", "ts-jest": "^26.5.3", - "typescript-to-lua": "^1.0.1" + "typescript": "4.7.3", + "typescript-to-lua": "^1.9.0", + "@typescript-to-lua/language-extensions": "^1.0.0" + }, + "peer-dependencies": { + "@typescript-to-lua/language-extensions": "^1.0.0" } } diff --git a/special/5.0.d.ts b/special/5.0.d.ts new file mode 100644 index 0000000..253f3ee --- /dev/null +++ b/special/5.0.d.ts @@ -0,0 +1,89 @@ +/** @noSelfInFile */ + +/** + * Sets the garbage-collection threshold to the given limit (in Kbytes) and + * checks it against the byte counter. If the new threshold is smaller than the + * byte counter, then Lua immediately runs the garbage collector (see 2.9). If + * limit is absent, it defaults to zero (thus forcing a garbage-collection + * cycle). + */ +declare function collectgarbage(limit: number): void; + +/** + * Similar to load, but gets the chunk from file filename or from the standard + * input, if no file name is given. + */ +declare function loadfile(filename?: string): LuaMultiReturn<[() => any] | [undefined, string]>; + +/** + * Similar to load, but gets the chunk from the given string. + * + * To load and run a given string, use the idiom + * + * `assert(loadstring(s))()` + * + * When absent, chunkname defaults to the given string. + */ +declare function loadstring( + string: string, + chunkname?: string +): LuaMultiReturn<[() => any] | [undefined, string]>; + +/** + * Returns all elements from the given list. This function is equivalent to + * + * `return list[1], list[2], ..., list[n]` + * + * except that the above code can be written only for a fixed n. The number n is + * the size of the list, as defined for the table.getn function. + */ +declare function unpack(list: T): LuaMultiReturn; + +/** + * Returns two results: the number of Kbytes of dynamic memory that Lua is using + * and the current garbage collector threshold (also in Kbytes). + */ +declare function gcinfo(): LuaMultiReturn<[number, number]>; + +/** + * Returns the current environment in use by the function. f can be a Lua + * function or a number that specifies the function at that stack level: Level 1 + * is the function calling getfenv. If the given function is not a Lua function, + * or if f is 0, getfenv returns the global environment. The default for f is 1. + */ +declare function getfenv(f?: Function | number): any; + +declare namespace io { + type FileReadNumberFormat = '*n'; + type FileReadLineFormat = '*l'; + type FileReadFormat = FileReadNumberFormat | FileReadLineFormat | '*a' | number; +} + +/** + * Sets the environment to be used by the given function. f can be a Lua + * function or a number that specifies the function at that stack level: Level 1 + * is the function calling setfenv. setfenv returns the given function. + * + * As a special case, when f is 0 setfenv changes the environment of the running + * thread. In this case, setfenv returns no values. + */ +declare function setfenv(f: T, table: object): T; +declare function setfenv(f: 0, table: object): Function; +declare function setfenv(f: number, table: object): void; + +/** + * This function is similar to pcall, except that it sets a new message handler + * msgh. + * + * xpcall calls function f in protected mode, using err as the error handler. + * Any error inside f is not propagated; instead, xpcall catches the error, + * calls the err function with the original error object, and returns a status + * code. Its first result is the status code (a boolean), which is true if the + * call succeeds without errors. In this case, xpcall also returns all results + * from the call, after this first result. In case of any error, xpcall returns + * false plus the result from err. + */ +declare function xpcall( + f: () => R, + err: (err: any) => E +): LuaMultiReturn<[true, R] | [false, E]>; diff --git a/test/__snapshots__/global.spec.ts.snap b/test/__snapshots__/global.spec.ts.snap index a20d2fa..bbfe81b 100644 --- a/test/__snapshots__/global.spec.ts.snap +++ b/test/__snapshots__/global.spec.ts.snap @@ -71,11 +71,7 @@ exports[`Lua version 5.1 / global pcall with context 1`] = ` exports[`Lua version 5.1 / global rawget 1`] = `"value = rawget({foo = \\"bar\\"}, \\"foo\\")"`; -exports[`Lua version 5.1 / global select 1`] = ` -"values = { - select(2, \\"a\\", \\"b\\", \\"c\\") -}" -`; +exports[`Lua version 5.1 / global select 1`] = `"values = {select(2, \\"a\\", \\"b\\", \\"c\\")}"`; exports[`Lua version 5.1 / global select destructured 1`] = `"b, c = select(2, \\"a\\", \\"b\\", \\"c\\")"`; @@ -84,9 +80,7 @@ exports[`Lua version 5.1 / global select with # 1`] = `"count = select(\\"#\\", exports[`Lua version 5.1 / global setmetatable with function index 1`] = ` "tbl = setmetatable( {}, - { - __index = function(____, key) return key .. \\"bar\\" end - } + {__index = function(____, key) return key .. \\"bar\\" end} ) takesStr = function(____, s) end @@ -181,11 +175,7 @@ exports[`Lua version 5.2 / global pcall with context 1`] = ` exports[`Lua version 5.2 / global rawget 1`] = `"value = rawget({foo = \\"bar\\"}, \\"foo\\")"`; -exports[`Lua version 5.2 / global select 1`] = ` -"values = { - select(2, \\"a\\", \\"b\\", \\"c\\") -}" -`; +exports[`Lua version 5.2 / global select 1`] = `"values = {select(2, \\"a\\", \\"b\\", \\"c\\")}"`; exports[`Lua version 5.2 / global select destructured 1`] = `"b, c = select(2, \\"a\\", \\"b\\", \\"c\\")"`; @@ -194,9 +184,7 @@ exports[`Lua version 5.2 / global select with # 1`] = `"count = select(\\"#\\", exports[`Lua version 5.2 / global setmetatable with function index 1`] = ` "tbl = setmetatable( {}, - { - __index = function(____, key) return key .. \\"bar\\" end - } + {__index = function(____, key) return key .. \\"bar\\" end} ) takesStr = function(____, s) end @@ -291,11 +279,7 @@ exports[`Lua version 5.3 / global pcall with context 1`] = ` exports[`Lua version 5.3 / global rawget 1`] = `"value = rawget({foo = \\"bar\\"}, \\"foo\\")"`; -exports[`Lua version 5.3 / global select 1`] = ` -"values = { - select(2, \\"a\\", \\"b\\", \\"c\\") -}" -`; +exports[`Lua version 5.3 / global select 1`] = `"values = {select(2, \\"a\\", \\"b\\", \\"c\\")}"`; exports[`Lua version 5.3 / global select destructured 1`] = `"b, c = select(2, \\"a\\", \\"b\\", \\"c\\")"`; @@ -304,9 +288,7 @@ exports[`Lua version 5.3 / global select with # 1`] = `"count = select(\\"#\\", exports[`Lua version 5.3 / global setmetatable with function index 1`] = ` "tbl = setmetatable( {}, - { - __index = function(____, key) return key .. \\"bar\\" end - } + {__index = function(____, key) return key .. \\"bar\\" end} ) takesStr = function(____, s) end @@ -401,11 +383,7 @@ exports[`Lua version 5.4 / global pcall with context 1`] = ` exports[`Lua version 5.4 / global rawget 1`] = `"value = rawget({foo = \\"bar\\"}, \\"foo\\")"`; -exports[`Lua version 5.4 / global select 1`] = ` -"values = { - select(2, \\"a\\", \\"b\\", \\"c\\") -}" -`; +exports[`Lua version 5.4 / global select 1`] = `"values = {select(2, \\"a\\", \\"b\\", \\"c\\")}"`; exports[`Lua version 5.4 / global select destructured 1`] = `"b, c = select(2, \\"a\\", \\"b\\", \\"c\\")"`; @@ -414,9 +392,7 @@ exports[`Lua version 5.4 / global select with # 1`] = `"count = select(\\"#\\", exports[`Lua version 5.4 / global setmetatable with function index 1`] = ` "tbl = setmetatable( {}, - { - __index = function(____, key) return key .. \\"bar\\" end - } + {__index = function(____, key) return key .. \\"bar\\" end} ) takesStr = function(____, s) end @@ -511,11 +487,7 @@ exports[`Lua version JIT / global pcall with context 1`] = ` exports[`Lua version JIT / global rawget 1`] = `"value = rawget({foo = \\"bar\\"}, \\"foo\\")"`; -exports[`Lua version JIT / global select 1`] = ` -"values = { - select(2, \\"a\\", \\"b\\", \\"c\\") -}" -`; +exports[`Lua version JIT / global select 1`] = `"values = {select(2, \\"a\\", \\"b\\", \\"c\\")}"`; exports[`Lua version JIT / global select destructured 1`] = `"b, c = select(2, \\"a\\", \\"b\\", \\"c\\")"`; @@ -524,9 +496,7 @@ exports[`Lua version JIT / global select with # 1`] = `"count = select(\\"#\\", exports[`Lua version JIT / global setmetatable with function index 1`] = ` "tbl = setmetatable( {}, - { - __index = function(____, key) return key .. \\"bar\\" end - } + {__index = function(____, key) return key .. \\"bar\\" end} ) takesStr = function(____, s) end diff --git a/test/__snapshots__/io.spec.ts.snap b/test/__snapshots__/io.spec.ts.snap index e44aaf4..7d8f79b 100644 --- a/test/__snapshots__/io.spec.ts.snap +++ b/test/__snapshots__/io.spec.ts.snap @@ -98,11 +98,7 @@ exports[`Lua version 5.1 / io stdout 1`] = `"io.stdout:write(\\"foobar\\")"`; exports[`Lua version 5.1 / io tmpfile 1`] = `"file = io.tmpfile()"`; -exports[`Lua version 5.1 / io type 1`] = ` -"print( - io.type(file) -)" -`; +exports[`Lua version 5.1 / io type 1`] = `"print(io.type(file))"`; exports[`Lua version 5.1 / io write 1`] = `"f, err = io.write(\\"foobar\\")"`; @@ -204,11 +200,7 @@ exports[`Lua version 5.2 / io stdout 1`] = `"io.stdout:write(\\"foobar\\")"`; exports[`Lua version 5.2 / io tmpfile 1`] = `"file = io.tmpfile()"`; -exports[`Lua version 5.2 / io type 1`] = ` -"print( - io.type(file) -)" -`; +exports[`Lua version 5.2 / io type 1`] = `"print(io.type(file))"`; exports[`Lua version 5.2 / io write 1`] = `"f, err = io.write(\\"foobar\\")"`; @@ -310,11 +302,7 @@ exports[`Lua version 5.3 / io stdout 1`] = `"io.stdout:write(\\"foobar\\")"`; exports[`Lua version 5.3 / io tmpfile 1`] = `"file = io.tmpfile()"`; -exports[`Lua version 5.3 / io type 1`] = ` -"print( - io.type(file) -)" -`; +exports[`Lua version 5.3 / io type 1`] = `"print(io.type(file))"`; exports[`Lua version 5.3 / io write 1`] = `"f, err = io.write(\\"foobar\\")"`; @@ -416,11 +404,7 @@ exports[`Lua version 5.4 / io stdout 1`] = `"io.stdout:write(\\"foobar\\")"`; exports[`Lua version 5.4 / io tmpfile 1`] = `"file = io.tmpfile()"`; -exports[`Lua version 5.4 / io type 1`] = ` -"print( - io.type(file) -)" -`; +exports[`Lua version 5.4 / io type 1`] = `"print(io.type(file))"`; exports[`Lua version 5.4 / io write 1`] = `"f, err = io.write(\\"foobar\\")"`; @@ -522,10 +506,6 @@ exports[`Lua version JIT / io stdout 1`] = `"io.stdout:write(\\"foobar\\")"`; exports[`Lua version JIT / io tmpfile 1`] = `"file = io.tmpfile()"`; -exports[`Lua version JIT / io type 1`] = ` -"print( - io.type(file) -)" -`; +exports[`Lua version JIT / io type 1`] = `"print(io.type(file))"`; exports[`Lua version JIT / io write 1`] = `"f, err = io.write(\\"foobar\\")"`; diff --git a/test/__snapshots__/string.spec.ts.snap b/test/__snapshots__/string.spec.ts.snap index 38517fc..0bc6d11 100644 --- a/test/__snapshots__/string.spec.ts.snap +++ b/test/__snapshots__/string.spec.ts.snap @@ -6,17 +6,9 @@ exports[`Lua version 5.1 / string string.byte multiple 1`] = `"a, b, c, d = stri exports[`Lua version 5.1 / string string.char 1`] = `"str = string.char(64, 65, 66)"`; -exports[`Lua version 5.1 / string string.dump 1`] = ` -"str = string.dump( - function() return 5 end -)" -`; +exports[`Lua version 5.1 / string string.dump 1`] = `"str = string.dump(function() return 5 end)"`; -exports[`Lua version 5.1 / string string.find 1`] = ` -"result = { - string.find(\\"abc\\", \\"b\\") -}" -`; +exports[`Lua version 5.1 / string string.find 1`] = `"result = {string.find(\\"abc\\", \\"b\\")}"`; exports[`Lua version 5.1 / string string.find destructure 1`] = `"start, ____end, matchString = string.find(\\"abc\\", \\"b\\")"`; @@ -39,34 +31,20 @@ end" `; exports[`Lua version 5.1 / string string.gsub function 1`] = ` -"result = { - string.gsub( - \\"hello world\\", - \\"l\\", - function(match) return \\"R\\" end - ) -}" +"result = {string.gsub( + \\"hello world\\", + \\"l\\", + function(match) return \\"R\\" end +)}" `; -exports[`Lua version 5.1 / string string.gsub string 1`] = ` -"result = { - string.gsub(\\"hello world\\", \\"l\\", \\"R\\") -}" -`; +exports[`Lua version 5.1 / string string.gsub string 1`] = `"result = {string.gsub(\\"hello world\\", \\"l\\", \\"R\\")}"`; exports[`Lua version 5.1 / string string.gsub string destructured 1`] = `"result, numOccurrences = string.gsub(\\"hello world\\", \\"l\\", \\"R\\")"`; -exports[`Lua version 5.1 / string string.gsub table 1`] = ` -"result = { - string.gsub(\\"hello world\\", \\"l\\", {l = \\"R\\"}) -}" -`; +exports[`Lua version 5.1 / string string.gsub table 1`] = `"result = {string.gsub(\\"hello world\\", \\"l\\", {l = \\"R\\"})}"`; -exports[`Lua version 5.1 / string string.match 1`] = ` -"result = { - string.match(\\"hello world\\", \\"l\\") -}" -`; +exports[`Lua version 5.1 / string string.match 1`] = `"result = {string.match(\\"hello world\\", \\"l\\")}"`; exports[`Lua version 5.1 / string string.match destructured 1`] = `"match1, match2 = string.match(\\"hello world\\", \\"l\\")"`; @@ -78,17 +56,9 @@ exports[`Lua version 5.2 / string string.byte multiple 1`] = `"a, b, c, d = stri exports[`Lua version 5.2 / string string.char 1`] = `"str = string.char(64, 65, 66)"`; -exports[`Lua version 5.2 / string string.dump 1`] = ` -"str = string.dump( - function() return 5 end -)" -`; +exports[`Lua version 5.2 / string string.dump 1`] = `"str = string.dump(function() return 5 end)"`; -exports[`Lua version 5.2 / string string.find 1`] = ` -"result = { - string.find(\\"abc\\", \\"b\\") -}" -`; +exports[`Lua version 5.2 / string string.find 1`] = `"result = {string.find(\\"abc\\", \\"b\\")}"`; exports[`Lua version 5.2 / string string.find destructure 1`] = `"start, ____end, matchString = string.find(\\"abc\\", \\"b\\")"`; @@ -111,34 +81,20 @@ end" `; exports[`Lua version 5.2 / string string.gsub function 1`] = ` -"result = { - string.gsub( - \\"hello world\\", - \\"l\\", - function(match) return \\"R\\" end - ) -}" +"result = {string.gsub( + \\"hello world\\", + \\"l\\", + function(match) return \\"R\\" end +)}" `; -exports[`Lua version 5.2 / string string.gsub string 1`] = ` -"result = { - string.gsub(\\"hello world\\", \\"l\\", \\"R\\") -}" -`; +exports[`Lua version 5.2 / string string.gsub string 1`] = `"result = {string.gsub(\\"hello world\\", \\"l\\", \\"R\\")}"`; exports[`Lua version 5.2 / string string.gsub string destructured 1`] = `"result, numOccurrences = string.gsub(\\"hello world\\", \\"l\\", \\"R\\")"`; -exports[`Lua version 5.2 / string string.gsub table 1`] = ` -"result = { - string.gsub(\\"hello world\\", \\"l\\", {l = \\"R\\"}) -}" -`; +exports[`Lua version 5.2 / string string.gsub table 1`] = `"result = {string.gsub(\\"hello world\\", \\"l\\", {l = \\"R\\"})}"`; -exports[`Lua version 5.2 / string string.match 1`] = ` -"result = { - string.match(\\"hello world\\", \\"l\\") -}" -`; +exports[`Lua version 5.2 / string string.match 1`] = `"result = {string.match(\\"hello world\\", \\"l\\")}"`; exports[`Lua version 5.2 / string string.match destructured 1`] = `"match1, match2 = string.match(\\"hello world\\", \\"l\\")"`; @@ -150,17 +106,9 @@ exports[`Lua version 5.3 / string string.byte multiple 1`] = `"a, b, c, d = stri exports[`Lua version 5.3 / string string.char 1`] = `"str = string.char(64, 65, 66)"`; -exports[`Lua version 5.3 / string string.dump 1`] = ` -"str = string.dump( - function() return 5 end -)" -`; +exports[`Lua version 5.3 / string string.dump 1`] = `"str = string.dump(function() return 5 end)"`; -exports[`Lua version 5.3 / string string.find 1`] = ` -"result = { - string.find(\\"abc\\", \\"b\\") -}" -`; +exports[`Lua version 5.3 / string string.find 1`] = `"result = {string.find(\\"abc\\", \\"b\\")}"`; exports[`Lua version 5.3 / string string.find destructure 1`] = `"start, ____end, matchString = string.find(\\"abc\\", \\"b\\")"`; @@ -183,34 +131,20 @@ end" `; exports[`Lua version 5.3 / string string.gsub function 1`] = ` -"result = { - string.gsub( - \\"hello world\\", - \\"l\\", - function(match) return \\"R\\" end - ) -}" +"result = {string.gsub( + \\"hello world\\", + \\"l\\", + function(match) return \\"R\\" end +)}" `; -exports[`Lua version 5.3 / string string.gsub string 1`] = ` -"result = { - string.gsub(\\"hello world\\", \\"l\\", \\"R\\") -}" -`; +exports[`Lua version 5.3 / string string.gsub string 1`] = `"result = {string.gsub(\\"hello world\\", \\"l\\", \\"R\\")}"`; exports[`Lua version 5.3 / string string.gsub string destructured 1`] = `"result, numOccurrences = string.gsub(\\"hello world\\", \\"l\\", \\"R\\")"`; -exports[`Lua version 5.3 / string string.gsub table 1`] = ` -"result = { - string.gsub(\\"hello world\\", \\"l\\", {l = \\"R\\"}) -}" -`; +exports[`Lua version 5.3 / string string.gsub table 1`] = `"result = {string.gsub(\\"hello world\\", \\"l\\", {l = \\"R\\"})}"`; -exports[`Lua version 5.3 / string string.match 1`] = ` -"result = { - string.match(\\"hello world\\", \\"l\\") -}" -`; +exports[`Lua version 5.3 / string string.match 1`] = `"result = {string.match(\\"hello world\\", \\"l\\")}"`; exports[`Lua version 5.3 / string string.match destructured 1`] = `"match1, match2 = string.match(\\"hello world\\", \\"l\\")"`; @@ -222,17 +156,9 @@ exports[`Lua version 5.4 / string string.byte multiple 1`] = `"a, b, c, d = stri exports[`Lua version 5.4 / string string.char 1`] = `"str = string.char(64, 65, 66)"`; -exports[`Lua version 5.4 / string string.dump 1`] = ` -"str = string.dump( - function() return 5 end -)" -`; +exports[`Lua version 5.4 / string string.dump 1`] = `"str = string.dump(function() return 5 end)"`; -exports[`Lua version 5.4 / string string.find 1`] = ` -"result = { - string.find(\\"abc\\", \\"b\\") -}" -`; +exports[`Lua version 5.4 / string string.find 1`] = `"result = {string.find(\\"abc\\", \\"b\\")}"`; exports[`Lua version 5.4 / string string.find destructure 1`] = `"start, ____end, matchString = string.find(\\"abc\\", \\"b\\")"`; @@ -255,34 +181,20 @@ end" `; exports[`Lua version 5.4 / string string.gsub function 1`] = ` -"result = { - string.gsub( - \\"hello world\\", - \\"l\\", - function(match) return \\"R\\" end - ) -}" +"result = {string.gsub( + \\"hello world\\", + \\"l\\", + function(match) return \\"R\\" end +)}" `; -exports[`Lua version 5.4 / string string.gsub string 1`] = ` -"result = { - string.gsub(\\"hello world\\", \\"l\\", \\"R\\") -}" -`; +exports[`Lua version 5.4 / string string.gsub string 1`] = `"result = {string.gsub(\\"hello world\\", \\"l\\", \\"R\\")}"`; exports[`Lua version 5.4 / string string.gsub string destructured 1`] = `"result, numOccurrences = string.gsub(\\"hello world\\", \\"l\\", \\"R\\")"`; -exports[`Lua version 5.4 / string string.gsub table 1`] = ` -"result = { - string.gsub(\\"hello world\\", \\"l\\", {l = \\"R\\"}) -}" -`; +exports[`Lua version 5.4 / string string.gsub table 1`] = `"result = {string.gsub(\\"hello world\\", \\"l\\", {l = \\"R\\"})}"`; -exports[`Lua version 5.4 / string string.match 1`] = ` -"result = { - string.match(\\"hello world\\", \\"l\\") -}" -`; +exports[`Lua version 5.4 / string string.match 1`] = `"result = {string.match(\\"hello world\\", \\"l\\")}"`; exports[`Lua version 5.4 / string string.match destructured 1`] = `"match1, match2 = string.match(\\"hello world\\", \\"l\\")"`; @@ -294,17 +206,9 @@ exports[`Lua version JIT / string string.byte multiple 1`] = `"a, b, c, d = stri exports[`Lua version JIT / string string.char 1`] = `"str = string.char(64, 65, 66)"`; -exports[`Lua version JIT / string string.dump 1`] = ` -"str = string.dump( - function() return 5 end -)" -`; +exports[`Lua version JIT / string string.dump 1`] = `"str = string.dump(function() return 5 end)"`; -exports[`Lua version JIT / string string.find 1`] = ` -"result = { - string.find(\\"abc\\", \\"b\\") -}" -`; +exports[`Lua version JIT / string string.find 1`] = `"result = {string.find(\\"abc\\", \\"b\\")}"`; exports[`Lua version JIT / string string.find destructure 1`] = `"start, ____end, matchString = string.find(\\"abc\\", \\"b\\")"`; @@ -327,34 +231,20 @@ end" `; exports[`Lua version JIT / string string.gsub function 1`] = ` -"result = { - string.gsub( - \\"hello world\\", - \\"l\\", - function(match) return \\"R\\" end - ) -}" +"result = {string.gsub( + \\"hello world\\", + \\"l\\", + function(match) return \\"R\\" end +)}" `; -exports[`Lua version JIT / string string.gsub string 1`] = ` -"result = { - string.gsub(\\"hello world\\", \\"l\\", \\"R\\") -}" -`; +exports[`Lua version JIT / string string.gsub string 1`] = `"result = {string.gsub(\\"hello world\\", \\"l\\", \\"R\\")}"`; exports[`Lua version JIT / string string.gsub string destructured 1`] = `"result, numOccurrences = string.gsub(\\"hello world\\", \\"l\\", \\"R\\")"`; -exports[`Lua version JIT / string string.gsub table 1`] = ` -"result = { - string.gsub(\\"hello world\\", \\"l\\", {l = \\"R\\"}) -}" -`; +exports[`Lua version JIT / string string.gsub table 1`] = `"result = {string.gsub(\\"hello world\\", \\"l\\", {l = \\"R\\"})}"`; -exports[`Lua version JIT / string string.match 1`] = ` -"result = { - string.match(\\"hello world\\", \\"l\\") -}" -`; +exports[`Lua version JIT / string string.match 1`] = `"result = {string.match(\\"hello world\\", \\"l\\")}"`; exports[`Lua version JIT / string string.match destructured 1`] = `"match1, match2 = string.match(\\"hello world\\", \\"l\\")"`; diff --git a/test/test-utils.ts b/test/test-utils.ts index c8b0437..cce9a3b 100644 --- a/test/test-utils.ts +++ b/test/test-utils.ts @@ -2,7 +2,7 @@ import * as fs from 'fs'; import * as path from 'path'; import * as ts from 'typescript'; -import { LuaTarget, Transpiler } from 'typescript-to-lua'; +import { LuaTarget, Transpiler, CompilerOptions } from 'typescript-to-lua'; const targets = [ LuaTarget.Lua51, @@ -25,7 +25,7 @@ export function tstl(luaTarget: LuaTarget, input: string): string { // Create a TS program containing input.ts and the declarations file to test const rootNames = ['input.ts', typesPath]; - const options = { + const options: CompilerOptions = { luaTarget, lib: ['lib.esnext.d.ts'], noHeader: true, @@ -83,21 +83,28 @@ function getCompilerHostWithInput(input: string) { let filePath = fileName; - if (fileName.startsWith('lib.')) { + if (fileName.includes('/@typescript/')) { const typeScriptDir = path.dirname(require.resolve('typescript')); - filePath = path.join(typeScriptDir, fileName); + const pathParts = fileName.split('@typescript/')[1].split('/'); + let libFileName = pathParts.join('.').replace(/-/g, '.'); + if (libFileName.endsWith('.ts') && !libFileName.endsWith('.d.ts')) { + libFileName = libFileName.substring(0, libFileName.length - 3) + '.d.ts'; + } + filePath = path.join(typeScriptDir, libFileName); } - if (fileName.endsWith('typescript-to-lua/language-extensions/index.d.ts')) { + if (fileName.endsWith('@typescript-to-lua/language-extensions/index.d.ts')) { filePath = path.resolve( __dirname, - `../node_modules/typescript-to-lua/language-extensions/index.d.ts` + `../node_modules/@typescript-to-lua/language-extensions/index.d.ts` ); } - const fileContent = fs.readFileSync(filePath).toString(); - fileCache[fileName] = fileContent; - return ts.createSourceFile(fileName, fileContent, languageVersion); + if (fs.existsSync(filePath)) { + const fileContent = fs.readFileSync(filePath).toString(); + fileCache[fileName] = fileContent; + return ts.createSourceFile(fileName, fileContent, languageVersion); + } }, }; } diff --git a/test/testproject/main.ts b/test/testproject/main.ts new file mode 100644 index 0000000..5d0d4f0 --- /dev/null +++ b/test/testproject/main.ts @@ -0,0 +1,9 @@ +/// +const mytable = new LuaMap(); + +for (const [k, v] of pairs(mytable)) { +} + +function multiReturn(): LuaMultiReturn<[string, number, string]> { + return $multi('3', 5, '6'); +} diff --git a/test/testproject/package-lock.json b/test/testproject/package-lock.json new file mode 100644 index 0000000..1473fbd --- /dev/null +++ b/test/testproject/package-lock.json @@ -0,0 +1,275 @@ +{ + "name": "testproject", + "lockfileVersion": 2, + "requires": true, + "packages": { + "": { + "devDependencies": { + "lua-types": "file:../..", + "typescript": "~4.7.3", + "typescript-to-lua": "^1.9.0" + } + }, + "../..": { + "version": "2.12.2", + "dev": true, + "license": "MIT", + "devDependencies": { + "@types/jest": "^26.0.20", + "@types/node": "^14.14.34", + "@typescript-to-lua/language-extensions": "^1.0.0", + "jest": "^26.6.3", + "jest-circus": "^26.6.3", + "prettier": "^2.0.5", + "ts-jest": "^26.5.3", + "typescript-to-lua": "^1.9.0" + } + }, + "node_modules/enhanced-resolve": { + "version": "5.10.0", + "resolved": "https://registry.npmjs.org/enhanced-resolve/-/enhanced-resolve-5.10.0.tgz", + "integrity": "sha512-T0yTFjdpldGY8PmuXXR0PyQ1ufZpEGiHVrp7zHKB7jdR4qlmZHhONVM5AQOAWXuF/w3dnHbEQVrNptJgt7F+cQ==", + "dev": true, + "dependencies": { + "graceful-fs": "^4.2.4", + "tapable": "^2.2.0" + }, + "engines": { + "node": ">=10.13.0" + } + }, + "node_modules/function-bind": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz", + "integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==", + "dev": true + }, + "node_modules/graceful-fs": { + "version": "4.2.10", + "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.10.tgz", + "integrity": "sha512-9ByhssR2fPVsNZj478qUUbKfmL0+t5BDVyjShtyZZLiK7ZDAArFFfopyOTj0M05wE2tJPisA4iTnnXl2YoPvOA==", + "dev": true + }, + "node_modules/has": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz", + "integrity": "sha512-f2dvO0VU6Oej7RkWJGrehjbzMAjFp5/VKPp5tTpWIV4JHHZK1/BxbFRtf/siA2SWTe09caDmVtYYzWEIbBS4zw==", + "dev": true, + "dependencies": { + "function-bind": "^1.1.1" + }, + "engines": { + "node": ">= 0.4.0" + } + }, + "node_modules/is-core-module": { + "version": "2.10.0", + "resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.10.0.tgz", + "integrity": "sha512-Erxj2n/LDAZ7H8WNJXd9tw38GYM3dv8rk8Zcs+jJuxYTW7sozH+SS8NtrSjVL1/vpLvWi1hxy96IzjJ3EHTJJg==", + "dev": true, + "dependencies": { + "has": "^1.0.3" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/lua-types": { + "resolved": "../..", + "link": true + }, + "node_modules/path-parse": { + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.7.tgz", + "integrity": "sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==", + "dev": true + }, + "node_modules/resolve": { + "version": "1.22.1", + "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.22.1.tgz", + "integrity": "sha512-nBpuuYuY5jFsli/JIs1oldw6fOQCBioohqWZg/2hiaOybXOft4lonv85uDOKXdf8rhyK159cxU5cDcK/NKk8zw==", + "dev": true, + "dependencies": { + "is-core-module": "^2.9.0", + "path-parse": "^1.0.7", + "supports-preserve-symlinks-flag": "^1.0.0" + }, + "bin": { + "resolve": "bin/resolve" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/source-map": { + "version": "0.7.4", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.7.4.tgz", + "integrity": "sha512-l3BikUxvPOcn5E74dZiq5BGsTb5yEwhaTSzccU6t4sDOH8NWJCstKO5QT2CvtFoK6F0saL7p9xHAqHOlCPJygA==", + "dev": true, + "engines": { + "node": ">= 8" + } + }, + "node_modules/supports-preserve-symlinks-flag": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/supports-preserve-symlinks-flag/-/supports-preserve-symlinks-flag-1.0.0.tgz", + "integrity": "sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w==", + "dev": true, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/tapable": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/tapable/-/tapable-2.2.1.tgz", + "integrity": "sha512-GNzQvQTOIP6RyTfE2Qxb8ZVlNmw0n88vp1szwWRimP02mnTsx3Wtn5qRdqY9w2XduFNUgvOwhNnQsjwCp+kqaQ==", + "dev": true, + "engines": { + "node": ">=6" + } + }, + "node_modules/typescript": { + "version": "4.7.4", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.7.4.tgz", + "integrity": "sha512-C0WQT0gezHuw6AdY1M2jxUO83Rjf0HP7Sk1DtXj6j1EwkQNZrHAg2XPWlq62oqEhYvONq5pkC2Y9oPljWToLmQ==", + "dev": true, + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, + "engines": { + "node": ">=4.2.0" + } + }, + "node_modules/typescript-to-lua": { + "version": "1.9.0", + "resolved": "https://registry.npmjs.org/typescript-to-lua/-/typescript-to-lua-1.9.0.tgz", + "integrity": "sha512-Oj8kutP1u/TSjN9oGUuESfOL+feHMSs7CCxl90C60jWTH+4ZXLtrXlRJTalA3Z2/aHjQXXgPaXQStSXBzAYLow==", + "dev": true, + "dependencies": { + "enhanced-resolve": "^5.8.2", + "resolve": "^1.15.1", + "source-map": "^0.7.3" + }, + "bin": { + "tstl": "dist/tstl.js" + }, + "engines": { + "node": ">=12.13.0" + }, + "peerDependencies": { + "typescript": "~4.7.3" + } + } + }, + "dependencies": { + "enhanced-resolve": { + "version": "5.10.0", + "resolved": "https://registry.npmjs.org/enhanced-resolve/-/enhanced-resolve-5.10.0.tgz", + "integrity": "sha512-T0yTFjdpldGY8PmuXXR0PyQ1ufZpEGiHVrp7zHKB7jdR4qlmZHhONVM5AQOAWXuF/w3dnHbEQVrNptJgt7F+cQ==", + "dev": true, + "requires": { + "graceful-fs": "^4.2.4", + "tapable": "^2.2.0" + } + }, + "function-bind": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz", + "integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==", + "dev": true + }, + "graceful-fs": { + "version": "4.2.10", + "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.10.tgz", + "integrity": "sha512-9ByhssR2fPVsNZj478qUUbKfmL0+t5BDVyjShtyZZLiK7ZDAArFFfopyOTj0M05wE2tJPisA4iTnnXl2YoPvOA==", + "dev": true + }, + "has": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz", + "integrity": "sha512-f2dvO0VU6Oej7RkWJGrehjbzMAjFp5/VKPp5tTpWIV4JHHZK1/BxbFRtf/siA2SWTe09caDmVtYYzWEIbBS4zw==", + "dev": true, + "requires": { + "function-bind": "^1.1.1" + } + }, + "is-core-module": { + "version": "2.10.0", + "resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.10.0.tgz", + "integrity": "sha512-Erxj2n/LDAZ7H8WNJXd9tw38GYM3dv8rk8Zcs+jJuxYTW7sozH+SS8NtrSjVL1/vpLvWi1hxy96IzjJ3EHTJJg==", + "dev": true, + "requires": { + "has": "^1.0.3" + } + }, + "lua-types": { + "version": "file:../..", + "requires": { + "@types/jest": "^26.0.20", + "@types/node": "^14.14.34", + "@typescript-to-lua/language-extensions": "^1.0.0", + "jest": "^26.6.3", + "jest-circus": "^26.6.3", + "prettier": "^2.0.5", + "ts-jest": "^26.5.3", + "typescript-to-lua": "^1.9.0" + } + }, + "path-parse": { + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.7.tgz", + "integrity": "sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==", + "dev": true + }, + "resolve": { + "version": "1.22.1", + "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.22.1.tgz", + "integrity": "sha512-nBpuuYuY5jFsli/JIs1oldw6fOQCBioohqWZg/2hiaOybXOft4lonv85uDOKXdf8rhyK159cxU5cDcK/NKk8zw==", + "dev": true, + "requires": { + "is-core-module": "^2.9.0", + "path-parse": "^1.0.7", + "supports-preserve-symlinks-flag": "^1.0.0" + } + }, + "source-map": { + "version": "0.7.4", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.7.4.tgz", + "integrity": "sha512-l3BikUxvPOcn5E74dZiq5BGsTb5yEwhaTSzccU6t4sDOH8NWJCstKO5QT2CvtFoK6F0saL7p9xHAqHOlCPJygA==", + "dev": true + }, + "supports-preserve-symlinks-flag": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/supports-preserve-symlinks-flag/-/supports-preserve-symlinks-flag-1.0.0.tgz", + "integrity": "sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w==", + "dev": true + }, + "tapable": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/tapable/-/tapable-2.2.1.tgz", + "integrity": "sha512-GNzQvQTOIP6RyTfE2Qxb8ZVlNmw0n88vp1szwWRimP02mnTsx3Wtn5qRdqY9w2XduFNUgvOwhNnQsjwCp+kqaQ==", + "dev": true + }, + "typescript": { + "version": "4.7.4", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.7.4.tgz", + "integrity": "sha512-C0WQT0gezHuw6AdY1M2jxUO83Rjf0HP7Sk1DtXj6j1EwkQNZrHAg2XPWlq62oqEhYvONq5pkC2Y9oPljWToLmQ==", + "dev": true + }, + "typescript-to-lua": { + "version": "1.9.0", + "resolved": "https://registry.npmjs.org/typescript-to-lua/-/typescript-to-lua-1.9.0.tgz", + "integrity": "sha512-Oj8kutP1u/TSjN9oGUuESfOL+feHMSs7CCxl90C60jWTH+4ZXLtrXlRJTalA3Z2/aHjQXXgPaXQStSXBzAYLow==", + "dev": true, + "requires": { + "enhanced-resolve": "^5.8.2", + "resolve": "^1.15.1", + "source-map": "^0.7.3" + } + } + } +} diff --git a/test/testproject/package.json b/test/testproject/package.json new file mode 100644 index 0000000..3df63a5 --- /dev/null +++ b/test/testproject/package.json @@ -0,0 +1,10 @@ +{ + "scripts": { + "build": "tstl" + }, + "devDependencies": { + "lua-types": "file:../..", + "typescript": "~4.7.3", + "typescript-to-lua": "^1.9.0" + } +} diff --git a/test/testproject/tsconfig.json b/test/testproject/tsconfig.json new file mode 100644 index 0000000..406f546 --- /dev/null +++ b/test/testproject/tsconfig.json @@ -0,0 +1,7 @@ +{ + "compilerOptions": { + "strict": true, + "target": "esnext", + "types": ["@typescript-to-lua/language-extensions"] + } +} diff --git a/test/tsconfig.json b/test/tsconfig.json index 59b09ee..6bbf74c 100644 --- a/test/tsconfig.json +++ b/test/tsconfig.json @@ -1,6 +1,7 @@ { "compilerOptions": { + "rootDir": ".", "types": ["node", "jest"] }, - "include": ["."] + "include": ["./*.ts"] }