@tilua-types/sunc 7.1.0 → 8.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.d.tilua CHANGED
@@ -11,33 +11,34 @@
11
11
  -- `RBXScriptSignal`), and `debug` here *adds* to the `debug` those libraries
12
12
  -- declare rather than replacing it.
13
13
  --
14
+ -- Every function is in a namespace by what it does — `env.getgenv()`,
15
+ -- `fs.read(path)`, `closure.hook(f, hook)` — and none is a global of its own.
16
+ -- A name the namespace already says is not said again — `fs.read`, not
17
+ -- `fs.readfile` — and every name is lowercase, as sUNC's are.
18
+ --
19
+ -- Nor can a script reach the executor's own globals by name: `readfile` or
20
+ -- `getrawmetatable` written in a script is reported, and compiles to `nil`.
21
+ -- The executor's environment is left as it is — `env.getgenv().readfile` is
22
+ -- still there, for whoever means it.
23
+ --
24
+ -- The namespaces are not the executor's: the compiler reads each from the
25
+ -- library's runtime (runtime/sunc.luau), which builds it as the script starts
26
+ -- from whatever the executor has. A function executors spell several ways is
27
+ -- whichever spelling there is — `http.request` is `request`, `http_request`,
28
+ -- `http.request` or `syn.request` — and one an executor has under none of them
29
+ -- raises "... is not available in this executor" when called.
30
+ --
14
31
  -- No executor implements all of this, and several names mean slightly
15
32
  -- different things between them. Where sUNC and UNC disagree, sUNC's shape is
16
- -- the one written down; where only UNC has a name (`crypt`, the `rconsole`
17
- -- family, mouse input), it is kept, since executors still expose it.
18
- --
19
- -- The other spellings UNC lists for a name (`http_request`, `getidentity`,
20
- -- `queueonteleport`, ...) are declared beside it, and the names every executor
21
- -- has that neither standard writes down — `decompile`, `saveinstance`, the
22
- -- keyboard — are at the end.
33
+ -- the one written down; where only UNC has a name (`crypt`, `rconsole`, mouse
34
+ -- input), it is kept, since executors still expose it.
35
+
36
+ type AnyFunction = (...args: unknown[]) => unknown
23
37
 
24
38
  -- ============================================================
25
- -- Environment
39
+ -- env: environments and the garbage collector
26
40
  -- ============================================================
27
41
 
28
- -- The executor's own global table — shared by every script it runs.
29
- declare function getgenv(): { [string]: unknown }
30
-
31
- -- The game's global environment: the `_G` LocalScripts and ModuleScripts see.
32
- declare function getrenv(): { [string]: unknown }
33
-
34
- -- The Luau registry.
35
- declare function getreg(): { [unknown]: unknown }
36
-
37
- -- Everything the garbage collector is holding. Tables are left out unless
38
- -- `includeTables` is true.
39
- declare function getgc(includeTables?: boolean): (((...args: unknown[]) => unknown) | { [unknown]: unknown })[]
40
-
41
42
  -- `filtergc` is `getgc` with the search done for you. The filter says what to
42
43
  -- look for, and `returnOne` asks for the first match instead of every match —
43
44
  -- which is what makes the return type two different things.
@@ -57,187 +58,233 @@ type TableFilter = {
57
58
  Metatable?: { [unknown]: unknown },
58
59
  }
59
60
 
60
- declare function filtergc(kind: "function", filter: FunctionFilter, returnOne: true): ((...args: unknown[]) => unknown) | nil
61
- declare function filtergc(kind: "function", filter: FunctionFilter, returnOne?: false): ((...args: unknown[]) => unknown)[]
62
- declare function filtergc(kind: "table", filter: TableFilter, returnOne: true): { [unknown]: unknown } | nil
63
- declare function filtergc(kind: "table", filter: TableFilter, returnOne?: false): { [unknown]: unknown }[]
61
+ declare env: {
62
+ -- The executor's own global table — shared by every script it runs.
63
+ getgenv: () => { [string]: unknown },
64
+ -- The game's global environment: the `_G` LocalScripts and ModuleScripts see.
65
+ getrenv: () => { [string]: unknown },
66
+ -- The Luau registry.
67
+ getreg: () => { [unknown]: unknown },
68
+ -- Everything the garbage collector is holding. Tables are left out unless
69
+ -- `includeTables` is true.
70
+ getgc: (includeTables?: boolean) => (AnyFunction | { [unknown]: unknown })[],
71
+ filtergc: ((kind: "function", filter: FunctionFilter, returnOne: true) => AnyFunction | nil)
72
+ & ((kind: "function", filter: FunctionFilter, returnOne?: false) => AnyFunction[])
73
+ & ((kind: "table", filter: TableFilter, returnOne: true) => { [unknown]: unknown } | nil)
74
+ & ((kind: "table", filter: TableFilter, returnOne?: false) => { [unknown]: unknown }[]),
75
+ }
64
76
 
65
77
  -- ============================================================
66
- -- Closures
78
+ -- closure: functions
67
79
  -- ============================================================
68
80
 
