2021-10-29 21:25:12 +01:00
|
|
|
// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
|
|
|
|
#include "Luau/BuiltinDefinitions.h"
|
|
|
|
|
|
|
|
namespace Luau
|
|
|
|
{
|
|
|
|
|
|
|
|
static const std::string kBuiltinDefinitionLuaSrc = R"BUILTIN_SRC(
|
|
|
|
|
|
|
|
declare bit32: {
|
2022-06-10 17:58:21 +01:00
|
|
|
band: (...number) -> number,
|
|
|
|
bor: (...number) -> number,
|
|
|
|
bxor: (...number) -> number,
|
|
|
|
btest: (number, ...number) -> boolean,
|
2022-11-04 17:33:22 +00:00
|
|
|
rrotate: (x: number, disp: number) -> number,
|
|
|
|
lrotate: (x: number, disp: number) -> number,
|
|
|
|
lshift: (x: number, disp: number) -> number,
|
|
|
|
arshift: (x: number, disp: number) -> number,
|
|
|
|
rshift: (x: number, disp: number) -> number,
|
|
|
|
bnot: (x: number) -> number,
|
|
|
|
extract: (n: number, field: number, width: number?) -> number,
|
|
|
|
replace: (n: number, v: number, field: number, width: number?) -> number,
|
|
|
|
countlz: (n: number) -> number,
|
|
|
|
countrz: (n: number) -> number,
|
2021-10-29 21:25:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
declare math: {
|
2022-10-21 16:05:56 +01:00
|
|
|
frexp: (n: number) -> (number, number),
|
|
|
|
ldexp: (s: number, e: number) -> number,
|
|
|
|
fmod: (x: number, y: number) -> number,
|
|
|
|
modf: (n: number) -> (number, number),
|
|
|
|
pow: (x: number, y: number) -> number,
|
|
|
|
exp: (n: number) -> number,
|
|
|
|
|
|
|
|
ceil: (n: number) -> number,
|
|
|
|
floor: (n: number) -> number,
|
|
|
|
abs: (n: number) -> number,
|
|
|
|
sqrt: (n: number) -> number,
|
|
|
|
|
|
|
|
log: (n: number, base: number?) -> number,
|
|
|
|
log10: (n: number) -> number,
|
|
|
|
|
|
|
|
rad: (n: number) -> number,
|
|
|
|
deg: (n: number) -> number,
|
|
|
|
|
|
|
|
sin: (n: number) -> number,
|
|
|
|
cos: (n: number) -> number,
|
|
|
|
tan: (n: number) -> number,
|
|
|
|
sinh: (n: number) -> number,
|
|
|
|
cosh: (n: number) -> number,
|
|
|
|
tanh: (n: number) -> number,
|
|
|
|
atan: (n: number) -> number,
|
|
|
|
acos: (n: number) -> number,
|
|
|
|
asin: (n: number) -> number,
|
|
|
|
atan2: (y: number, x: number) -> number,
|
2021-10-29 21:25:12 +01:00
|
|
|
|
2022-06-10 17:58:21 +01:00
|
|
|
min: (number, ...number) -> number,
|
|
|
|
max: (number, ...number) -> number,
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
pi: number,
|
|
|
|
huge: number,
|
|
|
|
|
2022-10-21 16:05:56 +01:00
|
|
|
randomseed: (seed: number) -> (),
|
2021-10-29 21:25:12 +01:00
|
|
|
random: (number?, number?) -> number,
|
|
|
|
|
2022-10-21 16:05:56 +01:00
|
|
|
sign: (n: number) -> number,
|
|
|
|
clamp: (n: number, min: number, max: number) -> number,
|
|
|
|
noise: (x: number, y: number?, z: number?) -> number,
|
|
|
|
round: (n: number) -> number,
|
2021-10-29 21:25:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type DateTypeArg = {
|
|
|
|
year: number,
|
|
|
|
month: number,
|
|
|
|
day: number,
|
|
|
|
hour: number?,
|
|
|
|
min: number?,
|
|
|
|
sec: number?,
|
|
|
|
isdst: boolean?,
|
|
|
|
}
|
|
|
|
|
|
|
|
type DateTypeResult = {
|
|
|
|
year: number,
|
|
|
|
month: number,
|
|
|
|
wday: number,
|
|
|
|
yday: number,
|
|
|
|
day: number,
|
|
|
|
hour: number,
|
|
|
|
min: number,
|
|
|
|
sec: number,
|
|
|
|
isdst: boolean,
|
|
|
|
}
|
|
|
|
|
|
|
|
declare os: {
|
2022-11-04 17:33:22 +00:00
|
|
|
time: (time: DateTypeArg?) -> number,
|
|
|
|
date: (formatString: string?, time: number?) -> DateTypeResult | string,
|
|
|
|
difftime: (t2: DateTypeResult | number, t1: DateTypeResult | number) -> number,
|
2021-10-29 21:25:12 +01:00
|
|
|
clock: () -> number,
|
|
|
|
}
|
|
|
|
|
|
|
|
declare function require(target: any): any
|
|
|
|
|
2022-03-18 00:46:04 +00:00
|
|
|
declare function getfenv(target: any): { [string]: any }
|
2021-10-29 21:25:12 +01:00
|
|
|
|
|
|
|
declare _G: any
|
|
|
|
declare _VERSION: string
|
|
|
|
|
|
|
|
declare function gcinfo(): number
|
|
|
|
|
2022-03-18 00:46:04 +00:00
|
|
|
declare function print<T...>(...: T...)
|
|
|
|
|
|
|
|
declare function type<T>(value: T): string
|
|
|
|
declare function typeof<T>(value: T): string
|
|
|
|
|
|
|
|
-- `assert` has a magic function attached that will give more detailed type information
|
|
|
|
declare function assert<T>(value: T, errorMessage: string?): T
|
2023-01-27 22:28:31 +00:00
|
|
|
declare function error<T>(message: T, level: number?): never
|
2022-03-18 00:46:04 +00:00
|
|
|
|
|
|
|
declare function tostring<T>(value: T): string
|
|
|
|
declare function tonumber<T>(value: T, radix: number?): number?
|
|
|
|
|
|
|
|
declare function rawequal<T1, T2>(a: T1, b: T2): boolean
|
|
|
|
declare function rawget<K, V>(tab: {[K]: V}, k: K): V
|
|
|
|
declare function rawset<K, V>(tab: {[K]: V}, k: K, v: V): {[K]: V}
|
2022-07-29 05:24:07 +01:00
|
|
|
declare function rawlen<K, V>(obj: {[K]: V} | string): number
|
2022-03-18 00:46:04 +00:00
|
|
|
|
|
|
|
declare function setfenv<T..., R...>(target: number | (T...) -> R..., env: {[string]: any}): ((T...) -> R...)?
|
|
|
|
|
2023-01-06 21:14:35 +00:00
|
|
|
declare function ipairs<V>(tab: {V}): (({V}, number) -> (number?, V), {V}, number)
|
2022-03-18 00:46:04 +00:00
|
|
|
|
|
|
|
declare function pcall<A..., R...>(f: (A...) -> R..., ...: A...): (boolean, R...)
|
|
|
|
|
|
|
|
-- FIXME: The actual type of `xpcall` is:
|
|
|
|
-- <E, A..., R1..., R2...>(f: (A...) -> R1..., err: (E) -> R2..., A...) -> (true, R1...) | (false, R2...)
|
|
|
|
-- Since we can't represent the return value, we use (boolean, R1...).
|
|
|
|
declare function xpcall<E, A..., R1..., R2...>(f: (A...) -> R1..., err: (E) -> R2..., ...: A...): (boolean, R1...)
|
|
|
|
|
|
|
|
-- `select` has a magic function attached to provide more detailed type information
|
|
|
|
declare function select<A...>(i: string | number, ...: A...): ...any
|
|
|
|
|
|
|
|
-- FIXME: This type is not entirely correct - `loadstring` returns a function or
|
|
|
|
-- (nil, string).
|
|
|
|
declare function loadstring<A...>(src: string, chunkname: string?): (((A...) -> any)?, string?)
|
|
|
|
|
|
|
|
declare function newproxy(mt: boolean?): any
|
|
|
|
|
|
|
|
declare coroutine: {
|
2022-11-04 17:33:22 +00:00
|
|
|
create: <A..., R...>(f: (A...) -> R...) -> thread,
|
|
|
|
resume: <A..., R...>(co: thread, A...) -> (boolean, R...),
|
2022-03-18 00:46:04 +00:00
|
|
|
running: () -> thread,
|
2022-11-04 17:33:22 +00:00
|
|
|
status: (co: thread) -> "dead" | "running" | "normal" | "suspended",
|
2022-03-18 00:46:04 +00:00
|
|
|
-- FIXME: This technically returns a function, but we can't represent this yet.
|
2022-11-04 17:33:22 +00:00
|
|
|
wrap: <A..., R...>(f: (A...) -> R...) -> any,
|
2022-03-18 00:46:04 +00:00
|
|
|
yield: <A..., R...>(A...) -> R...,
|
|
|
|
isyieldable: () -> boolean,
|
2022-11-04 17:33:22 +00:00
|
|
|
close: (co: thread) -> (boolean, any)
|
2022-03-18 00:46:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
declare table: {
|
2022-11-04 17:33:22 +00:00
|
|
|
concat: <V>(t: {V}, sep: string?, i: number?, j: number?) -> string,
|
|
|
|
insert: (<V>(t: {V}, value: V) -> ()) & (<V>(t: {V}, pos: number, value: V) -> ()),
|
|
|
|
maxn: <V>(t: {V}) -> number,
|
|
|
|
remove: <V>(t: {V}, number?) -> V?,
|
|
|
|
sort: <V>(t: {V}, comp: ((V, V) -> boolean)?) -> (),
|
|
|
|
create: <V>(count: number, value: V?) -> {V},
|
|
|
|
find: <V>(haystack: {V}, needle: V, init: number?) -> number?,
|
|
|
|
|
|
|
|
unpack: <V>(list: {V}, i: number?, j: number?) -> ...V,
|
2022-03-18 00:46:04 +00:00
|
|
|
pack: <V>(...V) -> { n: number, [number]: V },
|
|
|
|
|
2022-11-04 17:33:22 +00:00
|
|
|
getn: <V>(t: {V}) -> number,
|
|
|
|
foreach: <K, V>(t: {[K]: V}, f: (K, V) -> ()) -> (),
|
2022-03-18 00:46:04 +00:00
|
|
|
foreachi: <V>({V}, (number, V) -> ()) -> (),
|
|
|
|
|
2022-11-04 17:33:22 +00:00
|
|
|
move: <V>(src: {V}, a: number, b: number, t: number, dst: {V}?) -> {V},
|
|
|
|
clear: <K, V>(table: {[K]: V}) -> (),
|
2022-03-18 00:46:04 +00:00
|
|
|
|
2022-11-04 17:33:22 +00:00
|
|
|
isfrozen: <K, V>(t: {[K]: V}) -> boolean,
|
2022-03-18 00:46:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
declare debug: {
|
2022-11-04 17:33:22 +00:00
|
|
|
info: (<R...>(thread: thread, level: number, options: string) -> R...) & (<R...>(level: number, options: string) -> R...) & (<A..., R1..., R2...>(func: (A...) -> R1..., options: string) -> R2...),
|
|
|
|
traceback: ((message: string?, level: number?) -> string) & ((thread: thread, message: string?, level: number?) -> string),
|
2022-03-18 00:46:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
declare utf8: {
|
2022-06-03 23:15:45 +01:00
|
|
|
char: (...number) -> string,
|
2022-03-18 00:46:04 +00:00
|
|
|
charpattern: string,
|
2022-11-04 17:33:22 +00:00
|
|
|
codes: (str: string) -> ((string, number) -> (number, number), string, number),
|
|
|
|
codepoint: (str: string, i: number?, j: number?) -> ...number,
|
|
|
|
len: (s: string, i: number?, j: number?) -> (number?, number?),
|
|
|
|
offset: (s: string, n: number?, i: number?) -> number,
|
2022-03-18 00:46:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
-- Cannot use `typeof` here because it will produce a polytype when we expect a monotype.
|
|
|
|
declare function unpack<V>(tab: {V}, i: number?, j: number?): ...V
|
2021-10-29 21:25:12 +01:00
|
|
|
|
2021-11-12 14:27:34 +00:00
|
|
|
)BUILTIN_SRC";
|
|
|
|
|
|
|
|
std::string getBuiltinDefinitionSource()
|
|
|
|
{
|
2022-07-01 00:52:43 +01:00
|
|
|
std::string result = kBuiltinDefinitionLuaSrc;
|
|
|
|
return result;
|
2021-10-29 21:25:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Luau
|