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