69
- -- Replace what `func` does with `hook`, and give back a callable copy of the
70
- -- original. The hook keeps the original's type, so a hooked function is still
71
- -- called the way it was.
72
- declare function hookfunction<T>(func: T, hook: (...args: unknown[]) => unknown): T
73
-
74
- -- Replace one metamethod of `object`'s metatable, returning the original.
75
- declare function hookmetamethod<T>(object: T, method: string, hook: (...args: unknown[]) => unknown): (...args: unknown[]) => unknown
76
-
77
- -- Undo every hook on a function, back to the one it started as. Errors if the
78
- -- function was never hooked.
79
- declare function restorefunction(func: (...args: unknown[]) => unknown): nil
80
-
81
- -- A copy of `func` that is a distinct function with the same behaviour.
82
- declare function clonefunction<T>(func: T): T
83
- declare function replaceclosure<T>(func: T, hook: (...args: unknown[]) => unknown): T
84
-
85
- -- Wrap a Luau function so it looks and behaves like a C closure.
86
- declare function newcclosure<T>(func: T): T
87
-
88
- -- Was the caller of the current function the executor, rather than the game?
89
- declare function checkcaller(): boolean
90
-
91
- declare function iscclosure(func: (...args: unknown[]) => unknown): boolean
92
- declare function islclosure(func: (...args: unknown[]) => unknown): boolean
93
- declare function isexecutorclosure(func: (...args: unknown[]) => unknown): boolean
94
- declare function isourclosure(func: (...args: unknown[]) => unknown): boolean
95
- declare function checkclosure(func: (...args: unknown[]) => unknown): boolean
96
-
97
- -- A hash of a function's bytecode: two functions that do the same thing have
98
- -- the same hash, which is how a hook finds its target across updates.
99
- declare function getfunctionhash(func: (...args: unknown[]) => unknown): string
81
+ declare closure: {
82
+ -- Replace what `func` does with `hook`, and give back a callable copy of
83
+ -- the original. The hook keeps the original's type, so a hooked function
84
+ -- is still called the way it was. (`hookfunction`, `replaceclosure`)
85
+ hook: <T>(func: T, hook: AnyFunction) => T,
86
+ -- Undo every hook on a function, back to the one it started as. Errors if
87
+ -- the function was never hooked. (`restorefunction`)
88
+ restore: (func: AnyFunction) => void,
89
+ -- A copy of `func` that is a distinct function with the same behaviour.
90
+ -- (`clonefunction`)
91
+ clone: <T>(func: T) => T,
92
+ -- Wrap a Luau function so it looks and behaves like a C closure.
93
+ -- (`newcclosure`)
94
+ newcclosure: <T>(func: T) => T,
95
+ -- (`iscclosure`, `islclosure`)
96
+ iscclosure: (func: AnyFunction) => boolean,
97
+ islclosure: (func: AnyFunction) => boolean,
98
+ -- Was the function made by the executor, rather than the game?
99
+ -- (`isexecutorclosure`, `isourclosure`, `checkclosure`)
100
+ isexecutorclosure: (func: AnyFunction) => boolean,
101
+ -- Was the caller of the current function the executor, rather than the
102
+ -- game? (`checkcaller`)
103
+ checkcaller: () => boolean,
104
+ -- A hash of a function's bytecode: two functions that do the same thing
105
+ -- have the same hash, which is how a hook finds its target across
106
+ -- updates. (`getfunctionhash`)
107
+ hash: (func: AnyFunction) => string,
108
+ -- A function's own bytecode, as `scripts.bytecode` gives a script's.
109
+ -- (`getfunctionbytecode`)
110
+ bytecode: (func: AnyFunction) => string,
111
+ }
100
112
 
101
113
  -- ============================================================
102
- -- Metatables
114
+ -- metatable
103
115
  -- ============================================================
104
116
 
105
- declare function getrawmetatable<T>(object: T): { [unknown]: unknown } | nil
106
- declare function setrawmetatable<T>(object: T, metatable: { [unknown]: unknown } | nil): T
107
- declare function isreadonly(object: unknown): boolean
108
- declare function setreadonly(object: unknown, readonly: boolean): nil
109
-
110
- -- Inside a `__namecall` hook: which method was called.
111
- declare function getnamecallmethod(): string
117
+ declare metatable: {
118
+ -- (`getrawmetatable`, `setrawmetatable`)
119
+ getraw: <T>(object: T) => { [unknown]: unknown } | nil,
120
+ setraw: <T>(object: T, metatable: { [unknown]: unknown } | nil) => T,
121
+ -- (`isreadonly`, `setreadonly`)
122
+ isreadonly: (object: unknown) => boolean,
123
+ setreadonly: (object: unknown, readonly: boolean) => void,
124
+ -- Replace one metamethod of `object`'s metatable, returning the original.
125
+ -- (`hookmetamethod`)
126
+ hook: <T>(object: T, method: string, hook: AnyFunction) => AnyFunction,
127
+ -- Inside a `__namecall` hook: which method was called.
128
+ -- (`getnamecallmethod`)
129
+ getnamecallmethod: () => string,
130
+ }
112
131
 
113
132
  -- ============================================================
114
- -- Scripts and threads
133
+ -- scripts
115
134
  -- ============================================================
116
135
 
