Comparing version 2.8.0 to 2.9.1
@@ -1,2 +0,2 @@ | ||
import './core'; | ||
import './special/5.1'; | ||
/// <reference path="./core/index.d.ts" /> | ||
/// <reference path="./special/5.1.d.ts" /> |
@@ -1,2 +0,2 @@ | ||
import './core'; | ||
import './special/5.2'; | ||
/// <reference path="./core/index.d.ts" /> | ||
/// <reference path="./special/5.2.d.ts" /> |
@@ -1,2 +0,2 @@ | ||
import './core'; | ||
import './special/5.3'; | ||
/// <reference path="./core/index.d.ts" /> | ||
/// <reference path="./special/5.3.d.ts" /> |
@@ -1,2 +0,2 @@ | ||
import './core'; | ||
import './special/5.4'; | ||
/// <reference path="./core/index.d.ts" /> | ||
/// <reference path="./special/5.4.d.ts" /> |
@@ -10,48 +10,49 @@ // Based on https://www.lua.org/manual/5.3/manual.html#6.2 | ||
declare namespace coroutine { | ||
/** | ||
* Creates a new coroutine, with body f. f must be a function. Returns this | ||
* new coroutine, an object with type "thread". | ||
*/ | ||
function create(f: (...args: any[]) => any): LuaThread; | ||
/** | ||
* Creates a new coroutine, with body f. f must be a function. Returns this | ||
* new coroutine, an object with type "thread". | ||
*/ | ||
function create(f: (...args: any[]) => any): LuaThread; | ||
/** | ||
* Starts or continues the execution of coroutine co. The first time you | ||
* resume a coroutine, it starts running its body. The values val1, ... are | ||
* passed as the arguments to the body function. If the coroutine has yielded, | ||
* resume restarts it; the values val1, ... are passed as the results from the | ||
* yield. | ||
* | ||
* If the coroutine runs without any errors, resume returns true plus any | ||
* values passed to yield (when the coroutine yields) or any values returned | ||
* by the body function (when the coroutine terminates). If there is any | ||
* error, resume returns false plus the error message. | ||
* @tupleReturn | ||
*/ | ||
function resume(co: LuaThread, ...val: any[]): [true, ...any[]] | [false, string]; | ||
/** | ||
* Starts or continues the execution of coroutine co. The first time you | ||
* resume a coroutine, it starts running its body. The values val1, ... are | ||
* passed as the arguments to the body function. If the coroutine has yielded, | ||
* resume restarts it; the values val1, ... are passed as the results from the | ||
* yield. | ||
* | ||
* If the coroutine runs without any errors, resume returns true plus any | ||
* values passed to yield (when the coroutine yields) or any values returned | ||
* by the body function (when the coroutine terminates). If there is any | ||
* error, resume returns false plus the error message. | ||
*/ | ||
function resume( | ||
co: LuaThread, | ||
...val: any[] | ||
): LuaMultiReturn<[true, ...any[]] | [false, string]>; | ||
/** | ||
* Returns the status of coroutine co, as a string: "running", if the | ||
* coroutine is running (that is, it called status); "suspended", if the | ||
* coroutine is suspended in a call to yield, or if it has not started running | ||
* yet; "normal" if the coroutine is active but not running (that is, it has | ||
* resumed another coroutine); and "dead" if the coroutine has finished its | ||
* body function, or if it has stopped with an error. | ||
*/ | ||
function status(co: LuaThread): 'running' | 'suspended' | 'normal' | 'dead'; | ||
/** | ||
* Returns the status of coroutine co, as a string: "running", if the | ||
* coroutine is running (that is, it called status); "suspended", if the | ||
* coroutine is suspended in a call to yield, or if it has not started running | ||
* yet; "normal" if the coroutine is active but not running (that is, it has | ||
* resumed another coroutine); and "dead" if the coroutine has finished its | ||
* body function, or if it has stopped with an error. | ||
*/ | ||
function status(co: LuaThread): 'running' | 'suspended' | 'normal' | 'dead'; | ||
/** | ||
* Creates a new coroutine, with body f. f must be a function. Returns a | ||
* function that resumes the coroutine each time it is called. Any arguments | ||
* passed to the function behave as the extra arguments to resume. Returns the | ||
* same values returned by resume, except the first boolean. In case of error, | ||
* propagates the error. | ||
*/ | ||
function wrap(f: (...args: any[]) => any): /** @tupleReturn */ (...args: any[]) => any[]; | ||
/** | ||
* Creates a new coroutine, with body f. f must be a function. Returns a | ||
* function that resumes the coroutine each time it is called. Any arguments | ||
* passed to the function behave as the extra arguments to resume. Returns the | ||
* same values returned by resume, except the first boolean. In case of error, | ||
* propagates the error. | ||
*/ | ||
function wrap(f: (...args: any[]) => any): (...args: any[]) => LuaMultiReturn<any[]>; | ||
/** | ||
* Suspends the execution of the calling coroutine. Any arguments to yield are | ||
* passed as extra results to resume. | ||
* @tupleReturn | ||
*/ | ||
function yield(...args: any[]): any[]; | ||
/** | ||
* Suspends the execution of the calling coroutine. Any arguments to yield are | ||
* passed as extra results to resume. | ||
*/ | ||
function yield(...args: any[]): LuaMultiReturn<any[]>; | ||
} |
@@ -19,210 +19,210 @@ // Based on https://www.lua.org/manual/5.3/manual.html#6.10 | ||
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; | ||
/** | ||
* 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; | ||
/** | ||
* 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). | ||
* @tupleReturn | ||
*/ | ||
function gethook(thread?: LuaThread): [undefined, 0] | [Function, number, string?]; | ||
/** | ||
* 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( | ||
thread?: LuaThread | ||
): LuaMultiReturn<[undefined, 0] | [Function, number, string?]>; | ||
interface FunctionInfo<T extends Function = Function> { | ||
interface FunctionInfo<T extends Function = Function> { | ||
/** | ||
* 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; | ||
} | ||
/** | ||
* The function itself. | ||
* 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. | ||
*/ | ||
func: T; | ||
function getinfo<T extends Function>(f: T): FunctionInfo<T>; | ||
function getinfo<T extends Function>(f: T, what: string): Partial<FunctionInfo<T>>; | ||
function getinfo<T extends Function>(thread: LuaThread, f: T): FunctionInfo<T>; | ||
function getinfo<T extends Function>( | ||
thread: LuaThread, | ||
f: T, | ||
what: string | ||
): Partial<FunctionInfo<T>>; | ||
function getinfo(f: number): FunctionInfo | undefined; | ||
function getinfo(f: number, what: string): Partial<FunctionInfo> | undefined; | ||
function getinfo(thread: LuaThread, f: number): FunctionInfo | undefined; | ||
function getinfo(thread: LuaThread, f: number, what: string): Partial<FunctionInfo> | undefined; | ||
/** | ||
* A reasonable name for the function. | ||
* Returns the metatable of the given value or nil if it does not have a | ||
* metatable. | ||
*/ | ||
name?: string; | ||
function getmetatable<T extends any>(value: T): LuaMetatable<T> | undefined; | ||
/** | ||
* What the `name` field means. The empty string means that Lua did not find | ||
* a name for the function. | ||
* Returns the registry table (see §4.5). | ||
*/ | ||
namewhat: 'global' | 'local' | 'method' | 'field' | ''; | ||
function getregistry(): Record<string, any>; | ||
source: string; | ||
/** | ||
* A short version of source (up to 60 characters), useful for error | ||
* messages. | ||
* 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). | ||
*/ | ||
short_src: string; | ||
linedefined: number; | ||
lastlinedefined: number; | ||
function getupvalue(f: Function, up: number): LuaMultiReturn<[string, any] | []>; | ||
/** | ||
* What this function is. | ||
* Returns the Lua value associated to u. If u is not a full userdata, returns | ||
* nil. | ||
*/ | ||
what: 'Lua' | 'C' | 'main'; | ||
function getuservalue(u: LuaUserdata): any; | ||
currentline: number; | ||
/** | ||
* 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; | ||
function sethook( | ||
thread: LuaThread, | ||
hook: (event: 'call' | 'return' | 'line' | 'count', line?: number) => any, | ||
mask: string, | ||
count?: number | ||
): void; | ||
/** | ||
* Number of upvalues of that function. | ||
* 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. | ||
*/ | ||
nups: number; | ||
} | ||
function setlocal(level: number, local: number, value: any): string | undefined; | ||
function setlocal( | ||
thread: LuaThread, | ||
level: number, | ||
local: number, | ||
value: any | ||
): string | undefined; | ||
/** | ||
* 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<T extends Function>(f: T): FunctionInfo<T>; | ||
function getinfo<T extends Function>(f: T, what: string): Partial<FunctionInfo<T>>; | ||
function getinfo<T extends Function>(thread: LuaThread, f: T): FunctionInfo<T>; | ||
function getinfo<T extends Function>( | ||
thread: LuaThread, | ||
f: T, | ||
what: string, | ||
): Partial<FunctionInfo<T>>; | ||
function getinfo(f: number): FunctionInfo | undefined; | ||
function getinfo(f: number, what: string): Partial<FunctionInfo> | undefined; | ||
function getinfo(thread: LuaThread, f: number): FunctionInfo | undefined; | ||
function getinfo(thread: LuaThread, f: number, what: string): Partial<FunctionInfo> | undefined; | ||
/** | ||
* Sets the metatable for the given value to the given table (which can be | ||
* nil). Returns value. | ||
*/ | ||
function setmetatable<T, TIndex>( | ||
value: T, | ||
table: LuaMetatable<T & TIndex, TIndex> | null | undefined | ||
): T & TIndex; | ||
/** | ||
* Returns the metatable of the given value or nil if it does not have a | ||
* metatable. | ||
*/ | ||
function getmetatable<T extends any>(value: T): LuaMetatable<T> | 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; | ||
/** | ||
* Returns the registry table (see §4.5). | ||
*/ | ||
function getregistry(): Record<string, any>; | ||
/** | ||
* 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; | ||
/** | ||
* 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). | ||
* @tupleReturn | ||
*/ | ||
function getupvalue(f: Function, up: number): [string, any] | []; | ||
/** | ||
* Returns the Lua value associated to u. If u is not a full userdata, returns | ||
* nil. | ||
*/ | ||
function getuservalue(u: LuaUserdata): 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; | ||
function sethook( | ||
thread: LuaThread, | ||
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; | ||
function setlocal( | ||
thread: LuaThread, | ||
level: number, | ||
local: number, | ||
value: any, | ||
): string | undefined; | ||
/** | ||
* Sets the metatable for the given value to the given table (which can be | ||
* nil). Returns value. | ||
*/ | ||
function setmetatable<T, TIndex>( | ||
value: T, | ||
table: LuaMetatable<T & TIndex, TIndex> | null | undefined, | ||
): T & TIndex; | ||
/** | ||
* 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; | ||
/** | ||
* If message is present but is neither a string nor nil, this function | ||
* returns message without further processing. Otherwise, it returns a string | ||
* with a traceback of the call stack. The optional message string is appended | ||
* at the beginning of the traceback. An optional level number tells at which | ||
* level to start the traceback (default is 1, the function calling | ||
* traceback). | ||
*/ | ||
function traceback(message?: string | null, level?: number | null): string; | ||
function traceback(thread?: LuaThread, message?: string | null, level?: number | null): string; | ||
function traceback<T>(message: T): T; | ||
function traceback<T>(thread: LuaThread, message: T): T; | ||
/** | ||
* If message is present but is neither a string nor nil, this function | ||
* returns message without further processing. Otherwise, it returns a string | ||
* with a traceback of the call stack. The optional message string is appended | ||
* at the beginning of the traceback. An optional level number tells at which | ||
* level to start the traceback (default is 1, the function calling | ||
* traceback). | ||
*/ | ||
function traceback(message?: string | null, level?: number | null): string; | ||
function traceback(thread?: LuaThread, message?: string | null, level?: number | null): string; | ||
function traceback<T>(message: T): T; | ||
function traceback<T>(thread: LuaThread, message: T): T; | ||
} |
@@ -9,6 +9,2 @@ // Based on https://www.lua.org/manual/5.3/manual.html#6.1 | ||
type LuaUserdata = { readonly __internal__: unique symbol }; | ||
/** @luaIterator */ | ||
type LuaIterable<T> = Iterable<T> & { readonly __internal__: unique symbol }; | ||
/** @luaIterator @tupleReturn */ | ||
type LuaTupleIterable<T extends any[]> = Iterable<T> & { readonly __internal__: unique symbol }; | ||
@@ -128,3 +124,3 @@ /** | ||
*/ | ||
declare function ipairs<T>(t: Record<number, T>): LuaTupleIterable<[number, T]>; | ||
declare function ipairs<T>(t: Record<number, T>): LuaIterable<LuaMultiReturn<[number, T]>>; | ||
@@ -147,5 +143,4 @@ /** | ||
* fields. In particular, you may clear existing fields. | ||
* @tupleReturn | ||
*/ | ||
declare function next(table: object, index?: any): [any, any] | []; | ||
declare function next(table: object, index?: any): LuaMultiReturn<[any, any] | []>; | ||
@@ -164,3 +159,3 @@ /** | ||
*/ | ||
declare function pairs<T>(t: T): LuaTupleIterable<[keyof T, T[keyof T]]>; | ||
declare function pairs<T>(t: T): LuaIterable<LuaMultiReturn<[keyof T, T[keyof T]]>>; | ||
@@ -174,15 +169,13 @@ /** | ||
* pcall returns false plus the error message. | ||
* @tupleReturn | ||
*/ | ||
declare function pcall<This, Args extends any[], R>( | ||
f: (this: This, ...args: Args) => R, | ||
context: This, | ||
...args: Args | ||
): [true, R] | [false, string]; | ||
f: (this: This, ...args: Args) => R, | ||
context: This, | ||
...args: Args | ||
): LuaMultiReturn<[true, R] | [false, string]>; | ||
/** @tupleReturn */ | ||
declare function pcall<A extends any[], R>( | ||
f: (this: void, ...args: A) => R, | ||
...args: A | ||
): [true, R] | [false, string]; | ||
f: (this: void, ...args: A) => R, | ||
...args: A | ||
): LuaMultiReturn<[true, R] | [false, string]>; | ||
@@ -230,5 +223,4 @@ /** | ||
* arguments it received. | ||
* @tupleReturn | ||
*/ | ||
declare function select<T>(index: number, ...args: T[]): T[]; | ||
declare function select<T>(index: number, ...args: T[]): LuaMultiReturn<T[]>; | ||
@@ -252,4 +244,4 @@ /** | ||
declare function setmetatable<T extends object, TIndex extends object>( | ||
table: T, | ||
metatable: LuaMetatable<T & TIndex, TIndex> | null | undefined, | ||
table: T, | ||
metatable: LuaMetatable<T & TIndex, TIndex> | null | undefined | ||
): T & TIndex; | ||
@@ -290,3 +282,3 @@ | ||
declare function type( | ||
v: any, | ||
v: any | ||
): 'nil' | 'number' | 'string' | 'boolean' | 'table' | 'function' | 'thread' | 'userdata'; |
@@ -1,10 +0,12 @@ | ||
import './coroutine'; | ||
import './debug'; | ||
import './global'; | ||
import './io'; | ||
import './math'; | ||
import './metatable'; | ||
import './modules'; | ||
import './os'; | ||
import './string'; | ||
import './table'; | ||
/// <reference types="typescript-to-lua/language-extensions" /> | ||
/// <reference path="./coroutine.d.ts" /> | ||
/// <reference path="./debug.d.ts" /> | ||
/// <reference path="./global.d.ts" /> | ||
/// <reference path="./io.d.ts" /> | ||
/// <reference path="./math.d.ts" /> | ||
/// <reference path="./metatable.d.ts" /> | ||
/// <reference path="./modules.d.ts" /> | ||
/// <reference path="./os.d.ts" /> | ||
/// <reference path="./string.d.ts" /> | ||
/// <reference path="./table.d.ts" /> |
400
core/io.d.ts
@@ -26,219 +26,223 @@ // Based on https://www.lua.org/manual/5.3/manual.html#6.8 | ||
declare namespace io { | ||
/** | ||
* Equivalent to file:close(). Without a file, closes the default output file. | ||
*/ | ||
function close(file?: LuaFile): boolean; | ||
/** | ||
* 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; | ||
/** | ||
* 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; | ||
/** | ||
* 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<T extends FileReadFormat[]>( | ||
filename?: string, | ||
...formats: T | ||
): LuaTupleIterable< | ||
[] extends T ? [string] : { [P in keyof T]: T[P] extends 'n' ? number : string } | ||
>; | ||
/** | ||
* 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<T extends FileReadFormat[]>( | ||
filename?: string, | ||
...formats: T | ||
): LuaIterable< | ||
LuaMultiReturn< | ||
[] extends T ? [string] : { [P in keyof T]: T[P] extends 'n' ? number : string } | ||
> | ||
>; | ||
/** | ||
* 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. | ||
* @tupleReturn | ||
*/ | ||
function open(filename: string, mode?: string): [LuaFile] | [undefined, string, number]; | ||
/** | ||
* 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; | ||
/** | ||
* Similar to io.input, but operates over the default output file. | ||
*/ | ||
function output(file?: string | LuaFile): LuaFile; | ||
/** | ||
* This function is system dependent and is not available on all platforms. | ||
* | ||
* Starts program prog in a separated process and returns a file handle that | ||
* you can use to read data from this program (if mode is "r", the default) or | ||
* to write data to this program (if mode is "w"). | ||
*/ | ||
function popen(prog: string, mode?: 'r' | 'w'): LuaFile; | ||
/** | ||
* This function is system dependent and is not available on all platforms. | ||
* | ||
* Starts program prog in a separated process and returns a file handle that | ||
* you can use to read data from this program (if mode is "r", the default) or | ||
* to write data to this program (if mode is "w"). | ||
*/ | ||
function popen(prog: string, mode?: 'r' | 'w'): LuaFile; | ||
/** | ||
* Equivalent to io.input():read(···). | ||
* @tupleReturn | ||
*/ | ||
const read: LuaFile['read']; | ||
/** | ||
* Equivalent to io.input():read(···). | ||
*/ | ||
const read: LuaFile['read']; | ||
/** | ||
* 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; | ||
/** | ||
* 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; | ||
/** | ||
* 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(···). | ||
* @tupleReturn | ||
*/ | ||
function write(...args: (string | number)[]): [LuaFile] | [undefined, string]; | ||
/** | ||
* Equivalent to io.output():write(···). | ||
*/ | ||
function write(...args: (string | number)[]): LuaMultiReturn<[LuaFile] | [undefined, 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; | ||
/** | ||
* 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; | ||
/** | ||
* 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<T extends FileReadFormat[]>( | ||
...formats: T | ||
): LuaTupleIterable< | ||
[] extends T ? [string] : { [P in keyof T]: T[P] extends 'n' ? number : string } | ||
>; | ||
/** | ||
* 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<T extends FileReadFormat[]>( | ||
...formats: T | ||
): LuaIterable< | ||
LuaMultiReturn< | ||
[] extends T ? [string] : { [P in keyof T]: T[P] extends 'n' ? number : string } | ||
> | ||
>; | ||
/** | ||
* 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. | ||
* @tupleReturn | ||
*/ | ||
read<T extends FileReadFormat[]>( | ||
...formats: T | ||
): { [P in keyof T]?: T[P] extends 'n' ? number : string }; | ||
/** | ||
* 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<T extends FileReadFormat[]>( | ||
...formats: T | ||
): LuaMultiReturn<{ [P in keyof T]?: T[P] extends 'n' ? number : string }>; | ||
/** | ||
* 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. | ||
* @tupleReturn | ||
*/ | ||
seek(whence?: 'set' | 'cur' | 'end', offset?: number): [number] | [undefined, string]; | ||
/** | ||
* 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]>; | ||
/** | ||
* Sets the buffering mode for an output file. There are three available | ||
* modes: | ||
* | ||
* * "no": no buffering; the result of any output operation appears | ||
* immediately. | ||
* * "full": full buffering; output operation is performed only when the | ||
* buffer is full or when you explicitly flush the file (see io.flush). | ||
* * "line": line buffering; output is buffered until a newline is output or | ||
* there is any input from some special files (such as a terminal device). | ||
* For the last two cases, size specifies the size of the buffer, in bytes. | ||
* The default is an appropriate size. | ||
*/ | ||
setvbuf(mode: 'no' | 'full' | 'line', size?: number): void; | ||
/** | ||
* Sets the buffering mode for an output file. There are three available | ||
* modes: | ||
* | ||
* * "no": no buffering; the result of any output operation appears | ||
* immediately. | ||
* * "full": full buffering; output operation is performed only when the | ||
* buffer is full or when you explicitly flush the file (see io.flush). | ||
* * "line": line buffering; output is buffered until a newline is output or | ||
* there is any input from some special files (such as a terminal device). | ||
* For the last two cases, size specifies the size of the buffer, in bytes. | ||
* The default is an appropriate size. | ||
*/ | ||
setvbuf(mode: 'no' | 'full' | 'line', size?: number): void; | ||
/** | ||
* 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. | ||
* @tupleReturn | ||
*/ | ||
write(...args: (string | number)[]): [LuaFile] | [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]>; | ||
} |
@@ -14,97 +14,96 @@ // Based on https://www.lua.org/manual/5.3/manual.html#6.7 | ||
declare namespace math { | ||
/** | ||
* Returns the absolute value of x. (integer/float) | ||
*/ | ||
function abs(x: number): number; | ||
/** | ||
* 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 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 sine of x (in radians). | ||
*/ | ||
function asin(x: number): number; | ||
/** | ||
* Returns the smallest integral value larger than or equal to x. | ||
*/ | ||
function ceil(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; | ||
/** | ||
* 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; | ||
/** | ||
* 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 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 the largest integral value smaller than or equal to x. | ||
*/ | ||
function floor(x: number): number; | ||
/** | ||
* Returns the remainder of the division of x by y that rounds the quotient | ||
* towards zero. (integer/float) | ||
*/ | ||
function fmod(x: number, y: number): number; | ||
/** | ||
* Returns the remainder of the division of x by y that rounds the quotient | ||
* towards zero. (integer/float) | ||
*/ | ||
function fmod(x: number, y: number): number; | ||
/** | ||
* The float value HUGE_VAL, a value larger than any other numeric value. | ||
*/ | ||
const huge: number; | ||
/** | ||
* The float value HUGE_VAL, a value larger than any other numeric value. | ||
*/ | ||
const huge: 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 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 argument with the minimum value, according to the Lua operator | ||
* <. (integer/float) | ||
*/ | ||
function min(x: number, ...numbers: number[]): number; | ||
/** | ||
* Returns the integral part of x and the fractional part of x. Its second | ||
* result is always a float. | ||
* @tupleReturn | ||
*/ | ||
function modf(x: number): [number, number]; | ||
/** | ||
* Returns the integral part of x and the fractional part of x. Its second | ||
* result is always a float. | ||
*/ | ||
function modf(x: number): LuaMultiReturn<[number, number]>; | ||
/** | ||
* The value of π. | ||
*/ | ||
const pi: number; | ||
/** | ||
* The value of π. | ||
*/ | ||
const pi: number; | ||
/** | ||
* Converts the angle x from degrees to radians. | ||
*/ | ||
function rad(x: number): number; | ||
/** | ||
* Converts the angle x from degrees to radians. | ||
*/ | ||
function rad(x: number): number; | ||
/** | ||
* Returns the sine of x (assumed to be in radians). | ||
*/ | ||
function sin(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 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; | ||
/** | ||
* Returns the tangent of x (assumed to be in radians). | ||
*/ | ||
function tan(x: number): number; | ||
} |
// Based on https://www.lua.org/manual/5.3/manual.html#2.4 | ||
interface LuaMetatable<T, TIndex = object> { | ||
/** | ||
* 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 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 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 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 division (/) operation. Behavior similar to the addition operation. | ||
*/ | ||
__div?(this: T, operand: any): any; | ||
/** | ||
* the modulo (%) operation. Behavior similar to the addition operation. | ||
*/ | ||
__mod?(this: T, operand: any): any; | ||
/** | ||
* the modulo (%) operation. Behavior similar to the addition operation. | ||
*/ | ||
__mod?(this: T, operand: any): any; | ||
/** | ||
* the exponentiation (^) operation. Behavior similar to the addition | ||
* operation. | ||
*/ | ||
__pow?(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 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 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 length (#) operation. If the object is not a string, Lua will try its | ||
* metamethod. If there is a metamethod, Lua calls it with the object as | ||
* argument, and the result of the call (always adjusted to one value) is the | ||
* result of the operation. If there is no metamethod but the object is a | ||
* table, then Lua uses the table length operation (see §3.4.7). Otherwise, | ||
* Lua raises an error. | ||
*/ | ||
__len?(this: T): any; | ||
/** | ||
* the length (#) operation. If the object is not a string, Lua will try its | ||
* metamethod. If there is a metamethod, Lua calls it with the object as | ||
* argument, and the result of the call (always adjusted to one value) is the | ||
* result of the operation. If there is no metamethod but the object is a | ||
* table, then Lua uses the table length operation (see §3.4.7). Otherwise, | ||
* Lua raises an error. | ||
*/ | ||
__len?(this: T): 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 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 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 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 | ((this: T, key: any, value: any) => any); | ||
/** | ||
* 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 | ((this: T, key: any, value: any) => any); | ||
/** | ||
* 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 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; | ||
/** | ||
* 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 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 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; | ||
/** | ||
* 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; | ||
/** | ||
* 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; | ||
} |
@@ -41,102 +41,102 @@ // Based on https://www.lua.org/manual/5.3/manual.html#6.3 | ||
declare namespace package { | ||
/** | ||
* A string describing some compile-time configurations for packages. This | ||
* string is a sequence of lines: | ||
* * The first line is the directory separator string. Default is '\' for | ||
* Windows and '/' for all other systems. | ||
* * The second line is the character that separates templates in a path. | ||
* Default is ';'. | ||
* * The third line is the string that marks the substitution points in a | ||
* template. Default is '?'. | ||
* * The fourth line is a string that, in a path in Windows, is replaced by | ||
* the executable's directory. Default is '!'. | ||
* * The fifth line is a mark to ignore all text after it when building the | ||
* luaopen_ function name. Default is '-'. | ||
*/ | ||
var config: string; | ||
/** | ||
* A string describing some compile-time configurations for packages. This | ||
* string is a sequence of lines: | ||
* * The first line is the directory separator string. Default is '\' for | ||
* Windows and '/' for all other systems. | ||
* * The second line is the character that separates templates in a path. | ||
* Default is ';'. | ||
* * The third line is the string that marks the substitution points in a | ||
* template. Default is '?'. | ||
* * The fourth line is a string that, in a path in Windows, is replaced by | ||
* the executable's directory. Default is '!'. | ||
* * The fifth line is a mark to ignore all text after it when building the | ||
* luaopen_ function name. Default is '-'. | ||
*/ | ||
var config: string; | ||
/** | ||
* The path used by require to search for a C loader. | ||
* | ||
* Lua initializes the C path package.cpath in the same way it initializes the | ||
* Lua path package.path, using the environment variable LUA_CPATH_5_3, or the | ||
* environment variable LUA_CPATH, or a default path defined in luaconf.h. | ||
*/ | ||
var cpath: string; | ||
/** | ||
* The path used by require to search for a C loader. | ||
* | ||
* Lua initializes the C path package.cpath in the same way it initializes the | ||
* Lua path package.path, using the environment variable LUA_CPATH_5_3, or the | ||
* environment variable LUA_CPATH, or a default path defined in luaconf.h. | ||
*/ | ||
var cpath: string; | ||
/** | ||
* A table used by require to control which modules are already loaded. When | ||
* you require a module modname and package.loaded[modname] is not false, | ||
* require simply returns the value stored there. | ||
* | ||
* This variable is only a reference to the real table; assignments to this | ||
* variable do not change the table used by require. | ||
*/ | ||
const loaded: Record<string, any>; | ||
/** | ||
* A table used by require to control which modules are already loaded. When | ||
* you require a module modname and package.loaded[modname] is not false, | ||
* require simply returns the value stored there. | ||
* | ||
* This variable is only a reference to the real table; assignments to this | ||
* variable do not change the table used by require. | ||
*/ | ||
const loaded: Record<string, any>; | ||
/** | ||
* Dynamically links the host program with the C library libname. | ||
* | ||
* If funcname is "*", then it only links with the library, making the symbols | ||
* exported by the library available to other dynamically linked libraries. | ||
* Otherwise, it looks for a function funcname inside the library and returns | ||
* this function as a C function. So, funcname must follow the lua_CFunction | ||
* prototype (see lua_CFunction). | ||
* | ||
* This is a low-level function. It completely bypasses the package and module | ||
* system. Unlike require, it does not perform any path searching and does not | ||
* automatically adds extensions. libname must be the complete file name of | ||
* the C library, including if necessary a path and an extension. funcname | ||
* must be the exact name exported by the C library (which may depend on the C | ||
* compiler and linker used). | ||
* | ||
* This function is not supported by Standard C. As such, it is only available | ||
* on some platforms (Windows, Linux, Mac OS X, Solaris, BSD, plus other Unix | ||
* systems that support the dlfcn standard). | ||
*/ | ||
function loadlib( | ||
libname: string, | ||
funcname: string, | ||
): [Function] | [undefined, string, 'open' | 'init']; | ||
/** | ||
* Dynamically links the host program with the C library libname. | ||
* | ||
* If funcname is "*", then it only links with the library, making the symbols | ||
* exported by the library available to other dynamically linked libraries. | ||
* Otherwise, it looks for a function funcname inside the library and returns | ||
* this function as a C function. So, funcname must follow the lua_CFunction | ||
* prototype (see lua_CFunction). | ||
* | ||
* This is a low-level function. It completely bypasses the package and module | ||
* system. Unlike require, it does not perform any path searching and does not | ||
* automatically adds extensions. libname must be the complete file name of | ||
* the C library, including if necessary a path and an extension. funcname | ||
* must be the exact name exported by the C library (which may depend on the C | ||
* compiler and linker used). | ||
* | ||
* This function is not supported by Standard C. As such, it is only available | ||
* on some platforms (Windows, Linux, Mac OS X, Solaris, BSD, plus other Unix | ||
* systems that support the dlfcn standard). | ||
*/ | ||
function loadlib( | ||
libname: string, | ||
funcname: string | ||
): [Function] | [undefined, string, 'open' | 'init']; | ||
/** | ||
* The path used by require to search for a Lua loader. | ||
* | ||
* At start-up, Lua initializes this variable with the value of the | ||
* environment variable LUA_PATH_5_3 or the environment variable LUA_PATH or | ||
* with a default path defined in luaconf.h, if those environment variables | ||
* are not defined. Any ";;" in the value of the environment variable is | ||
* replaced by the default path. | ||
*/ | ||
var path: string; | ||
/** | ||
* The path used by require to search for a Lua loader. | ||
* | ||
* At start-up, Lua initializes this variable with the value of the | ||
* environment variable LUA_PATH_5_3 or the environment variable LUA_PATH or | ||
* with a default path defined in luaconf.h, if those environment variables | ||
* are not defined. Any ";;" in the value of the environment variable is | ||
* replaced by the default path. | ||
*/ | ||
var path: string; | ||
/** | ||
* A table to store loaders for specific modules (see require). | ||
* | ||
* This variable is only a reference to the real table; assignments to this | ||
* variable do not change the table used by require. | ||
*/ | ||
const preload: Record<string, (modname: string, fileName?: string) => any>; | ||
/** | ||
* A table to store loaders for specific modules (see require). | ||
* | ||
* This variable is only a reference to the real table; assignments to this | ||
* variable do not change the table used by require. | ||
*/ | ||
const preload: Record<string, (modname: string, fileName?: string) => any>; | ||
/** | ||
* Searches for the given name in the given path. | ||
* | ||
* A path is a string containing a sequence of templates separated by | ||
* semicolons. For each template, the function replaces each interrogation | ||
* mark (if any) in the template with a copy of name wherein all occurrences | ||
* of sep (a dot, by default) were replaced by rep (the system's directory | ||
* separator, by default), and then tries to open the resulting file name. | ||
* | ||
* For instance, if the path is the string | ||
* | ||
* `./?.lua;./?.lc;/usr/local/?/init.lua` | ||
* | ||
* the search for the name foo.a will try to open the files ./foo/a.lua, | ||
* ./foo/a.lc, and /usr/local/foo/a/init.lua, in that order. | ||
* | ||
* Returns the resulting name of the first file that it can open in read mode | ||
* (after closing the file), or nil plus an error message if none succeeds. | ||
* (This error message lists all file names it tried to open.) | ||
*/ | ||
function searchpath(name: string, path: string, sep?: string, rep?: string): string; | ||
/** | ||
* Searches for the given name in the given path. | ||
* | ||
* A path is a string containing a sequence of templates separated by | ||
* semicolons. For each template, the function replaces each interrogation | ||
* mark (if any) in the template with a copy of name wherein all occurrences | ||
* of sep (a dot, by default) were replaced by rep (the system's directory | ||
* separator, by default), and then tries to open the resulting file name. | ||
* | ||
* For instance, if the path is the string | ||
* | ||
* `./?.lua;./?.lc;/usr/local/?/init.lua` | ||
* | ||
* the search for the name foo.a will try to open the files ./foo/a.lua, | ||
* ./foo/a.lc, and /usr/local/foo/a/init.lua, in that order. | ||
* | ||
* Returns the resulting name of the first file that it can open in read mode | ||
* (after closing the file), or nil plus an error message if none succeeds. | ||
* (This error message lists all file names it tried to open.) | ||
*/ | ||
function searchpath(name: string, path: string, sep?: string, rep?: string): string; | ||
} |
350
core/os.d.ts
@@ -6,21 +6,21 @@ // Based on https://www.lua.org/manual/5.3/manual.html#6.9 | ||
interface LuaDateInfo { | ||
year: number; | ||
month: number; | ||
day: number; | ||
hour?: number; | ||
min?: number; | ||
sec?: number; | ||
isdst?: boolean; | ||
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; | ||
year: number; | ||
month: number; | ||
day: number; | ||
hour: number; | ||
min: number; | ||
sec: number; | ||
isdst: boolean; | ||
yday: number; | ||
wday: number; | ||
} | ||
@@ -32,172 +32,170 @@ | ||
declare namespace os { | ||
/** | ||
* Returns an approximation of the amount in seconds of CPU time used by the | ||
* program. | ||
*/ | ||
function clock(): number; | ||
/** | ||
* 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?: 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 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; | ||
/** | ||
* 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; | ||
/** | ||
* Returns the value of the process environment variable varname, or nil if | ||
* the variable is not defined. | ||
*/ | ||
function getenv(varname: string): string | undefined; | ||
/** | ||
* 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. | ||
* @tupleReturn | ||
*/ | ||
function remove(filename: string): [true] | [undefined, string]; | ||
/** | ||
* 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. | ||
* @tupleReturn | ||
*/ | ||
function rename(oldname: string, newname: string): [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; | ||
/** | ||
* 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(): 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 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; | ||
/** | ||
* 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; | ||
} |
@@ -21,191 +21,188 @@ // Based on https://www.lua.org/manual/5.3/manual.html#6.4 | ||
declare namespace string { | ||
/** | ||
* Returns the internal numeric codes of the characters s[i], s[i+1], ..., | ||
* s[j]. The default value for i is 1; the default value for j is i. These | ||
* indices are corrected following the same rules of function string.sub. | ||
* | ||
* Numeric codes are not necessarily portable across platforms. | ||
*/ | ||
function byte(s: string, i?: number): number; | ||
/** @tupleReturn */ | ||
function byte(s: string, i?: number, j?: number): number[]; | ||
/** | ||
* Returns the internal numeric codes of the characters s[i], s[i+1], ..., | ||
* s[j]. The default value for i is 1; the default value for j is i. These | ||
* indices are corrected following the same rules of function string.sub. | ||
* | ||
* Numeric codes are not necessarily portable across platforms. | ||
*/ | ||
function byte(s: string, i?: number): number; | ||
function byte(s: string, i?: number, j?: number): LuaMultiReturn<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; | ||
/** | ||
* 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; | ||
/** | ||
* 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. | ||
* @tupleReturn | ||
*/ | ||
function find( | ||
s: string, | ||
pattern: string, | ||
init?: number, | ||
plain?: boolean, | ||
): [number, number, ...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 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 (see §6.4.1) over the string s. If pattern specifies | ||
* no captures, then the whole match is produced in each call. | ||
* | ||
* As an example, the following loop will iterate over all the words from | ||
* string s, printing one per line: | ||
* | ||
* ``` | ||
* s = "hello world from Lua" | ||
* for w in string.gmatch(s, "%a+") do | ||
* print(w) | ||
* end | ||
* ``` | ||
* | ||
* 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.gmatch(s, "(%w+)=(%w+)") do | ||
* t[k] = v | ||
* end | ||
* ``` | ||
* | ||
* For this function, a caret '^' at the start of a pattern does not work as | ||
* an anchor, as this would prevent the iteration. | ||
*/ | ||
function gmatch(s: string, pattern: string): LuaTupleIterable<string[]>; | ||
/** | ||
* Returns an iterator function that, each time it is called, returns the next | ||
* captures from pattern (see §6.4.1) over the string s. If pattern specifies | ||
* no captures, then the whole match is produced in each call. | ||
* | ||
* As an example, the following loop will iterate over all the words from | ||
* string s, printing one per line: | ||
* | ||
* ``` | ||
* s = "hello world from Lua" | ||
* for w in string.gmatch(s, "%a+") do | ||
* print(w) | ||
* end | ||
* ``` | ||
* | ||
* 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.gmatch(s, "(%w+)=(%w+)") do | ||
* t[k] = v | ||
* end | ||
* ``` | ||
* | ||
* For this function, a caret '^' at the start of a pattern does not work as | ||
* an anchor, as this would prevent the iteration. | ||
*/ | ||
function gmatch(s: string, pattern: string): LuaIterable<LuaMultiReturn<string[]>>; | ||
/** | ||
* 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). | ||
* @tupleReturn | ||
*/ | ||
function gsub( | ||
s: string, | ||
pattern: string, | ||
repl: string | Record<string, string> | ((...matches: string[]) => string), | ||
n?: number, | ||
): [string, number]; | ||
/** | ||
* 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<string, string> | ((...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 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; | ||
/** | ||
* 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; | ||
/** | ||
* Looks for the first match of pattern (see §6.4.1) in the string s. If it | ||
* finds one, then match returns the captures from the pattern; otherwise it | ||
* returns nil. If pattern specifies no captures, then the whole match is | ||
* returned. A third, optional numeric argument init specifies where to start | ||
* the search; its default value is 1 and can be negative. | ||
*/ | ||
function match(s: string, pattern: string, init?: number): string[]; | ||
/** | ||
* Looks for the first match of pattern (see §6.4.1) in the string s. If it | ||
* finds one, then match returns the captures from the pattern; otherwise it | ||
* returns nil. If pattern specifies no captures, then the whole match is | ||
* returned. A third, optional numeric argument init specifies where to start | ||
* the search; its default value is 1 and can be negative. | ||
*/ | ||
function match(s: string, pattern: string, init?: number): LuaMultiReturn<string[]>; | ||
/** | ||
* Returns a string that is the string s reversed. | ||
*/ | ||
function reverse(s: string): string; | ||
/** | ||
* Returns a string that is the string s reversed. | ||
*/ | ||
function reverse(s: string): 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; | ||
/** | ||
* 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; | ||
/** | ||
* 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; | ||
} |
@@ -14,46 +14,46 @@ // Based on https://www.lua.org/manual/5.3/manual.html#6.6 | ||
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; | ||
/** | ||
* 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; | ||
/** | ||
* 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<T>(list: T[], value: T): void; | ||
function insert<T>(list: T[], pos: number, value: T): void; | ||
/** | ||
* 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<T>(list: T[], value: T): void; | ||
function insert<T>(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<T>(list: T[], pos?: number): T | undefined; | ||
/** | ||
* 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<T>(list: T[], pos?: number): T | undefined; | ||
/** | ||
* 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<T>(list: T[], comp?: (a: T, b: T) => boolean): 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<T>(list: T[], comp?: (a: T, b: T) => boolean): void; | ||
} |
@@ -1,2 +0,2 @@ | ||
import './core'; | ||
import './special/jit'; | ||
/// <reference path="./core/index.d.ts" /> | ||
/// <reference path="./special/jit.d.ts" /> |
{ | ||
"name": "lua-types", | ||
"version": "2.8.0", | ||
"description": "TypeScript definitions for Lua standard library", | ||
"keywords": [ | ||
"lua", | ||
"typescript", | ||
"tstl" | ||
], | ||
"repository": "https://github.com/ark120202/lua-types", | ||
"license": "MIT", | ||
"author": "ark120202", | ||
"files": [ | ||
"**/*.d.ts" | ||
], | ||
"scripts": { | ||
"lint": "prettier --check ." | ||
}, | ||
"prettier": { | ||
"printWidth": 100, | ||
"proseWrap": "never", | ||
"singleQuote": true, | ||
"trailingComma": "all" | ||
}, | ||
"devDependencies": { | ||
"prettier": "^2.0.5", | ||
"typescript-to-lua": "^0.32.2" | ||
} | ||
"name": "lua-types", | ||
"version": "2.9.1", | ||
"description": "TypeScript definitions for Lua standard library", | ||
"keywords": [ | ||
"lua", | ||
"typescript", | ||
"tstl" | ||
], | ||
"repository": "https://github.com/ark120202/lua-types", | ||
"license": "MIT", | ||
"author": "ark120202", | ||
"files": [ | ||
"**/*.d.ts", | ||
"tsconfig.json" | ||
], | ||
"scripts": { | ||
"test": "jest", | ||
"lint": "prettier --check ." | ||
}, | ||
"prettier": { | ||
"printWidth": 100, | ||
"tabWidth": 4, | ||
"proseWrap": "never", | ||
"singleQuote": true | ||
}, | ||
"dependencies": { | ||
"typescript-to-lua": "^0.39.0" | ||
}, | ||
"devDependencies": { | ||
"@types/jest": "^26.0.20", | ||
"@types/node": "^14.14.34", | ||
"jest": "^26.6.3", | ||
"jest-circus": "^26.6.3", | ||
"prettier": "^2.0.5", | ||
"ts-jest": "^26.5.3" | ||
} | ||
} |
@@ -9,3 +9,3 @@ # Lua Types | ||
> NOTE: In most of cases your environment-specific types would already include this package. In that case you don't need to do anything. If you're a developer of such types you should add `lua-types` as a dependency and load it by adding `/// <reference types="lua-types/version" />` | ||
> NOTE: In most of cases your environment-specific types would already include this package. In that case you don't need to do anything. If you're a developer of such types you should add `lua-types` as a dependency and load it by adding `/// <reference types="lua-types/<version>" />` | ||
@@ -25,4 +25,3 @@ 1. Get this package from npm | ||
"compilerOptions": { | ||
+ "moduleResolution": "node" | ||
+ "types": ["lua-types/version"] | ||
+ "types": ["lua-types/<version>"] | ||
} | ||
@@ -32,10 +31,10 @@ } | ||
Currently supported versions are: | ||
Where `<version>` is one of: | ||
- `5.1` | ||
- `5.2` | ||
- `5.3` | ||
- `5.4` | ||
- `jit` | ||
- `5.1` | ||
- `5.2` | ||
- `5.3` | ||
- `5.4` | ||
- `jit` | ||
> NOTE: All other files in this module shouldn't be considered public. Do not import them manually, as they may change in non-major updates. If your environment doesn't provide all of standard Lua features, consider banning them with a [no-restricted-globals](https://eslint.org/docs/rules/no-restricted-globals) eslint rule. |
@@ -14,8 +14,7 @@ /** @noSelfInFile */ | ||
* When absent, it defaults to "=(load)". | ||
* @tupleReturn | ||
*/ | ||
declare function load( | ||
func: () => string | null | undefined, | ||
chunkname?: string, | ||
): [() => any] | [undefined, string]; | ||
func: () => string | null | undefined, | ||
chunkname?: string | ||
): LuaMultiReturn<[() => any] | [undefined, string]>; | ||
@@ -25,5 +24,4 @@ /** | ||
* input, if no file name is given. | ||
* @tupleReturn | ||
*/ | ||
declare function loadfile(filename?: string): [() => any] | [undefined, string]; | ||
declare function loadfile(filename?: string): LuaMultiReturn<[() => any] | [undefined, string]>; | ||
@@ -38,5 +36,7 @@ /** | ||
* When absent, chunkname defaults to the given string. | ||
* @tupleReturn | ||
*/ | ||
declare function loadstring(string: string, chunkname?: string): [() => any] | [undefined, string]; | ||
declare function loadstring( | ||
string: string, | ||
chunkname?: string | ||
): LuaMultiReturn<[() => any] | [undefined, string]>; | ||
@@ -54,46 +54,50 @@ /** | ||
* false plus the result from err. | ||
* @tupleReturn | ||
*/ | ||
declare function xpcall<R, E>(f: () => R, err: (err: any) => E): [true, R] | [false, E]; | ||
declare function xpcall<R, E>( | ||
f: () => R, | ||
err: (err: any) => E | ||
): LuaMultiReturn<[true, R] | [false, E]>; | ||
declare namespace math { | ||
/** | ||
* Returns the logarithm of x. | ||
*/ | ||
function log(x: number): number; | ||
/** | ||
* Returns the logarithm of x. | ||
*/ | ||
function log(x: number): number; | ||
} | ||
declare namespace string { | ||
/** | ||
* Returns a string that is the concatenation of n copies of the string s. | ||
*/ | ||
function rep(s: string, n: number): string; | ||
/** | ||
* Returns a string that is the concatenation of n copies of the string s. | ||
*/ | ||
function rep(s: string, n: number): string; | ||
} | ||
declare namespace os { | ||
/** | ||
* 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; | ||
/** | ||
* 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; | ||
} | ||
declare namespace debug { | ||
/** | ||
* 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.) | ||
* | ||
* Variable names starting with '(' (open parentheses) represent internal | ||
* variables (loop control variables, temporaries, and C function locals). | ||
* @tupleReturn | ||
*/ | ||
function getlocal(level: number, local: number): [string, any]; | ||
/** @tupleReturn */ | ||
function getlocal(thread: LuaThread, level: number, local: number): [string, any]; | ||
/** | ||
* 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.) | ||
* | ||
* Variable names starting with '(' (open parentheses) represent internal | ||
* variables (loop control variables, temporaries, and C function locals). | ||
*/ | ||
function getlocal(level: number, local: number): LuaMultiReturn<[string, any]>; | ||
function getlocal( | ||
thread: LuaThread, | ||
level: number, | ||
local: number | ||
): LuaMultiReturn<[string, any]>; | ||
} | ||
type FileReadFormat = '*n' | '*a' | '*l' | number; |
@@ -21,7 +21,5 @@ /** @noSelfInFile */ | ||
* the length operator (see §2.5.5). | ||
* @tupleReturn | ||
*/ | ||
declare function unpack<T extends any[]>(list: T): T; | ||
/** @tupleReturn */ | ||
declare function unpack<T>(list: T[], i: number, j?: number): T[]; | ||
declare function unpack<T extends any[]>(list: T): LuaMultiReturn<T[]>; | ||
declare function unpack<T>(list: T[], i: number, j?: number): LuaMultiReturn<T[]>; | ||
@@ -49,95 +47,95 @@ /** | ||
declare namespace debug { | ||
/** | ||
* Returns the environment of object o. | ||
*/ | ||
function getfenv(o: object): any; | ||
/** | ||
* Returns the environment of object o. | ||
*/ | ||
function getfenv(o: object): any; | ||
/** | ||
* Sets the environment of the given object to the given table. Returns | ||
* object. | ||
*/ | ||
function setfenv<T extends object>(o: T, table: object): T; | ||
/** | ||
* Sets the environment of the given object to the given table. Returns | ||
* object. | ||
*/ | ||
function setfenv<T extends object>(o: T, table: object): T; | ||
} | ||
declare namespace package { | ||
/** | ||
* A table used by require to control how to load modules. | ||
* | ||
* Each entry in this table is a searcher function. When looking for a module, | ||
* require calls each of these searchers in ascending order, with the module | ||
* name (the argument given to require) as its sole parameter. The function | ||
* can return another function (the module loader) plus an extra value that | ||
* will be passed to that loader, or a string explaining why it did not find | ||
* that module (or nil if it has nothing to say). | ||
* | ||
* Lua initializes this table with four searcher functions. | ||
* | ||
* The first searcher simply looks for a loader in the package.preload table. | ||
* | ||
* The second searcher looks for a loader as a Lua library, using the path | ||
* stored at package.path. The search is done as described in function | ||
* package.searchpath. | ||
* | ||
* The third searcher looks for a loader as a C library, using the path given | ||
* by the variable package.cpath. Again, the search is done as described in | ||
* function package.searchpath. For instance, if the C path is the string | ||
* | ||
* `./?.so;./?.dll;/usr/local/?/init.so` | ||
* | ||
* the searcher for module foo will try to open the files ./foo.so, ./foo.dll, | ||
* and /usr/local/foo/init.so, in that order. Once it finds a C library, this | ||
* searcher first uses a dynamic link facility to link the application with | ||
* the library. Then it tries to find a C function inside the library to be | ||
* used as the loader. The name of this C function is the string "luaopen_" | ||
* concatenated with a copy of the module name where each dot is replaced by | ||
* an underscore. Moreover, if the module name has a hyphen, its suffix after | ||
* (and including) the first hyphen is removed. For instance, if the module | ||
* name is a.b.c-v2.1, the function name will be luaopen_a_b_c. | ||
* | ||
* The fourth searcher tries an all-in-one loader. It searches the C path for | ||
* a library for the root name of the given module. For instance, when | ||
* requiring a.b.c, it will search for a C library for a. If found, it looks | ||
* into it for an open function for the submodule; in our example, that would | ||
* be luaopen_a_b_c. With this facility, a package can pack several C | ||
* submodules into one single library, with each submodule keeping its | ||
* original open function. | ||
*/ | ||
var loaders: ( | ||
| /** @tupleReturn */ ((modname: string) => [(modname: string) => void]) | ||
| /** @tupleReturn */ (<T>(modname: string) => [(modname: string, extra: T) => T, T]) | ||
| string | ||
)[]; | ||
/** | ||
* A table used by require to control how to load modules. | ||
* | ||
* Each entry in this table is a searcher function. When looking for a module, | ||
* require calls each of these searchers in ascending order, with the module | ||
* name (the argument given to require) as its sole parameter. The function | ||
* can return another function (the module loader) plus an extra value that | ||
* will be passed to that loader, or a string explaining why it did not find | ||
* that module (or nil if it has nothing to say). | ||
* | ||
* Lua initializes this table with four searcher functions. | ||
* | ||
* The first searcher simply looks for a loader in the package.preload table. | ||
* | ||
* The second searcher looks for a loader as a Lua library, using the path | ||
* stored at package.path. The search is done as described in function | ||
* package.searchpath. | ||
* | ||
* The third searcher looks for a loader as a C library, using the path given | ||
* by the variable package.cpath. Again, the search is done as described in | ||
* function package.searchpath. For instance, if the C path is the string | ||
* | ||
* `./?.so;./?.dll;/usr/local/?/init.so` | ||
* | ||
* the searcher for module foo will try to open the files ./foo.so, ./foo.dll, | ||
* and /usr/local/foo/init.so, in that order. Once it finds a C library, this | ||
* searcher first uses a dynamic link facility to link the application with | ||
* the library. Then it tries to find a C function inside the library to be | ||
* used as the loader. The name of this C function is the string "luaopen_" | ||
* concatenated with a copy of the module name where each dot is replaced by | ||
* an underscore. Moreover, if the module name has a hyphen, its suffix after | ||
* (and including) the first hyphen is removed. For instance, if the module | ||
* name is a.b.c-v2.1, the function name will be luaopen_a_b_c. | ||
* | ||
* The fourth searcher tries an all-in-one loader. It searches the C path for | ||
* a library for the root name of the given module. For instance, when | ||
* requiring a.b.c, it will search for a C library for a. If found, it looks | ||
* into it for an open function for the submodule; in our example, that would | ||
* be luaopen_a_b_c. With this facility, a package can pack several C | ||
* submodules into one single library, with each submodule keeping its | ||
* original open function. | ||
*/ | ||
var loaders: ( | ||
| ((modname: string) => LuaMultiReturn<[(modname: string) => void]>) | ||
| (<T>(modname: string) => LuaMultiReturn<[(modname: string, extra: T) => T, T]>) | ||
| string | ||
)[]; | ||
} | ||
declare namespace os { | ||
/** | ||
* 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; | ||
/** | ||
* 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; | ||
} | ||
declare namespace math { | ||
/** | ||
* Returns the base-10 logarithm of x. | ||
*/ | ||
function log10(x: number): number; | ||
/** | ||
* Returns the base-10 logarithm of x. | ||
*/ | ||
function log10(x: number): number; | ||
} | ||
declare namespace table { | ||
/** | ||
* Returns the largest positive numerical index of the given table, or zero if | ||
* the table has no positive numerical indices. (To do its job this function | ||
* does a linear traversal of the whole table.) | ||
*/ | ||
function maxn(table: object): number; | ||
/** | ||
* Returns the largest positive numerical index of the given table, or zero if | ||
* the table has no positive numerical indices. (To do its job this function | ||
* does a linear traversal of the whole table.) | ||
*/ | ||
function maxn(table: object): number; | ||
} | ||
declare namespace coroutine { | ||
/** | ||
* Returns the running coroutine, or nil when called by the main thread. | ||
*/ | ||
function running(): LuaThread | undefined; | ||
/** | ||
* Returns the running coroutine, or nil when called by the main thread. | ||
*/ | ||
function running(): LuaThread | undefined; | ||
} |
@@ -1,4 +0,4 @@ | ||
import './5.1-only'; | ||
import './5.1-or-jit'; | ||
import './5.3-pre'; | ||
import './5.4-pre'; | ||
/// <reference path="./5.1-only.d.ts" /> | ||
/// <reference path="./5.1-or-jit.d.ts" /> | ||
/// <reference path="./5.3-pre.d.ts" /> | ||
/// <reference path="./5.4-pre.d.ts" /> |
@@ -47,109 +47,109 @@ /** @noSelfInFile */ | ||
declare namespace bit32 { | ||
/** | ||
* Returns the number x shifted disp bits to the right. The number disp may be | ||
* any representable integer. Negative displacements shift to the left. | ||
* | ||
* This shift operation is what is called arithmetic shift. Vacant bits on the | ||
* left are filled with copies of the higher bit of x; vacant bits on the | ||
* right are filled with zeros. In particular, displacements with absolute | ||
* values higher than 31 result in zero or 0xFFFFFFFF (all original bits are | ||
* shifted out). | ||
*/ | ||
function arshift(x: number, disp: number): number; | ||
/** | ||
* Returns the number x shifted disp bits to the right. The number disp may be | ||
* any representable integer. Negative displacements shift to the left. | ||
* | ||
* This shift operation is what is called arithmetic shift. Vacant bits on the | ||
* left are filled with copies of the higher bit of x; vacant bits on the | ||
* right are filled with zeros. In particular, displacements with absolute | ||
* values higher than 31 result in zero or 0xFFFFFFFF (all original bits are | ||
* shifted out). | ||
*/ | ||
function arshift(x: number, disp: number): number; | ||
/** | ||
* Returns the bitwise and of its operands. | ||
*/ | ||
function band(...operands: number[]): number; | ||
/** | ||
* Returns the bitwise and of its operands. | ||
*/ | ||
function band(...operands: number[]): number; | ||
/** | ||
* Returns the bitwise negation of x. For any integer x, the following | ||
* identity holds: | ||
* | ||
* `assert(bit32.bnot(x) == (-1 - x) % 2^32)` | ||
*/ | ||
function bnot(x: number): number; | ||
/** | ||
* Returns the bitwise negation of x. For any integer x, the following | ||
* identity holds: | ||
* | ||
* `assert(bit32.bnot(x) == (-1 - x) % 2^32)` | ||
*/ | ||
function bnot(x: number): number; | ||
/** | ||
* Returns the bitwise or of its operands. | ||
*/ | ||
function bor(...operands: number[]): number; | ||
/** | ||
* Returns the bitwise or of its operands. | ||
*/ | ||
function bor(...operands: number[]): number; | ||
/** | ||
* Returns a boolean signaling whether the bitwise and of its operands is | ||
* different from zero. | ||
*/ | ||
function btest(...operands: number[]): boolean; | ||
/** | ||
* Returns a boolean signaling whether the bitwise and of its operands is | ||
* different from zero. | ||
*/ | ||
function btest(...operands: number[]): boolean; | ||
/** | ||
* Returns the bitwise exclusive or of its operands. | ||
*/ | ||
function bxor(...operands: number[]): number; | ||
/** | ||
* Returns the bitwise exclusive or of its operands. | ||
*/ | ||
function bxor(...operands: number[]): number; | ||
/** | ||
* Returns the unsigned number formed by the bits field to field + width - 1 | ||
* from n. Bits are numbered from 0 (least significant) to 31 (most | ||
* significant). All accessed bits must be in the range [0, 31]. | ||
* | ||
* The default for width is 1. | ||
*/ | ||
function extract(n: number, field: number, width?: number): number; | ||
/** | ||
* Returns the unsigned number formed by the bits field to field + width - 1 | ||
* from n. Bits are numbered from 0 (least significant) to 31 (most | ||
* significant). All accessed bits must be in the range [0, 31]. | ||
* | ||
* The default for width is 1. | ||
*/ | ||
function extract(n: number, field: number, width?: number): number; | ||
/** | ||
* Returns a copy of n with the bits field to field + width - 1 replaced by | ||
* the value v. See bit32.extract for details about field and width. | ||
*/ | ||
function replace(n: number, v: number, field: number, width?: number): number; | ||
/** | ||
* Returns a copy of n with the bits field to field + width - 1 replaced by | ||
* the value v. See bit32.extract for details about field and width. | ||
*/ | ||
function replace(n: number, v: number, field: number, width?: number): number; | ||
/** | ||
* Returns the number x rotated disp bits to the left. The number disp may be | ||
* any representable integer. | ||
* | ||
* For any valid displacement, the following identity holds: | ||
* | ||
* `assert(bit32.lrotate(x, disp) == bit32.lrotate(x, disp % 32))` | ||
* | ||
* In particular, negative displacements rotate to the right. | ||
*/ | ||
function lrotate(x: number, disp: number): number; | ||
/** | ||
* Returns the number x rotated disp bits to the left. The number disp may be | ||
* any representable integer. | ||
* | ||
* For any valid displacement, the following identity holds: | ||
* | ||
* `assert(bit32.lrotate(x, disp) == bit32.lrotate(x, disp % 32))` | ||
* | ||
* In particular, negative displacements rotate to the right. | ||
*/ | ||
function lrotate(x: number, disp: number): number; | ||
/** | ||
* Returns the number x shifted disp bits to the left. The number disp may be | ||
* any representable integer. Negative displacements shift to the right. In | ||
* any direction, vacant bits are filled with zeros. In particular, | ||
* displacements with absolute values higher than 31 result in zero (all bits | ||
* are shifted out). | ||
* | ||
* For positive displacements, the following equality holds: | ||
* | ||
* `assert(bit32.lshift(b, disp) == (b * 2^disp) % 2^32)` | ||
*/ | ||
function lshift(x: number, disp: number): number; | ||
/** | ||
* Returns the number x shifted disp bits to the left. The number disp may be | ||
* any representable integer. Negative displacements shift to the right. In | ||
* any direction, vacant bits are filled with zeros. In particular, | ||
* displacements with absolute values higher than 31 result in zero (all bits | ||
* are shifted out). | ||
* | ||
* For positive displacements, the following equality holds: | ||
* | ||
* `assert(bit32.lshift(b, disp) == (b * 2^disp) % 2^32)` | ||
*/ | ||
function lshift(x: number, disp: number): number; | ||
/** | ||
* Returns the number x rotated disp bits to the right. The number disp may be | ||
* any representable integer. | ||
* | ||
* For any valid displacement, the following identity holds: | ||
* | ||
* `assert(bit32.rrotate(x, disp) == bit32.rrotate(x, disp % 32))` | ||
* | ||
* In particular, negative displacements rotate to the left. | ||
*/ | ||
function rrotate(x: number, disp: number): number; | ||
/** | ||
* Returns the number x rotated disp bits to the right. The number disp may be | ||
* any representable integer. | ||
* | ||
* For any valid displacement, the following identity holds: | ||
* | ||
* `assert(bit32.rrotate(x, disp) == bit32.rrotate(x, disp % 32))` | ||
* | ||
* In particular, negative displacements rotate to the left. | ||
*/ | ||
function rrotate(x: number, disp: number): number; | ||
/** | ||
* Returns the number x shifted disp bits to the right. The number disp may be | ||
* any representable integer. Negative displacements shift to the left. In any | ||
* direction, vacant bits are filled with zeros. In particular, displacements | ||
* with absolute values higher than 31 result in zero (all bits are shifted | ||
* out). | ||
* | ||
* For positive displacements, the following equality holds: | ||
* | ||
* `assert(bit32.rshift(b, disp) == math.floor(b % 2^32 / 2^disp))` | ||
* | ||
* This shift operation is what is called logical shift. | ||
*/ | ||
function rshift(x: number, disp: number): number; | ||
/** | ||
* Returns the number x shifted disp bits to the right. The number disp may be | ||
* any representable integer. Negative displacements shift to the left. In any | ||
* direction, vacant bits are filled with zeros. In particular, displacements | ||
* with absolute values higher than 31 result in zero (all bits are shifted | ||
* out). | ||
* | ||
* For positive displacements, the following equality holds: | ||
* | ||
* `assert(bit32.rshift(b, disp) == math.floor(b % 2^32 / 2^disp))` | ||
* | ||
* This shift operation is what is called logical shift. | ||
*/ | ||
function rshift(x: number, disp: number): number; | ||
} |
@@ -33,10 +33,9 @@ /** @noSelfInFile */ | ||
* binary chunks can crash the interpreter. | ||
* @tupleReturn | ||
*/ | ||
declare function load( | ||
chunk: string | (() => string | null | undefined), | ||
chunkname?: string, | ||
mode?: 'b' | 't' | 'bt', | ||
env?: object, | ||
): [() => any] | [undefined, string]; | ||
chunk: string | (() => string | null | undefined), | ||
chunkname?: string, | ||
mode?: 'b' | 't' | 'bt', | ||
env?: object | ||
): LuaMultiReturn<[() => any] | [undefined, string]>; | ||
@@ -46,9 +45,8 @@ /** | ||
* input, if no file name is given. | ||
* @tupleReturn | ||
*/ | ||
declare function loadfile( | ||
filename?: string, | ||
mode?: 'b' | 't' | 'bt', | ||
env?: object, | ||
): [() => any] | [undefined, string]; | ||
filename?: string, | ||
mode?: 'b' | 't' | 'bt', | ||
env?: object | ||
): LuaMultiReturn<[() => any] | [undefined, string]>; | ||
@@ -58,98 +56,98 @@ /** | ||
* msgh. | ||
* @tupleReturn | ||
*/ | ||
declare function xpcall<This, Args extends any[], R, E>( | ||
f: (this: This, ...args: Args) => R, | ||
msgh: (this: void, err: any) => E, | ||
context: This, | ||
...args: Args | ||
): [true, R] | [false, E]; | ||
f: (this: This, ...args: Args) => R, | ||
msgh: (this: void, err: any) => E, | ||
context: This, | ||
...args: Args | ||
): LuaMultiReturn<[true, R] | [false, E]>; | ||
/** @tupleReturn */ | ||
declare function xpcall<Args extends any[], R, E>( | ||
f: (this: void, ...args: Args) => R, | ||
msgh: (err: any) => E, | ||
...args: Args | ||
): [true, R] | [false, E]; | ||
f: (this: void, ...args: Args) => R, | ||
msgh: (err: any) => E, | ||
...args: Args | ||
): LuaMultiReturn<[true, R] | [false, E]>; | ||
declare namespace debug { | ||
interface FunctionInfo<T extends Function = Function> { | ||
nparams: number; | ||
isvararg: boolean; | ||
} | ||
interface FunctionInfo<T extends Function = Function> { | ||
nparams: number; | ||
isvararg: boolean; | ||
} | ||
/** | ||
* This function returns the name and the value of the local variable with | ||
* index local of the function at level f of the stack. This function accesses | ||
* not only explicit local variables, but also parameters, temporaries, etc. | ||
* | ||
* The first parameter or local variable has index 1, and so on, following the | ||
* order that they are declared in the code, counting only the variables that | ||
* are active in the current scope of the function. Negative indices refer to | ||
* vararg parameters; -1 is the first vararg parameter. The function returns | ||
* nil if there is no 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.) | ||
* | ||
* Variable names starting with '(' (open parenthesis) represent variables | ||
* with no known names (internal variables such as loop control variables, and | ||
* variables from chunks saved without debug information). | ||
* | ||
* The parameter f may also be a function. In that case, getlocal returns only | ||
* the name of function parameters. | ||
* @tupleReturn | ||
*/ | ||
function getlocal(f: Function | number, local: number): [string, any]; | ||
/** @tupleReturn */ | ||
function getlocal(thread: LuaThread, f: Function | number, local: number): [string, any]; | ||
/** | ||
* This function returns the name and the value of the local variable with | ||
* index local of the function at level f of the stack. This function accesses | ||
* not only explicit local variables, but also parameters, temporaries, etc. | ||
* | ||
* The first parameter or local variable has index 1, and so on, following the | ||
* order that they are declared in the code, counting only the variables that | ||
* are active in the current scope of the function. Negative indices refer to | ||
* vararg parameters; -1 is the first vararg parameter. The function returns | ||
* nil if there is no 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.) | ||
* | ||
* Variable names starting with '(' (open parenthesis) represent variables | ||
* with no known names (internal variables such as loop control variables, and | ||
* variables from chunks saved without debug information). | ||
* | ||
* The parameter f may also be a function. In that case, getlocal returns only | ||
* the name of function parameters. | ||
*/ | ||
function getlocal(f: Function | number, local: number): LuaMultiReturn<[string, any]>; | ||
function getlocal( | ||
thread: LuaThread, | ||
f: Function | number, | ||
local: number | ||
): LuaMultiReturn<[string, any]>; | ||
/** | ||
* Returns a unique identifier (as a light userdata) for the upvalue numbered | ||
* n from the given function. | ||
* | ||
* These unique identifiers allow a program to check whether different | ||
* closures share upvalues. Lua closures that share an upvalue (that is, that | ||
* access a same external local variable) will return identical ids for those | ||
* upvalue indices. | ||
*/ | ||
function upvalueid(f: Function, n: number): LuaUserdata; | ||
/** | ||
* Returns a unique identifier (as a light userdata) for the upvalue numbered | ||
* n from the given function. | ||
* | ||
* These unique identifiers allow a program to check whether different | ||
* closures share upvalues. Lua closures that share an upvalue (that is, that | ||
* access a same external local variable) will return identical ids for those | ||
* upvalue indices. | ||
*/ | ||
function upvalueid(f: Function, n: number): LuaUserdata; | ||
/** | ||
* Make the n1-th upvalue of the Lua closure f1 refer to the n2-th upvalue of | ||
* the Lua closure f2. | ||
*/ | ||
function upvaluejoin(f1: Function, n1: number, f2: Function, n2: number): void; | ||
/** | ||
* Make the n1-th upvalue of the Lua closure f1 refer to the n2-th upvalue of | ||
* the Lua closure f2. | ||
*/ | ||
function upvaluejoin(f1: Function, n1: number, f2: Function, n2: number): void; | ||
} | ||
declare namespace math { | ||
/** | ||
* Returns the logarithm of x in the given base. The default for base is e (so | ||
* that the function returns the natural logarithm of x). | ||
*/ | ||
function log(x: number, base?: number): number; | ||
/** | ||
* Returns the logarithm of x in the given base. The default for base is e (so | ||
* that the function returns the natural logarithm of x). | ||
*/ | ||
function log(x: number, base?: number): number; | ||
} | ||
declare namespace string { | ||
/** | ||
* Returns a string that is the concatenation of n copies of the string s | ||
* separated by the string sep. The default value for sep is the empty string | ||
* (that is, no separator). Returns the empty string if n is not positive. | ||
* | ||
* (Note that it is very easy to exhaust the memory of your machine with a | ||
* single call to this function.) | ||
*/ | ||
function rep(s: string, n: number, sep?: string): string; | ||
/** | ||
* Returns a string that is the concatenation of n copies of the string s | ||
* separated by the string sep. The default value for sep is the empty string | ||
* (that is, no separator). Returns the empty string if n is not positive. | ||
* | ||
* (Note that it is very easy to exhaust the memory of your machine with a | ||
* single call to this function.) | ||
*/ | ||
function rep(s: string, n: number, sep?: string): string; | ||
} | ||
declare namespace os { | ||
/** | ||
* Calls the ISO C function exit to terminate the host program. If code is | ||
* true, the returned status is EXIT_SUCCESS; if code is false, the returned | ||
* status is EXIT_FAILURE; if code is a number, the returned status is this | ||
* number. The default value for code is true. | ||
* | ||
* If the optional second argument close is true, closes the Lua state before | ||
* exiting. | ||
*/ | ||
function exit(code?: boolean | number, close?: boolean): never; | ||
/** | ||
* Calls the ISO C function exit to terminate the host program. If code is | ||
* true, the returned status is EXIT_SUCCESS; if code is false, the returned | ||
* status is EXIT_FAILURE; if code is a number, the returned status is this | ||
* number. The default value for code is true. | ||
* | ||
* If the optional second argument close is true, closes the Lua state before | ||
* exiting. | ||
*/ | ||
function exit(code?: boolean | number, close?: boolean): never; | ||
} |
@@ -36,136 +36,134 @@ /** @noSelfInFile */ | ||
declare namespace package { | ||
/** | ||
* A table used by require to control how to load modules. | ||
* | ||
* Each entry in this table is a searcher function. When looking for a module, | ||
* require calls each of these searchers in ascending order, with the module | ||
* name (the argument given to require) as its sole parameter. The function | ||
* can return another function (the module loader) plus an extra value that | ||
* will be passed to that loader, or a string explaining why it did not find | ||
* that module (or nil if it has nothing to say). | ||
* | ||
* Lua initializes this table with four searcher functions. | ||
* | ||
* The first searcher simply looks for a loader in the package.preload table. | ||
* | ||
* The second searcher looks for a loader as a Lua library, using the path | ||
* stored at package.path. The search is done as described in function | ||
* package.searchpath. | ||
* | ||
* The third searcher looks for a loader as a C library, using the path given | ||
* by the variable package.cpath. Again, the search is done as described in | ||
* function package.searchpath. For instance, if the C path is the string | ||
* | ||
* `./?.so;./?.dll;/usr/local/?/init.so` | ||
* | ||
* the searcher for module foo will try to open the files ./foo.so, ./foo.dll, | ||
* and /usr/local/foo/init.so, in that order. Once it finds a C library, this | ||
* searcher first uses a dynamic link facility to link the application with | ||
* the library. Then it tries to find a C function inside the library to be | ||
* used as the loader. The name of this C function is the string "luaopen_" | ||
* concatenated with a copy of the module name where each dot is replaced by | ||
* an underscore. Moreover, if the module name has a hyphen, its suffix after | ||
* (and including) the first hyphen is removed. For instance, if the module | ||
* name is a.b.c-v2.1, the function name will be luaopen_a_b_c. | ||
* | ||
* The fourth searcher tries an all-in-one loader. It searches the C path for | ||
* a library for the root name of the given module. For instance, when | ||
* requiring a.b.c, it will search for a C library for a. If found, it looks | ||
* into it for an open function for the submodule; in our example, that would | ||
* be luaopen_a_b_c. With this facility, a package can pack several C | ||
* submodules into one single library, with each submodule keeping its | ||
* original open function. | ||
* | ||
* All searchers except the first one (preload) return as the extra value the | ||
* file name where the module was found, as returned by package.searchpath. | ||
* The first searcher returns no extra value. | ||
*/ | ||
var searchers: ( | ||
| /** @tupleReturn */ ((modname: string) => [(modname: string) => void]) | ||
| /** @tupleReturn */ (<T>(modname: string) => [(modname: string, extra: T) => T, T]) | ||
| string | ||
)[]; | ||
/** | ||
* A table used by require to control how to load modules. | ||
* | ||
* Each entry in this table is a searcher function. When looking for a module, | ||
* require calls each of these searchers in ascending order, with the module | ||
* name (the argument given to require) as its sole parameter. The function | ||
* can return another function (the module loader) plus an extra value that | ||
* will be passed to that loader, or a string explaining why it did not find | ||
* that module (or nil if it has nothing to say). | ||
* | ||
* Lua initializes this table with four searcher functions. | ||
* | ||
* The first searcher simply looks for a loader in the package.preload table. | ||
* | ||
* The second searcher looks for a loader as a Lua library, using the path | ||
* stored at package.path. The search is done as described in function | ||
* package.searchpath. | ||
* | ||
* The third searcher looks for a loader as a C library, using the path given | ||
* by the variable package.cpath. Again, the search is done as described in | ||
* function package.searchpath. For instance, if the C path is the string | ||
* | ||
* `./?.so;./?.dll;/usr/local/?/init.so` | ||
* | ||
* the searcher for module foo will try to open the files ./foo.so, ./foo.dll, | ||
* and /usr/local/foo/init.so, in that order. Once it finds a C library, this | ||
* searcher first uses a dynamic link facility to link the application with | ||
* the library. Then it tries to find a C function inside the library to be | ||
* used as the loader. The name of this C function is the string "luaopen_" | ||
* concatenated with a copy of the module name where each dot is replaced by | ||
* an underscore. Moreover, if the module name has a hyphen, its suffix after | ||
* (and including) the first hyphen is removed. For instance, if the module | ||
* name is a.b.c-v2.1, the function name will be luaopen_a_b_c. | ||
* | ||
* The fourth searcher tries an all-in-one loader. It searches the C path for | ||
* a library for the root name of the given module. For instance, when | ||
* requiring a.b.c, it will search for a C library for a. If found, it looks | ||
* into it for an open function for the submodule; in our example, that would | ||
* be luaopen_a_b_c. With this facility, a package can pack several C | ||
* submodules into one single library, with each submodule keeping its | ||
* original open function. | ||
* | ||
* All searchers except the first one (preload) return as the extra value the | ||
* file name where the module was found, as returned by package.searchpath. | ||
* The first searcher returns no extra value. | ||
*/ | ||
var searchers: ( | ||
| ((modname: string) => LuaMultiReturn<[(modname: string) => void]>) | ||
| (<T>(modname: string) => LuaMultiReturn<[(modname: string, extra: T) => T, T]>) | ||
| string | ||
)[]; | ||
} | ||
declare namespace table { | ||
/** | ||
* Returns the elements from the given list. This function is equivalent to | ||
* | ||
* `return list[i], list[i+1], ···, list[j]` | ||
* | ||
* By default, i is 1 and j is #list. | ||
* @tupleReturn | ||
*/ | ||
function unpack<T extends any[]>(list: T): T; | ||
/** @tupleReturn */ | ||
function unpack<T>(list: T[], i: number, j?: number): T[]; | ||
/** | ||
* Returns the elements from the given list. This function is equivalent to | ||
* | ||
* `return list[i], list[i+1], ···, list[j]` | ||
* | ||
* By default, i is 1 and j is #list. | ||
*/ | ||
function unpack<T extends any[]>(list: T): LuaMultiReturn<T[]>; | ||
function unpack<T>(list: T[], i: number, j?: number): LuaMultiReturn<T[]>; | ||
/** | ||
* Returns a new table with all parameters stored into keys 1, 2, etc. and | ||
* with a field "n" with the total number of parameters. Note that the | ||
* resulting table may not be a sequence. | ||
*/ | ||
function pack<T extends any[]>(...args: T): T & { n: number }; | ||
/** | ||
* Returns a new table with all parameters stored into keys 1, 2, etc. and | ||
* with a field "n" with the total number of parameters. Note that the | ||
* resulting table may not be a sequence. | ||
*/ | ||
function pack<T extends any[]>(...args: T): T & { n: number }; | ||
} | ||
declare namespace os { | ||
/** | ||
* This function is equivalent to the ISO C function system. It passes command | ||
* to be executed by an operating system shell. Its first result is true if | ||
* the command terminated successfully, or nil otherwise. After this first | ||
* result the function returns a string plus a number, as follows: | ||
* * "exit": the command terminated normally; the following number is the exit | ||
* status of the command. | ||
* * "signal": the command was terminated by a signal; the following number is | ||
* the signal that terminated the command. | ||
* | ||
* When called without a command, os.execute returns a boolean that is true if | ||
* a shell is available. | ||
*/ | ||
function execute(): boolean; | ||
/** | ||
* This function is equivalent to the ISO C function system. It passes command | ||
* to be executed by an operating system shell. Its first result is true if | ||
* the command terminated successfully, or nil otherwise. After this first | ||
* result the function returns a string plus a number, as follows: | ||
* * "exit": the command terminated normally; the following number is the exit | ||
* status of the command. | ||
* * "signal": the command was terminated by a signal; the following number is | ||
* the signal that terminated the command. | ||
* | ||
* When called without a command, os.execute returns a boolean that is true if | ||
* a shell is available. | ||
*/ | ||
function execute(): boolean; | ||
/** | ||
* This function is equivalent to the ISO C function system. It passes command | ||
* to be executed by an operating system shell. Its first result is true if | ||
* the command terminated successfully, or nil otherwise. After this first | ||
* result the function returns a string plus a number, as follows: | ||
* * "exit": the command terminated normally; the following number is the exit | ||
* status of the command. | ||
* * "signal": the command was terminated by a signal; the following number is | ||
* the signal that terminated the command. | ||
* | ||
* When called without a command, os.execute returns a boolean that is true if | ||
* a shell is available. | ||
* @tupleReturn | ||
*/ | ||
function execute(command: string): [true | undefined, 'exit' | 'signal', number]; | ||
/** | ||
* This function is equivalent to the ISO C function system. It passes command | ||
* to be executed by an operating system shell. Its first result is true if | ||
* the command terminated successfully, or nil otherwise. After this first | ||
* result the function returns a string plus a number, as follows: | ||
* * "exit": the command terminated normally; the following number is the exit | ||
* status of the command. | ||
* * "signal": the command was terminated by a signal; the following number is | ||
* the signal that terminated the command. | ||
* | ||
* When called without a command, os.execute returns a boolean that is true if | ||
* a shell is available. | ||
*/ | ||
function execute( | ||
command: string | ||
): LuaMultiReturn<[true | undefined, 'exit' | 'signal', number]>; | ||
} | ||
declare namespace debug { | ||
interface FunctionInfo<T extends Function> { | ||
istailcall: boolean; | ||
} | ||
interface FunctionInfo<T extends Function> { | ||
istailcall: boolean; | ||
} | ||
} | ||
interface LuaMetatable<T> { | ||
/** | ||
* Handle iteration through table pairs when `for k,v in pairs(tbl) do ... | ||
* end` is called. | ||
*/ | ||
__pairs?<T>(t: T): [(t: T, index?: any) => [any, any], T]; | ||
/** | ||
* Handle iteration through table pairs when `for k,v in pairs(tbl) do ... | ||
* end` is called. | ||
*/ | ||
__pairs?<T>(t: T): [(t: T, index?: any) => [any, any], T]; | ||
/** | ||
* Handle iteration through table pairs when `for k,v in ipairs(tbl) do ... | ||
* end` is called. | ||
*/ | ||
__ipairs?<T extends object>(t: T): [(t: T, index?: number) => [number, any], T, 0]; | ||
/** | ||
* Handle iteration through table pairs when `for k,v in ipairs(tbl) do ... | ||
* end` is called. | ||
*/ | ||
__ipairs?<T extends object>(t: T): [(t: T, index?: number) => [number, any], T, 0]; | ||
} | ||
declare namespace coroutine { | ||
/** | ||
* Returns the running coroutine plus a boolean, true when the running | ||
* coroutine is the main one. | ||
* @tupleReturn | ||
*/ | ||
function running(): [LuaThread, boolean]; | ||
/** | ||
* Returns the running coroutine plus a boolean, true when the running | ||
* coroutine is the main one. | ||
*/ | ||
function running(): LuaMultiReturn<[LuaThread, boolean]>; | ||
} |
@@ -1,6 +0,6 @@ | ||
import './5.2-only'; | ||
import './5.2-or-jit'; | ||
import './5.2-plus'; | ||
import './5.2-plus-or-jit'; | ||
import './5.3-pre'; | ||
import './5.4-pre'; | ||
/// <reference path="./5.2-only.d.ts" /> | ||
/// <reference path="./5.2-or-jit.d.ts" /> | ||
/// <reference path="./5.2-plus.d.ts" /> | ||
/// <reference path="./5.2-plus-or-jit.d.ts" /> | ||
/// <reference path="./5.3-pre.d.ts" /> | ||
/// <reference path="./5.4-pre.d.ts" /> |
@@ -14,99 +14,98 @@ /** @noSelfInFile */ | ||
declare namespace math { | ||
/** | ||
* 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.) | ||
* | ||
* The default value for x is 1, so that the call math.atan(y) returns the arc | ||
* tangent of y. | ||
*/ | ||
function atan(y: number, 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.) | ||
* | ||
* The default value for x is 1, so that the call math.atan(y) returns the arc | ||
* tangent of y. | ||
*/ | ||
function atan(y: number, x?: number): number; | ||
/** | ||
* An integer with the minimum value for an integer. | ||
*/ | ||
const mininteger: number; | ||
/** | ||
* An integer with the minimum value for an integer. | ||
*/ | ||
const mininteger: number; | ||
/** | ||
* An integer with the maximum value for an integer. | ||
*/ | ||
const maxinteger: number; | ||
/** | ||
* An integer with the maximum value for an integer. | ||
*/ | ||
const maxinteger: number; | ||
/** | ||
* If the value x is convertible to an integer, returns that integer. | ||
* Otherwise, returns nil. | ||
*/ | ||
function tointeger(x: number): number; | ||
/** | ||
* If the value x is convertible to an integer, returns that integer. | ||
* Otherwise, returns nil. | ||
*/ | ||
function tointeger(x: number): number; | ||
/** | ||
* Returns "integer" if x is an integer, "float" if it is a float, or nil if x | ||
* is not a number. | ||
*/ | ||
function type(x: number): 'integer' | 'float' | undefined; | ||
/** | ||
* Returns "integer" if x is an integer, "float" if it is a float, or nil if x | ||
* is not a number. | ||
*/ | ||
function type(x: number): 'integer' | 'float' | undefined; | ||
/** | ||
* Returns a boolean, true if and only if integer m is below integer n when | ||
* they are compared as unsigned integers. | ||
*/ | ||
function ult(m: number, n: number): boolean; | ||
/** | ||
* Returns a boolean, true if and only if integer m is below integer n when | ||
* they are compared as unsigned integers. | ||
*/ | ||
function ult(m: number, n: number): boolean; | ||
} | ||
declare namespace table { | ||
/** | ||
* Moves elements from table a1 to table a2, performing the equivalent to the | ||
* following multiple assignment: a2[t],··· = a1[f],···,a1[e]. The default for | ||
* a2 is a1. The destination range can overlap with the source range. The | ||
* number of elements to be moved must fit in a Lua integer. | ||
* | ||
* Returns the destination table a2. | ||
*/ | ||
function move<T1, T2 = T1>(a1: T1[], f: number, e: number, t: number, a2?: T2[]): (T2 | T1)[]; | ||
/** | ||
* Moves elements from table a1 to table a2, performing the equivalent to the | ||
* following multiple assignment: a2[t],··· = a1[f],···,a1[e]. The default for | ||
* a2 is a1. The destination range can overlap with the source range. The | ||
* number of elements to be moved must fit in a Lua integer. | ||
* | ||
* Returns the destination table a2. | ||
*/ | ||
function move<T1, T2 = T1>(a1: T1[], f: number, e: number, t: number, a2?: T2[]): (T2 | T1)[]; | ||
} | ||
declare namespace string { | ||
/** | ||
* Returns a string containing a binary representation (a binary chunk) of the | ||
* given function, so that a later load on this string returns a copy of the | ||
* function (but with new upvalues). If strip is a true value, the binary | ||
* representation may not include all debug information about the function, to | ||
* save space. | ||
* | ||
* Functions with upvalues have only their number of upvalues saved. When | ||
* (re)loaded, those upvalues receive fresh instances containing nil. (You can | ||
* use the debug library to serialize and reload the upvalues of a function in | ||
* a way adequate to your needs.) | ||
*/ | ||
function dump(func: Function, strip?: boolean): string; | ||
/** | ||
* Returns a string containing a binary representation (a binary chunk) of the | ||
* given function, so that a later load on this string returns a copy of the | ||
* function (but with new upvalues). If strip is a true value, the binary | ||
* representation may not include all debug information about the function, to | ||
* save space. | ||
* | ||
* Functions with upvalues have only their number of upvalues saved. When | ||
* (re)loaded, those upvalues receive fresh instances containing nil. (You can | ||
* use the debug library to serialize and reload the upvalues of a function in | ||
* a way adequate to your needs.) | ||
*/ | ||
function dump(func: Function, strip?: boolean): string; | ||
/** | ||
* Returns a binary string containing the values v1, v2, etc. packed (that is, | ||
* serialized in binary form) according to the format string fmt (see §6.4.2). | ||
*/ | ||
function pack(fmt: string, ...values: any[]): string; | ||
/** | ||
* Returns a binary string containing the values v1, v2, etc. packed (that is, | ||
* serialized in binary form) according to the format string fmt (see §6.4.2). | ||
*/ | ||
function pack(fmt: string, ...values: any[]): string; | ||
/** | ||
* Returns the values packed in string s (see string.pack) according to the | ||
* format string fmt (see §6.4.2). An optional pos marks where to start | ||
* reading in s (default is 1). After the read values, this function also | ||
* returns the index of the first unread byte in s. | ||
* @tupleReturn | ||
*/ | ||
function unpack(fmt: string, s: string, pos?: number): any[]; | ||
/** | ||
* Returns the values packed in string s (see string.pack) according to the | ||
* format string fmt (see §6.4.2). An optional pos marks where to start | ||
* reading in s (default is 1). After the read values, this function also | ||
* returns the index of the first unread byte in s. | ||
*/ | ||
function unpack(fmt: string, s: string, pos?: number): LuaMultiReturn<any[]>; | ||
/** | ||
* Returns the size of a string resulting from string.pack with the given | ||
* format. The format string cannot have the variable-length options 's' or | ||
* 'z' (see §6.4.2). | ||
*/ | ||
function packsize(fmt: string): number; | ||
/** | ||
* Returns the size of a string resulting from string.pack with the given | ||
* format. The format string cannot have the variable-length options 's' or | ||
* 'z' (see §6.4.2). | ||
*/ | ||
function packsize(fmt: string): number; | ||
} | ||
declare namespace coroutine { | ||
/** | ||
* Returns true when the running coroutine can yield. | ||
* | ||
* A running coroutine is yieldable if it is not the main thread and it is not | ||
* inside a non-yieldable C function. | ||
*/ | ||
function isyieldable(): boolean; | ||
/** | ||
* Returns true when the running coroutine can yield. | ||
* | ||
* A running coroutine is yieldable if it is not the main thread and it is not | ||
* inside a non-yieldable C function. | ||
*/ | ||
function isyieldable(): boolean; | ||
} | ||
@@ -129,106 +128,105 @@ | ||
declare namespace utf8 { | ||
/** | ||
* Receives zero or more integers, converts each one to its corresponding | ||
* UTF-8 byte sequence and returns a string with the concatenation of all | ||
* these sequences | ||
*/ | ||
function char(...args: number[]): string; | ||
/** | ||
* Receives zero or more integers, converts each one to its corresponding | ||
* UTF-8 byte sequence and returns a string with the concatenation of all | ||
* these sequences | ||
*/ | ||
function char(...args: number[]): string; | ||
/** | ||
* The pattern (a string, not a function) "[\0-\x7F\xC2-\xF4][\x80-\xBF]*" | ||
* (see §6.4.1), which matches exactly one UTF-8 byte sequence, assuming that | ||
* the subject is a valid UTF-8 string. | ||
*/ | ||
var charpattern: string; | ||
/** | ||
* The pattern (a string, not a function) "[\0-\x7F\xC2-\xF4][\x80-\xBF]*" | ||
* (see §6.4.1), which matches exactly one UTF-8 byte sequence, assuming that | ||
* the subject is a valid UTF-8 string. | ||
*/ | ||
var charpattern: string; | ||
/** | ||
* Returns values so that the construction | ||
* | ||
* `for p, c in utf8.codes(s) do body end` | ||
* | ||
* will iterate over all characters in string s, with p being the position (in | ||
* bytes) and c the code point of each character. It raises an error if it | ||
* meets any invalid byte sequence. | ||
*/ | ||
function codes<S extends string>( | ||
s: S, | ||
): [/** @tupleReturn */ (s: S, index?: number) => [number, number], S, 0]; | ||
/** | ||
* Returns values so that the construction | ||
* | ||
* `for p, c in utf8.codes(s) do body end` | ||
* | ||
* will iterate over all characters in string s, with p being the position (in | ||
* bytes) and c the code point of each character. It raises an error if it | ||
* meets any invalid byte sequence. | ||
*/ | ||
function codes<S extends string>( | ||
s: S | ||
): [(s: S, index?: number) => LuaMultiReturn<[number, number]>, S, 0]; | ||
/** | ||
* Returns the codepoints (as integers) from all characters in s that start | ||
* between byte position i and j (both included). The default for i is 1 and | ||
* for j is i. It raises an error if it meets any invalid byte sequence. | ||
* @tupleReturn | ||
*/ | ||
function codepoint(s: string, i?: number, j?: number): number[]; | ||
/** | ||
* Returns the codepoints (as integers) from all characters in s that start | ||
* between byte position i and j (both included). The default for i is 1 and | ||
* for j is i. It raises an error if it meets any invalid byte sequence. | ||
*/ | ||
function codepoint(s: string, i?: number, j?: number): LuaMultiReturn<number[]>; | ||
/** | ||
* Returns the number of UTF-8 characters in string s that start between | ||
* positions i and j (both inclusive). The default for i is 1 and for j is -1. | ||
* If it finds any invalid byte sequence, returns a false value plus the | ||
* position of the first invalid byte. | ||
*/ | ||
function len(s: string, i?: number, j?: number): number; | ||
/** | ||
* Returns the number of UTF-8 characters in string s that start between | ||
* positions i and j (both inclusive). The default for i is 1 and for j is -1. | ||
* If it finds any invalid byte sequence, returns a false value plus the | ||
* position of the first invalid byte. | ||
*/ | ||
function len(s: string, i?: number, j?: number): number; | ||
/** | ||
* Returns the position (in bytes) where the encoding of the n-th character of | ||
* s (counting from position i) starts. A negative n gets characters before | ||
* position i. The default for i is 1 when n is non-negative and #s + 1 | ||
* otherwise, so that utf8.offset(s, -n) gets the offset of the n-th character | ||
* from the end of the string. If the specified character is neither in the | ||
* subject nor right after its end, the function returns nil. | ||
* | ||
* As a special case, when n is 0 the function returns the start of the | ||
* encoding of the character that contains the i-th byte of s. | ||
* | ||
* This function assumes that s is a valid UTF-8 string. | ||
*/ | ||
function offset(s: string, n?: number, i?: number): number; | ||
/** | ||
* Returns the position (in bytes) where the encoding of the n-th character of | ||
* s (counting from position i) starts. A negative n gets characters before | ||
* position i. The default for i is 1 when n is non-negative and #s + 1 | ||
* otherwise, so that utf8.offset(s, -n) gets the offset of the n-th character | ||
* from the end of the string. If the specified character is neither in the | ||
* subject nor right after its end, the function returns nil. | ||
* | ||
* As a special case, when n is 0 the function returns the start of the | ||
* encoding of the character that contains the i-th byte of s. | ||
* | ||
* This function assumes that s is a valid UTF-8 string. | ||
*/ | ||
function offset(s: string, n?: number, i?: number): number; | ||
} | ||
interface LuaMetatable<T> { | ||
/** | ||
* the floor division (//) operation. Behavior similar to the addition | ||
* operation. | ||
*/ | ||
__idiv?(this: T, operand: any): any; | ||
/** | ||
* the floor division (//) operation. Behavior similar to the addition | ||
* operation. | ||
*/ | ||
__idiv?(this: T, operand: any): any; | ||
/** | ||
* the bitwise AND (&) operation. Behavior similar to the addition operation, | ||
* except that Lua will try a metamethod if any operand is neither an integer | ||
* nor a value coercible to an integer (see §3.4.3). | ||
*/ | ||
__band?(this: T, operand: any): any; | ||
/** | ||
* the bitwise AND (&) operation. Behavior similar to the addition operation, | ||
* except that Lua will try a metamethod if any operand is neither an integer | ||
* nor a value coercible to an integer (see §3.4.3). | ||
*/ | ||
__band?(this: T, operand: any): any; | ||
/** | ||
* the bitwise OR (|) operation. Behavior similar to the bitwise AND | ||
* operation. | ||
*/ | ||
__bor?(this: T, operand: any): any; | ||
/** | ||
* the bitwise OR (|) operation. Behavior similar to the bitwise AND | ||
* operation. | ||
*/ | ||
__bor?(this: T, operand: any): any; | ||
/** | ||
* the bitwise exclusive OR (binary ~) operation. Behavior similar to the | ||
* bitwise AND operation. | ||
*/ | ||
__bxor?(this: T, operand: any): any; | ||
/** | ||
* the bitwise exclusive OR (binary ~) operation. Behavior similar to the | ||
* bitwise AND operation. | ||
*/ | ||
__bxor?(this: T, operand: any): any; | ||
/** | ||
* the bitwise NOT (unary ~) operation. Behavior similar to the bitwise AND | ||
* operation. | ||
*/ | ||
__bnot?(this: T, operand: any): any; | ||
/** | ||
* the bitwise NOT (unary ~) operation. Behavior similar to the bitwise AND | ||
* operation. | ||
*/ | ||
__bnot?(this: T, operand: any): any; | ||
/** | ||
* the bitwise left shift (<<) operation. Behavior similar to the bitwise AND | ||
* operation. | ||
*/ | ||
__shl?(this: T, operand: any): any; | ||
/** | ||
* the bitwise left shift (<<) operation. Behavior similar to the bitwise AND | ||
* operation. | ||
*/ | ||
__shl?(this: T, operand: any): any; | ||
/** | ||
* the bitwise right shift (>>) operation. Behavior similar to the bitwise AND | ||
* operation. | ||
*/ | ||
__shr?(this: T, operand: any): any; | ||
/** | ||
* the bitwise right shift (>>) operation. Behavior similar to the bitwise AND | ||
* operation. | ||
*/ | ||
__shr?(this: T, operand: any): any; | ||
} | ||
type FileReadFormat = 'n' | 'a' | 'l' | 'L' | number; |
/** @noSelfInFile */ | ||
declare namespace math { | ||
/** | ||
* Returns the arc tangent of x (in radians). | ||
*/ | ||
function atan(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 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 hyperbolic cosine of x. | ||
*/ | ||
function cosh(x: number): number; | ||
/** | ||
* Returns the hyperbolic cosine of x. | ||
*/ | ||
function cosh(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 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 m2e (e should be an integer). | ||
*/ | ||
function ldexp(m: number, e: number): number; | ||
/** | ||
* Returns xy. (You can also use the expression x^y to compute this value.) | ||
*/ | ||
function pow(x: number, y: number): number; | ||
/** | ||
* Returns xy. (You can also use the expression x^y to compute this value.) | ||
*/ | ||
function pow(x: number, y: number): number; | ||
/** | ||
* Returns the hyperbolic sine of x. | ||
*/ | ||
function sinh(x: number): number; | ||
/** | ||
* Returns the hyperbolic sine of x. | ||
*/ | ||
function sinh(x: number): number; | ||
/** | ||
* Returns the hyperbolic tangent of x. | ||
*/ | ||
function tanh(x: number): number; | ||
/** | ||
* Returns the hyperbolic tangent of x. | ||
*/ | ||
function tanh(x: number): number; | ||
} |
@@ -1,4 +0,4 @@ | ||
import './5.2-plus'; | ||
import './5.2-plus-or-jit'; | ||
import './5.3-plus'; | ||
import './5.4-pre'; | ||
/// <reference path="./5.2-plus.d.ts" /> | ||
/// <reference path="./5.2-plus-or-jit.d.ts" /> | ||
/// <reference path="./5.3-plus.d.ts" /> | ||
/// <reference path="./5.4-pre.d.ts" /> |
/** @noSelfInFile */ | ||
declare namespace math { | ||
/** | ||
* 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 call math.random(n), for a positive n, is equivalent | ||
* to math.random(1,n). The call math.random(0) produces an integer with all | ||
* bits (pseudo)random. | ||
* | ||
* Lua initializes its pseudo-random generator with a weak attempt for | ||
* "randomness", so that math.random should generate different sequences of | ||
* results each time the program runs. To ensure a required level of | ||
* randomness to the initial state (or contrarily, to have a deterministic | ||
* sequence, for instance when debugging a program), you should call | ||
* math.randomseed explicitly. | ||
* | ||
* The results from this function have good statistical qualities, but they | ||
* are not cryptographically secure. (For instance, there are no garanties | ||
* that it is hard to predict future results based on the observation of some | ||
* number of previous results.) | ||
*/ | ||
function random(m?: number, n?: 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 call math.random(n), for a positive n, is equivalent | ||
* to math.random(1,n). The call math.random(0) produces an integer with all | ||
* bits (pseudo)random. | ||
* | ||
* Lua initializes its pseudo-random generator with a weak attempt for | ||
* "randomness", so that math.random should generate different sequences of | ||
* results each time the program runs. To ensure a required level of | ||
* randomness to the initial state (or contrarily, to have a deterministic | ||
* sequence, for instance when debugging a program), you should call | ||
* math.randomseed explicitly. | ||
* | ||
* The results from this function have good statistical qualities, but they | ||
* are not cryptographically secure. (For instance, there are no garanties | ||
* that it is hard to predict future results based on the observation of some | ||
* number of previous results.) | ||
*/ | ||
function random(m?: number, n?: number): number; | ||
/** | ||
* Sets x and y as the "seed" for the pseudo-random generator: equal seeds | ||
* produce equal sequences of numbers. The default for y is zero. | ||
*/ | ||
function randomseed(x: number, y?: number): number; | ||
/** | ||
* Sets x and y as the "seed" for the pseudo-random generator: equal seeds | ||
* produce equal sequences of numbers. The default for y is zero. | ||
*/ | ||
function randomseed(x: number, y?: number): number; | ||
} |
/** @noSelfInFile */ | ||
declare namespace math { | ||
/** | ||
* 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; | ||
/** | ||
* 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; | ||
/** | ||
* Sets x as the "seed" for the pseudo-random generator: equal seeds produce | ||
* equal sequences of numbers. | ||
*/ | ||
function randomseed(x: number): number; | ||
} |
@@ -1,4 +0,4 @@ | ||
import './5.2-plus'; | ||
import './5.2-plus-or-jit'; | ||
import './5.3-plus'; | ||
import './5.4-only'; | ||
/// <reference path="./5.2-plus.d.ts" /> | ||
/// <reference path="./5.2-plus-or-jit.d.ts" /> | ||
/// <reference path="./5.3-plus.d.ts" /> | ||
/// <reference path="./5.4-only.d.ts" /> |
@@ -33,302 +33,300 @@ /** @noSelfInFile */ | ||
* binary chunks can crash the interpreter. | ||
* @tupleReturn | ||
*/ | ||
declare function loadstring( | ||
chunk: string | (() => string | null | undefined), | ||
chunkname?: string, | ||
mode?: 'b' | 't' | 'bt', | ||
env?: object, | ||
): [() => any] | [undefined, string]; | ||
chunk: string | (() => string | null | undefined), | ||
chunkname?: string, | ||
mode?: 'b' | 't' | 'bt', | ||
env?: object | ||
): LuaMultiReturn<[() => any] | [undefined, string]>; | ||
declare namespace bit { | ||
/** | ||
* Normalizes a number to the numeric range for bit operations and returns it. | ||
* This function is usually not needed since all bit operations already | ||
* normalize all of their input arguments. Check the operational semantics for | ||
* details. | ||
*/ | ||
function tobit(x: number): number; | ||
/** | ||
* Normalizes a number to the numeric range for bit operations and returns it. | ||
* This function is usually not needed since all bit operations already | ||
* normalize all of their input arguments. Check the operational semantics for | ||
* details. | ||
*/ | ||
function tobit(x: number): number; | ||
/** | ||
* Converts its first argument to a hex string. The number of hex digits is | ||
* given by the absolute value of the optional second argument. Positive | ||
* numbers between 1 and 8 generate lowercase hex digits. Negative numbers | ||
* generate uppercase hex digits. Only the least-significant 4*|n| bits are | ||
* used. The default is to generate 8 lowercase hex digits. | ||
*/ | ||
function tohex(x: number, n?: number): string; | ||
/** | ||
* Converts its first argument to a hex string. The number of hex digits is | ||
* given by the absolute value of the optional second argument. Positive | ||
* numbers between 1 and 8 generate lowercase hex digits. Negative numbers | ||
* generate uppercase hex digits. Only the least-significant 4*|n| bits are | ||
* used. The default is to generate 8 lowercase hex digits. | ||
*/ | ||
function tohex(x: number, n?: number): string; | ||
/** | ||
* Returns the bitwise not of its argument. | ||
*/ | ||
function bnot(x: number): number; | ||
/** | ||
* Returns the bitwise not of its argument. | ||
*/ | ||
function bnot(x: number): number; | ||
/** | ||
* Returns the bitwise or of all of its arguments. | ||
*/ | ||
function bor(x: number, ...rest: number[]): number; | ||
/** | ||
* Returns the bitwise and of all of its arguments. | ||
*/ | ||
function band(x: number, ...rest: number[]): number; | ||
/** | ||
* Returns the bitwise xor of all of its arguments. | ||
*/ | ||
function bxor(x: number, ...rest: number[]): number; | ||
/** | ||
* Returns the bitwise or of all of its arguments. | ||
*/ | ||
function bor(x: number, ...rest: number[]): number; | ||
/** | ||
* Returns the bitwise and of all of its arguments. | ||
*/ | ||
function band(x: number, ...rest: number[]): number; | ||
/** | ||
* Returns the bitwise xor of all of its arguments. | ||
*/ | ||
function bxor(x: number, ...rest: number[]): number; | ||
/** | ||
* Returns the (bitwise logical left-shift, bitwise logical right-shift, | ||
* bitwise arithmetic right-shift) of its first argument by the number of bits | ||
* given by the second argument. | ||
* | ||
* Logical shifts treat the first argument as an unsigned number and shift in | ||
* 0-bits. Arithmetic right-shift treats the most-significant bit as a sign | ||
* bit and replicates it. | ||
* | ||
* Only the lower 5 bits of the shift count are used (reduces to the range | ||
* [0..31]). | ||
*/ | ||
function lshift(x: number, n: number): number; | ||
/** | ||
* Returns the (bitwise logical left-shift, bitwise logical right-shift, | ||
* bitwise arithmetic right-shift) of its first argument by the number of bits | ||
* given by the second argument. | ||
* | ||
* Logical shifts treat the first argument as an unsigned number and shift in | ||
* 0-bits. Arithmetic right-shift treats the most-significant bit as a sign | ||
* bit and replicates it. | ||
* | ||
* Only the lower 5 bits of the shift count are used (reduces to the range | ||
* [0..31]). | ||
*/ | ||
function rshift(x: number, n: number): number; | ||
/** | ||
* Returns the (bitwise logical left-shift, bitwise logical right-shift, | ||
* bitwise arithmetic right-shift) of its first argument by the number of bits | ||
* given by the second argument. | ||
* | ||
* Logical shifts treat the first argument as an unsigned number and shift in | ||
* 0-bits. Arithmetic right-shift treats the most-significant bit as a sign | ||
* bit and replicates it. | ||
* | ||
* Only the lower 5 bits of the shift count are used (reduces to the range | ||
* [0..31]). | ||
*/ | ||
function arshift(x: number, n: number): number; | ||
/** | ||
* Returns the (bitwise logical left-shift, bitwise logical right-shift, | ||
* bitwise arithmetic right-shift) of its first argument by the number of bits | ||
* given by the second argument. | ||
* | ||
* Logical shifts treat the first argument as an unsigned number and shift in | ||
* 0-bits. Arithmetic right-shift treats the most-significant bit as a sign | ||
* bit and replicates it. | ||
* | ||
* Only the lower 5 bits of the shift count are used (reduces to the range | ||
* [0..31]). | ||
*/ | ||
function lshift(x: number, n: number): number; | ||
/** | ||
* Returns the (bitwise logical left-shift, bitwise logical right-shift, | ||
* bitwise arithmetic right-shift) of its first argument by the number of bits | ||
* given by the second argument. | ||
* | ||
* Logical shifts treat the first argument as an unsigned number and shift in | ||
* 0-bits. Arithmetic right-shift treats the most-significant bit as a sign | ||
* bit and replicates it. | ||
* | ||
* Only the lower 5 bits of the shift count are used (reduces to the range | ||
* [0..31]). | ||
*/ | ||
function rshift(x: number, n: number): number; | ||
/** | ||
* Returns the (bitwise logical left-shift, bitwise logical right-shift, | ||
* bitwise arithmetic right-shift) of its first argument by the number of bits | ||
* given by the second argument. | ||
* | ||
* Logical shifts treat the first argument as an unsigned number and shift in | ||
* 0-bits. Arithmetic right-shift treats the most-significant bit as a sign | ||
* bit and replicates it. | ||
* | ||
* Only the lower 5 bits of the shift count are used (reduces to the range | ||
* [0..31]). | ||
*/ | ||
function arshift(x: number, n: number): number; | ||
/** | ||
* Returns bitwise left rotation of its first argument by the number of bits | ||
* given by the second argument. Bits shifted out on one side are shifted back | ||
* in on the other side. | ||
* | ||
* Only the lower 5 bits of the rotate count are used (reduces to the range | ||
* [0..31]). | ||
*/ | ||
function rol(x: number, n: number): number; | ||
/** | ||
* Returns bitwise left rotation of its first argument by the number of bits | ||
* given by the second argument. Bits shifted out on one side are shifted back | ||
* in on the other side. | ||
* | ||
* Only the lower 5 bits of the rotate count are used (reduces to the range | ||
* [0..31]). | ||
*/ | ||
function rol(x: number, n: number): number; | ||
/** | ||
* Returns bitwise right rotation of its first argument by the number of bits | ||
* given by the second argument. Bits shifted out on one side are shifted back | ||
* in on the other side. | ||
* | ||
* Only the lower 5 bits of the rotate count are used (reduces to the range | ||
* [0..31]). | ||
*/ | ||
function ror(x: number, n: number): number; | ||
/** | ||
* Returns bitwise right rotation of its first argument by the number of bits | ||
* given by the second argument. Bits shifted out on one side are shifted back | ||
* in on the other side. | ||
* | ||
* Only the lower 5 bits of the rotate count are used (reduces to the range | ||
* [0..31]). | ||
*/ | ||
function ror(x: number, n: number): number; | ||
/** | ||
* Swaps the bytes of its argument and returns it. This can be used to convert | ||
* little-endian 32 bit numbers to big-endian 32 bit numbers or vice versa | ||
*/ | ||
function bswap(x: number): number; | ||
/** | ||
* Swaps the bytes of its argument and returns it. This can be used to convert | ||
* little-endian 32 bit numbers to big-endian 32 bit numbers or vice versa | ||
*/ | ||
function bswap(x: number): number; | ||
} | ||
declare namespace ffi { | ||
/** | ||
* Adds multiple C declarations for types or external symbols (named variables | ||
* or functions). def must be a Lua string. It's recommended to use the | ||
* syntactic sugar for string arguments as follows: | ||
* | ||
* The contents of the string must be a sequence of C declarations, separated | ||
* by semicolons. The trailing semicolon for a single declaration may be | ||
* omitted. | ||
* | ||
* Please note that external symbols are only declared, but they are not bound | ||
* to any specific address, yet. Binding is achieved with C library namespaces | ||
* (see below). | ||
* | ||
* C declarations are not passed through a C pre-processor, yet. No | ||
* pre-processor tokens are allowed, except for #pragma pack. Replace #define | ||
* in existing C header files with enum, static const or typedef and/or pass | ||
* the files through an external C pre-processor (once). Be careful not to | ||
* include unneeded or redundant declarations from unrelated header files. | ||
*/ | ||
function cdef(defs: string): void; | ||
/** | ||
* Adds multiple C declarations for types or external symbols (named variables | ||
* or functions). def must be a Lua string. It's recommended to use the | ||
* syntactic sugar for string arguments as follows: | ||
* | ||
* The contents of the string must be a sequence of C declarations, separated | ||
* by semicolons. The trailing semicolon for a single declaration may be | ||
* omitted. | ||
* | ||
* Please note that external symbols are only declared, but they are not bound | ||
* to any specific address, yet. Binding is achieved with C library namespaces | ||
* (see below). | ||
* | ||
* C declarations are not passed through a C pre-processor, yet. No | ||
* pre-processor tokens are allowed, except for #pragma pack. Replace #define | ||
* in existing C header files with enum, static const or typedef and/or pass | ||
* the files through an external C pre-processor (once). Be careful not to | ||
* include unneeded or redundant declarations from unrelated header files. | ||
*/ | ||
function cdef(defs: string): void; | ||
/** | ||
* This is the default C library namespace — note the uppercase 'C'. It binds | ||
* to the default set of symbols or libraries on the target system. These are | ||
* more or less the same as a C compiler would offer by default, without | ||
* specifying extra link libraries. | ||
* | ||
* On POSIX systems, this binds to symbols in the default or global namespace. | ||
* This includes all exported symbols from the executable and any libraries | ||
* loaded into the global namespace. This includes at least libc, libm, libdl | ||
* (on Linux), libgcc (if compiled with GCC), as well as any exported symbols | ||
* from the Lua/C API provided by LuaJIT itself. | ||
* | ||
* On Windows systems, this binds to symbols exported from the *.exe, the | ||
* lua51.dll (i.e. the Lua/C API provided by LuaJIT itself), the C runtime | ||
* library LuaJIT was linked with (msvcrt*.dll), kernel32.dll, user32.dll and | ||
* gdi32.dll. | ||
*/ | ||
const C: Record<string, any>; | ||
/** | ||
* This is the default C library namespace — note the uppercase 'C'. It binds | ||
* to the default set of symbols or libraries on the target system. These are | ||
* more or less the same as a C compiler would offer by default, without | ||
* specifying extra link libraries. | ||
* | ||
* On POSIX systems, this binds to symbols in the default or global namespace. | ||
* This includes all exported symbols from the executable and any libraries | ||
* loaded into the global namespace. This includes at least libc, libm, libdl | ||
* (on Linux), libgcc (if compiled with GCC), as well as any exported symbols | ||
* from the Lua/C API provided by LuaJIT itself. | ||
* | ||
* On Windows systems, this binds to symbols exported from the *.exe, the | ||
* lua51.dll (i.e. the Lua/C API provided by LuaJIT itself), the C runtime | ||
* library LuaJIT was linked with (msvcrt*.dll), kernel32.dll, user32.dll and | ||
* gdi32.dll. | ||
*/ | ||
const C: Record<string, any>; | ||
/** | ||
* This loads the dynamic library given by name and returns a new C library | ||
* namespace which binds to its symbols. On POSIX systems, if global is true, | ||
* the library symbols are loaded into the global namespace, too. | ||
* | ||
* If name is a path, the library is loaded from this path. Otherwise name is | ||
* canonicalized in a system-dependent way and searched in the default search | ||
* path for dynamic libraries: | ||
* | ||
* On POSIX systems, if the name contains no dot, the extension .so is | ||
* appended. Also, the lib prefix is prepended if necessary. So ffi.load("z") | ||
* looks for "libz.so" in the default shared library search path. | ||
* | ||
* On Windows systems, if the name contains no dot, the extension .dll is | ||
* appended. So ffi.load("ws2_32") looks for "ws2_32.dll" in the default DLL | ||
* search path. | ||
*/ | ||
function load(name: string, global?: boolean): any; | ||
/** | ||
* This loads the dynamic library given by name and returns a new C library | ||
* namespace which binds to its symbols. On POSIX systems, if global is true, | ||
* the library symbols are loaded into the global namespace, too. | ||
* | ||
* If name is a path, the library is loaded from this path. Otherwise name is | ||
* canonicalized in a system-dependent way and searched in the default search | ||
* path for dynamic libraries: | ||
* | ||
* On POSIX systems, if the name contains no dot, the extension .so is | ||
* appended. Also, the lib prefix is prepended if necessary. So ffi.load("z") | ||
* looks for "libz.so" in the default shared library search path. | ||
* | ||
* On Windows systems, if the name contains no dot, the extension .dll is | ||
* appended. So ffi.load("ws2_32") looks for "ws2_32.dll" in the default DLL | ||
* search path. | ||
*/ | ||
function load(name: string, global?: boolean): any; | ||
// TODO: http://luajit.org/ext_ffi_api.html | ||
// TODO: http://luajit.org/ext_ffi_api.html | ||
} | ||
declare namespace jit { | ||
/** | ||
* Turns the whole JIT compiler on (default). | ||
* | ||
* This function is typically used with the command line option -j on. | ||
*/ | ||
function on(): void; | ||
/** | ||
* Turns the whole JIT compiler on (default). | ||
* | ||
* This function is typically used with the command line option -j on. | ||
*/ | ||
function on(): void; | ||
/** | ||
* Turns the whole JIT compiler off. | ||
* | ||
* This function is typically used with the command line option -j off. | ||
*/ | ||
function off(): void; | ||
/** | ||
* Turns the whole JIT compiler off. | ||
* | ||
* This function is typically used with the command line option -j off. | ||
*/ | ||
function off(): void; | ||
/** | ||
* Flushes the whole cache of compiled code. | ||
*/ | ||
function flush(): void; | ||
/** | ||
* Flushes the whole cache of compiled code. | ||
*/ | ||
function flush(): void; | ||
/** | ||
* Enables JIT compilation for a Lua function (this is the default). | ||
* | ||
* The current function, i.e. the Lua function calling this library function, | ||
* can also be specified by passing true as the first argument. | ||
* | ||
* If the second argument is true, JIT compilation is also enabled, disabled | ||
* or flushed recursively for all sub-functions of a function. With false only | ||
* the sub-functions are affected. | ||
* | ||
* This function only sets a flag which is checked when the function is about | ||
* to be compiled. It does not trigger immediate compilation. | ||
*/ | ||
function on(func: Function | true, recursive?: boolean): void; | ||
/** | ||
* Enables JIT compilation for a Lua function (this is the default). | ||
* | ||
* The current function, i.e. the Lua function calling this library function, | ||
* can also be specified by passing true as the first argument. | ||
* | ||
* If the second argument is true, JIT compilation is also enabled, disabled | ||
* or flushed recursively for all sub-functions of a function. With false only | ||
* the sub-functions are affected. | ||
* | ||
* This function only sets a flag which is checked when the function is about | ||
* to be compiled. It does not trigger immediate compilation. | ||
*/ | ||
function on(func: Function | true, recursive?: boolean): void; | ||
/** | ||
* Disables JIT compilation for a Lua function and flushes any already | ||
* compiled code from the code cache. | ||
* | ||
* The current function, i.e. the Lua function calling this library function, | ||
* can also be specified by passing true as the first argument. | ||
* | ||
* If the second argument is true, JIT compilation is also enabled, disabled | ||
* or flushed recursively for all sub-functions of a function. With false only | ||
* the sub-functions are affected. | ||
* | ||
* This function only sets a flag which is checked when the function is about | ||
* to be compiled. It does not trigger immediate compilation. | ||
*/ | ||
function off(func: Function | true, recursive?: boolean): void; | ||
/** | ||
* Disables JIT compilation for a Lua function and flushes any already | ||
* compiled code from the code cache. | ||
* | ||
* The current function, i.e. the Lua function calling this library function, | ||
* can also be specified by passing true as the first argument. | ||
* | ||
* If the second argument is true, JIT compilation is also enabled, disabled | ||
* or flushed recursively for all sub-functions of a function. With false only | ||
* the sub-functions are affected. | ||
* | ||
* This function only sets a flag which is checked when the function is about | ||
* to be compiled. It does not trigger immediate compilation. | ||
*/ | ||
function off(func: Function | true, recursive?: boolean): void; | ||
/** | ||
* Flushes the code, but doesn't affect the enable/disable status. | ||
* | ||
* The current function, i.e. the Lua function calling this library function, | ||
* can also be specified by passing true as the first argument. | ||
* | ||
* If the second argument is true, JIT compilation is also enabled, disabled | ||
* or flushed recursively for all sub-functions of a function. With false only | ||
* the sub-functions are affected. | ||
*/ | ||
function flush(func: Function | true, recursive?: boolean): void; | ||
/** | ||
* Flushes the code, but doesn't affect the enable/disable status. | ||
* | ||
* The current function, i.e. the Lua function calling this library function, | ||
* can also be specified by passing true as the first argument. | ||
* | ||
* If the second argument is true, JIT compilation is also enabled, disabled | ||
* or flushed recursively for all sub-functions of a function. With false only | ||
* the sub-functions are affected. | ||
*/ | ||
function flush(func: Function | true, recursive?: boolean): void; | ||
/** | ||
* Flushes the root trace, specified by its number, and all of its side traces | ||
* from the cache. The code for the trace will be retained as long as there | ||
* are any other traces which link to it. | ||
*/ | ||
function flush(tr: number): void; | ||
/** | ||
* Flushes the root trace, specified by its number, and all of its side traces | ||
* from the cache. The code for the trace will be retained as long as there | ||
* are any other traces which link to it. | ||
*/ | ||
function flush(tr: number): void; | ||
/** | ||
* Returns the current status of the JIT compiler. The first result is either | ||
* true or false if the JIT compiler is turned on or off. The remaining | ||
* results are strings for CPU-specific features and enabled optimizations. | ||
* @tupleReturn | ||
*/ | ||
function status(): [boolean, ...string[]]; | ||
/** | ||
* Returns the current status of the JIT compiler. The first result is either | ||
* true or false if the JIT compiler is turned on or off. The remaining | ||
* results are strings for CPU-specific features and enabled optimizations. | ||
*/ | ||
function status(): LuaMultiReturn<[boolean, ...string[]]>; | ||
/** | ||
* Contains the LuaJIT version string. | ||
*/ | ||
const version: string; | ||
/** | ||
* Contains the LuaJIT version string. | ||
*/ | ||
const version: string; | ||
/** | ||
* Contains the version number of the LuaJIT core. Version xx.yy.zz is | ||
* represented by the decimal number xxyyzz. | ||
*/ | ||
const version_num: number; | ||
/** | ||
* Contains the version number of the LuaJIT core. Version xx.yy.zz is | ||
* represented by the decimal number xxyyzz. | ||
*/ | ||
const version_num: number; | ||
/** | ||
* Contains the target OS name. | ||
*/ | ||
const os: 'Windows' | 'Linux' | 'OSX' | 'BSD' | 'POSIX' | 'Other'; | ||
/** | ||
* Contains the target OS name. | ||
*/ | ||
const os: 'Windows' | 'Linux' | 'OSX' | 'BSD' | 'POSIX' | 'Other'; | ||
/** | ||
* Contains the target architecture name. | ||
*/ | ||
const arch: 'x86' | 'x64' | 'arm' | 'ppc' | 'ppcspe' | 'mips'; | ||
/** | ||
* Contains the target architecture name. | ||
*/ | ||
const arch: 'x86' | 'x64' | 'arm' | 'ppc' | 'ppcspe' | 'mips'; | ||
/** | ||
* This sub-module provides the backend for the -O command line option. | ||
* | ||
* You can also use it programmatically, e.g.: | ||
* | ||
* ``` | ||
* jit.opt.start(2) -- same as -O2 | ||
* jit.opt.start("-dce") | ||
* jit.opt.start("hotloop=10", "hotexit=2") | ||
* ``` | ||
* | ||
* Unlike in LuaJIT 1.x, the module is built-in and optimization is turned on | ||
* by default! It's no longer necessary to run require("jit.opt").start(), | ||
* which was one of the ways to enable optimization. | ||
*/ | ||
const opt: any; | ||
/** | ||
* This sub-module provides the backend for the -O command line option. | ||
* | ||
* You can also use it programmatically, e.g.: | ||
* | ||
* ``` | ||
* jit.opt.start(2) -- same as -O2 | ||
* jit.opt.start("-dce") | ||
* jit.opt.start("hotloop=10", "hotexit=2") | ||
* ``` | ||
* | ||
* Unlike in LuaJIT 1.x, the module is built-in and optimization is turned on | ||
* by default! It's no longer necessary to run require("jit.opt").start(), | ||
* which was one of the ways to enable optimization. | ||
*/ | ||
const opt: any; | ||
/** | ||
* This sub-module holds functions to introspect the bytecode, generated | ||
* traces, the IR and the generated machine code. The functionality provided | ||
* by this module is still in flux and therefore undocumented. | ||
* | ||
* The debug modules -jbc, -jv and -jdump make extensive use of these | ||
* functions. Please check out their source code, if you want to know more. | ||
*/ | ||
const util: any; | ||
/** | ||
* This sub-module holds functions to introspect the bytecode, generated | ||
* traces, the IR and the generated machine code. The functionality provided | ||
* by this module is still in flux and therefore undocumented. | ||
* | ||
* The debug modules -jbc, -jv and -jdump make extensive use of these | ||
* functions. Please check out their source code, if you want to know more. | ||
*/ | ||
const util: any; | ||
} |
@@ -1,6 +0,6 @@ | ||
import './5.1-or-jit'; | ||
import './5.2-or-jit'; | ||
import './5.2-plus-or-jit'; | ||
import './5.3-pre'; | ||
import './5.4-pre'; | ||
import './jit-only'; | ||
/// <reference path="./5.1-or-jit.d.ts" /> | ||
/// <reference path="./5.2-or-jit.d.ts" /> | ||
/// <reference path="./5.2-plus-or-jit.d.ts" /> | ||
/// <reference path="./5.3-pre.d.ts" /> | ||
/// <reference path="./5.4-pre.d.ts" /> | ||
/// <reference path="./jit-only.d.ts" /> |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
127750
37
1
6
2826
38
1
+ Addedtypescript-to-lua@^0.39.0
+ Addedfunction-bind@1.1.2(transitive)
+ Addedhasown@2.0.2(transitive)
+ Addedis-core-module@2.15.1(transitive)
+ Addedpath-parse@1.0.7(transitive)
+ Addedresolve@1.22.8(transitive)
+ Addedsource-map@0.7.4(transitive)
+ Addedsupports-preserve-symlinks-flag@1.0.0(transitive)
+ Addedtypescript@4.3.5(transitive)
+ Addedtypescript-to-lua@0.39.6(transitive)