117
- declare function getcallingscript(): BaseScript | nil
118
- declare function getscripts(): (LocalScript | ModuleScript)[]
119
- declare function getrunningscripts(): (LocalScript | ModuleScript)[]
120
- declare function getloadedmodules(excludeCore?: boolean): ModuleScript[]
121
- declare function getscriptfromthread(thread: thread): BaseScript | nil
122
-
123
- -- A script's globals, the way the script itself sees them.
124
- declare function getsenv(script: LocalScript | ModuleScript): { [string]: unknown }
125
-
126
- declare function getscriptbytecode(script: LocalScript | ModuleScript): string
127
- declare function getscriptclosure(script: LocalScript | ModuleScript): (...args: unknown[]) => unknown
128
- declare function getscripthash(script: LocalScript | ModuleScript): string
129
- declare function getscriptfunction(script: LocalScript | ModuleScript): (...args: unknown[]) => unknown
130
- declare function dumpstring(script: LocalScript | ModuleScript): string
131
-
132
- -- The current thread's permission level, and a way to change it.
133
- declare function getthreadidentity(): number
134
- declare function setthreadidentity(identity: number): nil
135
- declare function getidentity(): number
136
- declare function setidentity(identity: number): nil
137
- declare function getthreadcontext(): number
138
- declare function setthreadcontext(identity: number): nil
136
+ declare scripts: {
137
+ -- (`getcallingscript`)
138
+ calling: () => BaseScript | nil,
139
+ -- (`getscripts`, `getrunningscripts`, `getloadedmodules`)
140
+ all: () => (LocalScript | ModuleScript)[],
141
+ running: () => (LocalScript | ModuleScript)[],
142
+ loadedmodules: (excludeCore?: boolean) => ModuleScript[],
143
+ -- (`getscriptfromthread`)
144
+ fromthread: (thread: thread) => BaseScript | nil,
145
+ -- A script's globals, the way the script itself sees them. (`getsenv`)
146
+ env: (script: LocalScript | ModuleScript) => { [string]: unknown },
147
+ -- (`getscriptbytecode`, `dumpstring`)
148
+ bytecode: (script: LocalScript | ModuleScript) => string,
149
+ -- (`getscriptclosure`, `getscriptfunction`)
150
+ closure: (script: LocalScript | ModuleScript) => AnyFunction,
151
+ -- (`getscripthash`)
152
+ hash: (script: LocalScript | ModuleScript) => string,
153
+ -- A script's bytecode turned back into Luau source. What comes back is
154
+ -- the decompiler's reading of it — names of locals are gone — and on
155
+ -- failure it is a comment saying so rather than an error. (`decompile`)
156
+ decompile: (script: LocalScript | ModuleScript | AnyFunction) => string,
157
+ }
139
158
 
140
159
  -- ============================================================
141
- -- Instances
160
+ -- identity: the current thread's permission level
142
161
  -- ============================================================
143
162
 
144
- -- A reference to the same instance that the game's own code cannot recognise
145
- -- as yours — what keeps a detection hook from seeing the instance you hold.
146
- declare function cloneref<T>(object: T): T
147
-
148
- -- Two references, one instance?
149
- declare function compareinstances(a: Instance, b: Instance): boolean
150
-
151
- -- Every instance in the data model, and those parented to nil.
152
- declare function getinstances(): Instance[]
153
- declare function getnilinstances(): Instance[]
154
-
155
- -- A hidden container for the executor's own UI, which the game cannot see.
156
- declare function gethui(): Folder
157
-
158
- -- Properties the engine hides from scripts: `Instance.Archivable`-style flags,
159
- -- and anything marked not scriptable.
160
- declare function gethiddenproperty(object: Instance, property: string): [unknown, boolean]
161
- declare function sethiddenproperty(object: Instance, property: string, value: unknown): boolean
162
- declare function isscriptable(object: Instance, property: string): boolean
163
- declare function setscriptable(object: Instance, property: string, scriptable: boolean): boolean
163
+ declare identity: {
164
+ -- (`getthreadidentity`, `getidentity`, `getthreadcontext`)
165
+ get: () => number,
166
+ -- (`setthreadidentity`, `setidentity`, `setthreadcontext`)
167
+ set: (identity: number) => void,
168
+ }
164
169
 
165
- -- The function assigned to a callback property (`OnServerInvoke`, ...).
166
- declare function getcallbackvalue(object: Instance, property: string): ((...args: unknown[]) => unknown) | nil
170
+ -- ============================================================
171
+ -- instance
172
+ -- ============================================================
167
173
 
168
- declare function setrbxclipboard(data: string): boolean
174
+ declare instance: {
175
+ -- A reference to the same instance that the game's own code cannot
176
+ -- recognise as yours — what keeps a detection hook from seeing the
177
+ -- instance you hold. (`cloneref`)
178
+ cloneref: <T>(object: T) => T,
179
+ -- Two references, one instance? (`compareinstances`)
180
+ compare: (a: Instance, b: Instance) => boolean,
181
+ -- Every instance in the data model, and those parented to nil.
182
+ -- (`getinstances`, `getnilinstances`)
183
+ all: () => Instance[],
184
+ nilparented: () => Instance[],
185
+ -- A hidden container for the executor's own UI, which the game cannot
186
+ -- see. (`gethui`)
187
+ gethui: () => Folder,
188
+ -- Properties the engine hides from scripts: `Instance.Archivable`-style
189
+ -- flags, and anything marked not scriptable. `gethidden` answers the value
190
+ -- and whether it was hidden. (`gethiddenproperty`, `sethiddenproperty`,
191
+ -- `isscriptable`, `setscriptable`)
192
+ gethidden: (object: Instance, property: string) => [unknown, boolean],
193
+ sethidden: (object: Instance, property: string, value: unknown) => boolean,
194
+ isscriptable: (object: Instance, property: string) => boolean,
195
+ setscriptable: (object: Instance, property: string, scriptable: boolean) => boolean,
196
+ -- The function assigned to a callback property (`OnServerInvoke`, ...).
197
+ -- (`getcallbackvalue`)
198
+ getcallback: (object: Instance, property: string) => AnyFunction | nil,
199
+ -- (`fireclickdetector`, `fireproximityprompt`)
200
+ fireclickdetector: (object: ClickDetector, distance?: number, event?: string) => void,
201
+ fireproximityprompt: (prompt: ProximityPrompt) => void,
202
+ -- `toggle` is true (or 0) to begin the touch and false (or 1) to end it.
203
+ -- (`firetouchinterest`)
204
+ firetouch: (part: BasePart, other: BasePart, toggle: boolean | number) => void,
205
+ -- `game:GetObjects`, which a script may not call itself. (`getobjects`)
206
+ getobjects: (assetId: string) => Instance[],
207
+ -- Does this client simulate the part's physics? (`isnetworkowner`)
208
+ isnetworkowner: (part: BasePart) => boolean,
209
+ -- Write the place, or one instance and what is under it, to a file in the
210
+ -- workspace folder. The options are the executor's own (`mode`,
211
+ -- `noscripts`, `FilePath`, ...), so they are left open. (`saveinstance`)
212
+ save: (target?: Instance | { [string]: unknown }, options?: { [string]: unknown }) => void,
213
+ }
169
214
 
170
215
  declare cache: {
171
216
  -- Forget an instance, so the next reference to it is a new one.
172
- invalidate: (object: Instance) => nil,
217
+ invalidate: (object: Instance) => void,
173
218
  -- Point every future reference to `object` at `newObject` instead.
174
- replace: (object: Instance, newObject: Instance) => nil,
219
+ replace: (object: Instance, newObject: Instance) => void,
220
+ -- (`cache.iscached`)
175
221
  iscached: (object: Instance) => boolean,
176
222
  }
177
223
 
178
224
  -- ============================================================
179
- -- Signals and events
225
+ -- signal
180
226
  -- ============================================================
181
227
 
182
228
  -- One connection of a signal. `Function` and `Thread` are nil for connections
183
229
  -- the engine made itself.
184
230
  type Connection = {
185
- Function: ((...args: unknown[]) => unknown) | nil,
231
+ Function: AnyFunction | nil,
186
232
  Thread: thread | nil,
187
233
  Enabled: boolean,
188
234
  ForeignState: boolean,
189
235
  LuaConnection: boolean,
190
- Fire: (self: Connection, ...args: unknown[]) => nil,
191
- Defer: (self: Connection, ...args: unknown[]) => nil,
192
- Disconnect: (self: Connection) => nil,
193
- Disable: (self: Connection) => nil,
194
- Enable: (self: Connection) => nil,
236
+ Fire: (self: Connection, ...args: unknown[]) => void,
237
+ Defer: (self: Connection, ...args: unknown[]) => void,
238
+ Disconnect: (self: Connection) => void,
239
+ Disable: (self: Connection) => void,
240
+ Enable: (self: Connection) => void,
195
241
  }
196
242
 
197
243
  -- Any signal at all. Written as the shape every signal has rather than as
198
244
  -- `RBXScriptSignal<T>`, because a signal's type carries the arguments of its
199
245
  -- own event, as a tuple, and these functions do not care which event it is.
200
- type AnySignal = { Connect: (self: unknown, callback: (...args: unknown[]) => nil) => RBXScriptConnection }
201
-
202
- declare function getconnections(signal: AnySignal): Connection[]
203
-
204
- -- Run every Luau connection of a signal now.
205
- declare function firesignal(signal: AnySignal, ...args: unknown[]): nil
206
-
207
- -- Send a signal to the server, for the signals that replicate.
208
- declare function replicatesignal(signal: AnySignal, ...args: unknown[]): nil
209
-
210
- declare function fireclickdetector(object: ClickDetector, distance?: number, event?: string): nil
211
- declare function fireproximityprompt(prompt: ProximityPrompt): nil
212
-
213
- -- `toggle` is true (or 0) to begin the touch and false (or 1) to end it.
214
- declare function firetouchinterest(part: BasePart, other: BasePart, toggle: boolean | number): nil
246
+ type AnySignal = { Connect: (self: unknown, callback: (...args: unknown[]) => void) => RBXScriptConnection }
247
+
248
+ declare signal: {
249
+ -- (`getconnections`)
250
+ connections: (signal: AnySignal) => Connection[],
251
+ -- Run every Luau connection of a signal now. (`firesignal`)
252
+ fire: (signal: AnySignal, ...args: unknown[]) => void,
253
+ -- Send a signal to the server, for the signals that replicate.
254
+ -- (`replicatesignal`)
255
+ replicate: (signal: AnySignal, ...args: unknown[]) => void,
256
+ }
215
257
 
216
258
  -- ============================================================
217
- -- Filesystem
259
+ -- fs: the executor's workspace folder
218
260
  -- ============================================================
219
261
  --
220
262
  -- Paths are relative to the executor's own workspace folder.
221
263
 
222
- declare function readfile(path: string): string
223
- declare function writefile(path: string, data: string): nil
224
- declare function appendfile(path: string, data: string): nil
225
- declare function delfile(path: string): nil
226
- declare function isfile(path: string): boolean
227
- declare function listfiles(path: string): string[]
228
- declare function makefolder(path: string): nil
229
- declare function delfolder(path: string): nil
230
- declare function isfolder(path: string): boolean
231
- declare function dofile(path: string): nil
232
- -- Compiles a file without running it, as `loadstring` does a string.
233
- declare function loadfile(path: string, chunkname?: string): [((...args: unknown[]) => unknown) | nil, string | nil]
234
-
235
- -- A `rbxasset://` id for a file on disk, usable wherever the engine takes a
236
- -- content id (images, sounds, meshes).
237
- declare function getcustomasset(path: string, noCache?: boolean): string
264
+ declare fs: {
265
+ -- (`readfile`, `writefile`, `appendfile`, `delfile`, `isfile`, `listfiles`)
266
+ read: (path: string) => string,
267
+ write: (path: string, data: string) => void,
268
+ append: (path: string, data: string) => void,
269
+ delete: (path: string) => void,
270
+ isfile: (path: string) => boolean,
271
+ list: (path: string) => string[],
272
+ -- (`makefolder`, `delfolder`, `isfolder`)
273
+ makefolder: (path: string) => void,
274
+ deletefolder: (path: string) => void,
275
+ isfolder: (path: string) => boolean,
276
+ -- Run a file. (`dofile`)
277
+ dofile: (path: string) => void,
278
+ -- Compile a file without running it, as `loadstring` does a string.
279
+ -- (`loadfile`)
280
+ loadfile: (path: string, chunkname?: string) => [AnyFunction | nil, string | nil],
281
+ -- A `rbxasset://` id for a file on disk, usable wherever the engine takes
282
+ -- a content id (images, sounds, meshes). (`getcustomasset`)
283
+ getcustomasset: (path: string, noCache?: boolean) => string,
284
+ }
238
285
 
239
286
  -- ============================================================
240
- -- HTTP and encoding
287
+ -- http, websocket
241
288
  -- ============================================================
242
289
 
243
290
  type HttpRequest = {
@@ -256,62 +303,94 @@ type HttpResponse = {
256
303
  Headers: { [string]: string },
257
304
  }
258
305
 
259
- -- Yields until the response arrives.
260
- declare function request(options: HttpRequest): HttpResponse
261
- declare function http_request(options: HttpRequest): HttpResponse
262
- declare http: {
263
- request: (options: HttpRequest) => HttpResponse,
306
+ -- What a body can hold that a Luau table cannot: a key whose value is nil.
307
+ -- Each stands in for one in a body built by `http.request(types => ...)`, and
308
+ -- is written as what it says as the request goes out.
309
+ type HttpPlaceholder = { readonly __httpPlaceholder: true }
310
+ type HttpTypes = {
311
+ -- JSON's `null`: the key is sent, with no value.
312
+ readonly null: HttpPlaceholder,
313
+ -- Not sent at all, as JavaScript's `undefined`: left out of an object,
314
+ -- and `null` in an array, where leaving it out would move the rest.
315
+ readonly undefined: HttpPlaceholder,
264
316
  }
265
317
 
266
- declare function base64encode(data: string): string
267
- declare function base64decode(data: string): string
268
- declare function lz4compress(data: string): string
269
- declare function lz4decompress(data: string, size: number): string
270
-
271
- -- UNC put the encoding and cipher helpers in one table; executors still do.
272
- declare crypt: {
273
- base64encode: (data: string) => string,
274
- base64decode: (data: string) => string,
275
- base64_encode: (data: string) => string,
276
- base64_decode: (data: string) => string,
277
- base64: { encode: (data: string) => string, decode: (data: string) => string },
278
- encrypt: (data: string, key: string, iv?: string, mode?: string) => [string, string],
279
- decrypt: (data: string, key: string, iv: string, mode: string) => string,
280
- hash: (data: string, algorithm: string) => string,
281
- generatebytes: (size: number) => string,
282
- generatekey: () => string,
318
+ -- A request built by a function. `Body` may be the value itself, sent as JSON
319
+ -- — `[]` an array and `{}` an object, as `HttpService:JSONEncode` writes them
320
+ -- under tilua, and with `Content-Type: application/json` unless the headers
321
+ -- say otherwise — or a string, sent as it is.
322
+ type HttpBuiltRequest = {
323
+ Url: string,
324
+ Method?: "GET" | "POST" | "PATCH" | "PUT" | "DELETE" | "HEAD" | "OPTIONS",
325
+ Body?: string | { [string]: unknown } | unknown[],
326
+ Headers?: { [string]: string },
327
+ Cookies?: { [string]: string },
283
328
  }
284
329
 
285
- declare base64: {
286
- encode: (data: string) => string,
287
- decode: (data: string) => string,
330
+ declare http: {
331
+ -- Yields until the response arrives. Given a function, calls it with the
332
+ -- placeholders and sends the request it builds:
333
+ --
334
+ -- http.request(types => ({
335
+ -- Url: url, Method: "POST",
336
+ -- Body: { name: "x", team: types.null, tags: [] },
337
+ -- }))
338
+ --
339
+ -- (`request`, `http_request`, `http.request`, `syn.request`, `fluxus.request`)
340
+ request: ((options: HttpRequest) => HttpResponse)
341
+ & ((build: (types: HttpTypes) => HttpBuiltRequest) => HttpResponse),
288
342
  }
289
343
 
290
344
  type WebSocketConnection = {
291
- Send: (self: WebSocketConnection, message: string) => nil,
292
- Close: (self: WebSocketConnection) => nil,
345
+ Send: (self: WebSocketConnection, message: string) => void,
346
+ Close: (self: WebSocketConnection) => void,
293
347
  OnMessage: RBXScriptSignal<[string]>,
294
348
  OnClose: RBXScriptSignal<[]>,
295
349
  }
296
350
 
297
- declare WebSocket: {
351
+ declare websocket: {
352
+ -- (`WebSocket.connect`)
298
353
  connect: (url: string) => WebSocketConnection,
299
354
  }
300
355
 
301
356
  -- ============================================================
302
- -- Drawing
357
+ -- encoding, crypt
358
+ -- ============================================================
359
+
360
+ declare encoding: {
361
+ -- (`base64encode`, `crypt.base64encode`, `crypt.base64_encode`,
362
+ -- `crypt.base64.encode`, `base64.encode`, and the same for decode)
363
+ base64encode: (data: string) => string,
364
+ base64decode: (data: string) => string,
365
+ -- (`lz4compress`, `lz4decompress`)
366
+ lz4compress: (data: string) => string,
367
+ lz4decompress: (data: string, size: number) => string,
368
+ }
369
+
370
+ declare crypt: {
371
+ -- The ciphertext and the iv it used.
372
+ encrypt: (data: string, key: string, iv?: string, mode?: string) => [string, string],
373
+ decrypt: (data: string, key: string, iv: string, mode: string) => string,
374
+ hash: (data: string, algorithm: string) => string,
375
+ -- (`crypt.generatebytes`, `crypt.generatekey`)
376
+ generatebytes: (size: number) => string,
377
+ generatekey: () => string,
378
+ }
379
+
380
+ -- ============================================================
381
+ -- drawing
303
382
  -- ============================================================
304
383
  --
305
- -- Shapes drawn above the game window. `Drawing.new` gives back the type its
306
- -- argument names, so `Drawing.new("Circle").Radius` is a number and
307
- -- `Drawing.new("Line").Radius` is an error.
384
+ -- Shapes drawn above the game window. `drawing.new` gives back the type its
385
+ -- argument names, so `drawing.new("Circle").Radius` is a number and
386
+ -- `drawing.new("Line").Radius` is an error.
308
387
 
309
388
  type BaseDrawing = {
310
389
  Visible: boolean,
311
390
  ZIndex: number,
312
391
  Transparency: number,
313
392
  Color: Color3,
314
- Destroy: (self: BaseDrawing) => nil,
393
+ Destroy: (self: BaseDrawing) => void,
315
394
  }
316
395
 
317
396
  type DrawingLine = BaseDrawing & { From: Vector2, To: Vector2, Thickness: number }
@@ -342,7 +421,8 @@ type DrawingTriangle = BaseDrawing & {
342
421
  type Drawing = DrawingLine | DrawingText | DrawingImage | DrawingCircle
343
422
  | DrawingSquare | DrawingQuad | DrawingTriangle
344
423
 
345
- declare Drawing: {
424
+ declare drawing: {
425
+ -- (`Drawing.new`)
346
426
  new: ((kind: "Line") => DrawingLine)
347
427
  & ((kind: "Text") => DrawingText)
348
428
  & ((kind: "Image") => DrawingImage)
@@ -350,66 +430,65 @@ declare Drawing: {
350
430
  & ((kind: "Square") => DrawingSquare)
351
431
  & ((kind: "Quad") => DrawingQuad)
352
432
  & ((kind: "Triangle") => DrawingTriangle),
353
- Fonts: { UI: number, System: number, Plex: number, Monospace: number },
433
+ -- (`Drawing.Fonts`)
434
+ fonts: { UI: number, System: number, Plex: number, Monospace: number },
435
+ -- Destroy every drawing at once; references to them stop working.
436
+ -- (`cleardrawcache`)
437
+ clear: () => void,
438
+ -- (`getrenderproperty`, `setrenderproperty`, `isrenderobj`)
439
+ getproperty: (drawing: Drawing, property: string) => unknown,
440
+ setproperty: (drawing: Drawing, property: string, value: unknown) => void,
441
+ isdrawing: (object: unknown) => boolean,
354
442
  }
355
443
 
356
- -- Destroy every drawing at once; references to them stop working.
357
- declare function cleardrawcache(): nil
358
-
359
- declare function getrenderproperty(drawing: Drawing, property: string): unknown
360
- declare function setrenderproperty(drawing: Drawing, property: string, value: unknown): nil
361
- declare function isrenderobj(object: unknown): boolean
362
-
363
444
  -- ============================================================
364
- -- Console
445
+ -- rconsole: the executor's own console window
365
446
  -- ============================================================
366
447
 
367
- declare function rconsolecreate(): nil
368
- declare function rconsoledestroy(): nil
369
- declare function rconsoleclear(): nil
370
- declare function rconsoleprint(text: string): nil
371
- declare function rconsolesettitle(title: string): nil
372
- declare function rconsoleinput(): string
373
- declare function rconsolename(title: string): nil
374
-
375
- -- The same six without the `r`.
376
- declare function consolecreate(): nil
377
- declare function consoledestroy(): nil
378
- declare function consoleclear(): nil
379
- declare function consoleprint(text: string): nil
380
- declare function consolesettitle(title: string): nil
381
- declare function consoleinput(): string
448
+ declare rconsole: {
449
+ -- (`rconsolecreate` ... `rconsoleinput`, and the same without the `r`;
450
+ -- `rconsolename` for `settitle`)
451
+ create: () => void,
452
+ destroy: () => void,
453
+ clear: () => void,
454
+ print: (text: string) => void,
455
+ settitle: (title: string) => void,
456
+ input: () => string,
457
+ }
382
458
 
383
459
  -- ============================================================
384
- -- Input
460
+ -- input: real mouse and keyboard events
385
461
  -- ============================================================
386
462
  --
387
- -- Real mouse and keyboard events, delivered to the window. They do nothing
388
- -- while the Roblox window is not the active one — `isrbxactive` says whether
389
- -- it is.
390
-
391
- declare function isrbxactive(): boolean
392
- declare function isgameactive(): boolean
393
- declare function mouse1click(): nil
394
- declare function mouse1press(): nil
395
- declare function mouse1release(): nil
396
- declare function mouse2click(): nil
397
- declare function mouse2press(): nil
398
- declare function mouse2release(): nil
399
- declare function mousemoveabs(x: number, y: number): nil
400
- declare function mousemoverel(x: number, y: number): nil
401
- declare function mousescroll(pixels: number): nil
402
-
403
- -- Keys are Windows virtual-key codes (`0x57` is W), not `Enum.KeyCode`.
404
- declare function keypress(key: number): nil
405
- declare function keyrelease(key: number): nil
406
- declare function keyclick(key: number): nil
463
+ -- Delivered to the window. They do nothing while the Roblox window is not the
464
+ -- active one — `input.isactive` says whether it is.
465
+
466
+ declare input: {
467
+ -- (`isrbxactive`, `isgameactive`)
468
+ isactive: () => boolean,
469
+ -- (`mouse1click`, `mouse1press`, ...)
470
+ mouse1click: () => void,
471
+ mouse1press: () => void,
472
+ mouse1release: () => void,
473
+ mouse2click: () => void,
474
+ mouse2press: () => void,
475
+ mouse2release: () => void,
476
+ -- (`mousemoveabs`, `mousemoverel`, `mousescroll`)
477
+ mousemoveabs: (x: number, y: number) => void,
478
+ mousemoverel: (x: number, y: number) => void,
479
+ mousescroll: (pixels: number) => void,
480
+ -- Keys are Windows virtual-key codes (`0x57` is W), not `Enum.KeyCode`.
481
+ -- (`keypress`, `keyrelease`, `keyclick`)
482
+ keypress: (key: number) => void,
483
+ keyrelease: (key: number) => void,
484
+ keyclick: (key: number) => void,
485
+ }
407
486
 
408
487
  -- ============================================================
409
- -- Debug
488
+ -- debug
410
489
  -- ============================================================
411
490
  --
412
- -- These add to the `debug` of the standard library and `@tilua-types/roblox`: the executor
491
+ -- These add to Lua's own `debug`, which is already a global: the executor
413
492
  -- reaches into a function's own bytecode. Each takes a function, or a stack
414
493
  -- level counted from the caller.
415
494
 
@@ -418,7 +497,7 @@ declare function keyclick(key: number): nil
418
497
  type DebugInfo = {
419
498
  source: string,
420
499
  short_src: string,
421
- func: (...args: unknown[]) => unknown,
500
+ func: AnyFunction,
422
501
  what: "Lua" | "C",
423
502
  currentline: number,
424
503
  name: string,
@@ -428,69 +507,53 @@ type DebugInfo = {
428
507
  }
429
508
 
430
509
  declare debug: {
431
- getinfo: (func: ((...args: unknown[]) => unknown) | number) => DebugInfo,
432
- getconstant: (func: ((...args: unknown[]) => unknown) | number, index: number) => unknown,
433
- getconstants: (func: ((...args: unknown[]) => unknown) | number) => unknown[],
434
- setconstant: (func: ((...args: unknown[]) => unknown) | number, index: number, value: unknown) => nil,
435
- getupvalue: (func: ((...args: unknown[]) => unknown) | number, index: number) => unknown,
436
- getupvalues: (func: ((...args: unknown[]) => unknown) | number) => unknown[],
437
- setupvalue: (func: ((...args: unknown[]) => unknown) | number, index: number, value: unknown) => nil,
438
- getproto: (func: ((...args: unknown[]) => unknown) | number, index: number, active?: boolean)
439
- => ((...args: unknown[]) => unknown) | ((...args: unknown[]) => unknown)[],
440
- getprotos: (func: ((...args: unknown[]) => unknown) | number) => ((...args: unknown[]) => unknown)[],
510
+ getinfo: (func: AnyFunction | number) => DebugInfo,
511
+ getconstant: (func: AnyFunction | number, index: number) => unknown,
512
+ getconstants: (func: AnyFunction | number) => unknown[],
513
+ setconstant: (func: AnyFunction | number, index: number, value: unknown) => void,
514
+ getupvalue: (func: AnyFunction | number, index: number) => unknown,
515
+ getupvalues: (func: AnyFunction | number) => unknown[],
516
+ setupvalue: (func: AnyFunction | number, index: number, value: unknown) => void,
517
+ getproto: (func: AnyFunction | number, index: number, active?: boolean) => AnyFunction | AnyFunction[],
518
+ getprotos: (func: AnyFunction | number) => AnyFunction[],
441
519
  getstack: (level: number, index?: number) => unknown,
442
- setstack: (level: number, index: number, value: unknown) => nil,
520
+ setstack: (level: number, index: number, value: unknown) => void,
443
521
  }
444
522
 
445
523
  -- ============================================================
446
- -- Miscellaneous
524
+ -- executor, clipboard, teleport, actor
447
525
  -- ============================================================
448
526
 
449
- -- The executor's name and version.
450
- declare function identifyexecutor(): [string, string]
451
- declare function getexecutorname(): [string, string]
452
-
453
- declare function setclipboard(text: string): nil
454
- declare function toclipboard(text: string): nil
455
- declare function setfpscap(fps: number): nil
456
- declare function getfpscap(): number
457
- declare function messagebox(text: string, caption: string, flags: number): number
458
-
459
- -- Source to run after the next teleport, in the new place.
460
- declare function queue_on_teleport(code: string): nil
461
- declare function queueonteleport(code: string): nil
462
-
463
- -- ============================================================
464
- -- Beyond the standards
465
- -- ============================================================
466
- --
467
- -- In neither sUNC nor UNC, and in nearly every executor all the same. With no
468
- -- standard to follow, the shapes are the ones executors agree on.
469
-
470
- -- A script's bytecode turned back into Luau source. What comes back is the
471
- -- decompiler's reading of it — names of locals are gone — and on failure it is
472
- -- a comment saying so rather than an error.
473
- declare function decompile(script: LocalScript | ModuleScript | ((...args: unknown[]) => unknown)): string
474
-
475
- -- A function's own bytecode, as `getscriptbytecode` gives a script's.
476
- declare function getfunctionbytecode(func: (...args: unknown[]) => unknown): string
477
-
478
- -- Write the place, or one instance and what is under it, to a file in the
479
- -- workspace folder. The options are the executor's own (`mode`, `noscripts`,
480
- -- `FilePath`, ...), so they are left open.
481
- declare function saveinstance(target?: Instance | { [string]: unknown }, options?: { [string]: unknown }): nil
482
-
483
- -- `game:GetObjects`, which a script may not call itself.
484
- declare function getobjects(assetId: string): Instance[]
527
+ declare executor: {
528
+ -- The executor's name and version. (`identifyexecutor`, `getexecutorname`)
529
+ identify: () => [string, string],
530
+ -- An id for the machine the executor runs on. (`gethwid`)
531
+ hwid: () => string,
532
+ -- (`setfpscap`, `getfpscap`)
533
+ setfpscap: (fps: number) => void,
534
+ getfpscap: () => number,
535
+ -- (`messagebox`)
536
+ messagebox: (text: string, caption: string, flags: number) => number,
537
+ }
485
538
 
486
- -- Does this client simulate the part's physics?
487
- declare function isnetworkowner(part: BasePart): boolean
539
+ declare clipboard: {
540
+ -- (`setclipboard`, `toclipboard`)
541
+ set: (text: string) => void,
542
+ -- Roblox Studio's clipboard, of instances. (`setrbxclipboard`)
543
+ setrbx: (data: string) => boolean,
544
+ }
488
545
 
489
- -- An id for the machine the executor runs on.
490
- declare function gethwid(): string
546
+ declare teleport: {
547
+ -- Source to run after the next teleport, in the new place.
548
+ -- (`queue_on_teleport`, `queueonteleport`, `queueteleport`)
549
+ queue: (code: string) => void,
550
+ }
491
551
 
492
552
  -- Parallel Luau: the actors of the game, and code run inside one — each actor
493
553
  -- is a Luau state of its own, which a script outside cannot reach.
494
- declare function getactors(): Actor[]
495
- declare function run_on_actor(actor: Actor, code: string, ...args: unknown[]): nil
496
- declare function isparallel(): boolean
554
+ declare actor: {
555
+ -- (`getactors`, `run_on_actor`, `isparallel`)
556
+ all: () => Actor[],
557
+ run: (actor: Actor, code: string, ...args: unknown[]) => void,
558
+ isparallel: () => boolean,
559
+ }