@tilua-types/sunc 8.0.0 → 10.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/README.md +19 -2
- package/index.d.tilua +116 -115
- package/lowering.mjs +3 -0
- package/package.json +2 -2
- package/runtime/sunc.luau +277 -278
package/README.md
CHANGED
|
@@ -37,8 +37,14 @@ http.request({ Url: url })
|
|
|
37
37
|
The namespaces are not the executor's — no executor has `fs` or `closure`.
|
|
38
38
|
The compiler reads each from the library's runtime, which builds it as the
|
|
39
39
|
script starts from whatever the executor has, under whichever spelling it
|
|
40
|
-
has. A function the executor has under none of them
|
|
41
|
-
|
|
40
|
+
has. A function the executor has under none of them is `nil`, so every
|
|
41
|
+
member is optional and a script says what it needs before it calls it:
|
|
42
|
+
|
|
43
|
+
```luau
|
|
44
|
+
if (fs.write) fs.write("log.txt", text)
|
|
45
|
+
const hui = instance.gethui
|
|
46
|
+
const parent = hui ? hui() : game:GetService("CoreGui")
|
|
47
|
+
```
|
|
42
48
|
|
|
43
49
|
| Namespace | Functions (what the executor calls them) |
|
|
44
50
|
| --- | --- |
|
|
@@ -110,3 +116,14 @@ No executor implements all of this, and several names mean slightly different
|
|
|
110
116
|
things between them — the types say what the standard says, not what any one
|
|
111
117
|
executor does. Nothing here exists in a normal Roblox game: a script using
|
|
112
118
|
these runs only under an executor.
|
|
119
|
+
|
|
120
|
+
<!-- compatibility:start -->
|
|
121
|
+
## Compatibility
|
|
122
|
+
|
|
123
|
+
`@tilua-types/sunc@10.0.0` works with these tilua packages. *Released with* is the
|
|
124
|
+
version it was built and tested against.
|
|
125
|
+
|
|
126
|
+
| Package | Range | Released with | |
|
|
127
|
+
| --- | --- | --- | --- |
|
|
128
|
+
| `@tilua-types/roblox` | `^9.0.0` | 9.0.0 | dependency |
|
|
129
|
+
<!-- compatibility:end -->
|
package/index.d.tilua
CHANGED
|
@@ -26,7 +26,8 @@
|
|
|
26
26
|
-- from whatever the executor has. A function executors spell several ways is
|
|
27
27
|
-- whichever spelling there is — `http.request` is `request`, `http_request`,
|
|
28
28
|
-- `http.request` or `syn.request` — and one an executor has under none of them
|
|
29
|
-
--
|
|
29
|
+
-- is `nil`, so every member is optional and `if (fs.write)` says whether the
|
|
30
|
+
-- executor has it.
|
|
30
31
|
--
|
|
31
32
|
-- No executor implements all of this, and several names mean slightly
|
|
32
33
|
-- different things between them. Where sUNC and UNC disagree, sUNC's shape is
|
|
@@ -60,15 +61,15 @@ type TableFilter = {
|
|
|
60
61
|
|
|
61
62
|
declare env: {
|
|
62
63
|
-- The executor's own global table — shared by every script it runs.
|
|
63
|
-
getgenv
|
|
64
|
+
getgenv?: () => { [string]: unknown },
|
|
64
65
|
-- The game's global environment: the `_G` LocalScripts and ModuleScripts see.
|
|
65
|
-
getrenv
|
|
66
|
+
getrenv?: () => { [string]: unknown },
|
|
66
67
|
-- The Luau registry.
|
|
67
|
-
getreg
|
|
68
|
+
getreg?: () => { [unknown]: unknown },
|
|
68
69
|
-- Everything the garbage collector is holding. Tables are left out unless
|
|
69
70
|
-- `includeTables` is true.
|
|
70
|
-
getgc
|
|
71
|
-
filtergc
|
|
71
|
+
getgc?: (includeTables?: boolean) => (AnyFunction | { [unknown]: unknown })[],
|
|
72
|
+
filtergc?: ((kind: "function", filter: FunctionFilter, returnOne: true) => AnyFunction | nil)
|
|
72
73
|
& ((kind: "function", filter: FunctionFilter, returnOne?: false) => AnyFunction[])
|
|
73
74
|
& ((kind: "table", filter: TableFilter, returnOne: true) => { [unknown]: unknown } | nil)
|
|
74
75
|
& ((kind: "table", filter: TableFilter, returnOne?: false) => { [unknown]: unknown }[]),
|
|
@@ -82,32 +83,32 @@ declare closure: {
|
|
|
82
83
|
-- Replace what `func` does with `hook`, and give back a callable copy of
|
|
83
84
|
-- the original. The hook keeps the original's type, so a hooked function
|
|
84
85
|
-- is still called the way it was. (`hookfunction`, `replaceclosure`)
|
|
85
|
-
hook
|
|
86
|
+
hook?: <T>(func: T, hook: AnyFunction) => T,
|
|
86
87
|
-- Undo every hook on a function, back to the one it started as. Errors if
|
|
87
88
|
-- the function was never hooked. (`restorefunction`)
|
|
88
|
-
restore
|
|
89
|
+
restore?: (func: AnyFunction) => void,
|
|
89
90
|
-- A copy of `func` that is a distinct function with the same behaviour.
|
|
90
91
|
-- (`clonefunction`)
|
|
91
|
-
clone
|
|
92
|
+
clone?: <T>(func: T) => T,
|
|
92
93
|
-- Wrap a Luau function so it looks and behaves like a C closure.
|
|
93
94
|
-- (`newcclosure`)
|
|
94
|
-
newcclosure
|
|
95
|
+
newcclosure?: <T>(func: T) => T,
|
|
95
96
|
-- (`iscclosure`, `islclosure`)
|
|
96
|
-
iscclosure
|
|
97
|
-
islclosure
|
|
97
|
+
iscclosure?: (func: AnyFunction) => boolean,
|
|
98
|
+
islclosure?: (func: AnyFunction) => boolean,
|
|
98
99
|
-- Was the function made by the executor, rather than the game?
|
|
99
100
|
-- (`isexecutorclosure`, `isourclosure`, `checkclosure`)
|
|
100
|
-
isexecutorclosure
|
|
101
|
+
isexecutorclosure?: (func: AnyFunction) => boolean,
|
|
101
102
|
-- Was the caller of the current function the executor, rather than the
|
|
102
103
|
-- game? (`checkcaller`)
|
|
103
|
-
checkcaller
|
|
104
|
+
checkcaller?: () => boolean,
|
|
104
105
|
-- A hash of a function's bytecode: two functions that do the same thing
|
|
105
106
|
-- have the same hash, which is how a hook finds its target across
|
|
106
107
|
-- updates. (`getfunctionhash`)
|
|
107
|
-
hash
|
|
108
|
+
hash?: (func: AnyFunction) => string,
|
|
108
109
|
-- A function's own bytecode, as `scripts.bytecode` gives a script's.
|
|
109
110
|
-- (`getfunctionbytecode`)
|
|
110
|
-
bytecode
|
|
111
|
+
bytecode?: (func: AnyFunction) => string,
|
|
111
112
|
}
|
|
112
113
|
|
|
113
114
|
-- ============================================================
|
|
@@ -116,17 +117,17 @@ declare closure: {
|
|
|
116
117
|
|
|
117
118
|
declare metatable: {
|
|
118
119
|
-- (`getrawmetatable`, `setrawmetatable`)
|
|
119
|
-
getraw
|
|
120
|
-
setraw
|
|
120
|
+
getraw?: <T>(object: T) => { [unknown]: unknown } | nil,
|
|
121
|
+
setraw?: <T>(object: T, metatable: { [unknown]: unknown } | nil) => T,
|
|
121
122
|
-- (`isreadonly`, `setreadonly`)
|
|
122
|
-
isreadonly
|
|
123
|
-
setreadonly
|
|
123
|
+
isreadonly?: (object: unknown) => boolean,
|
|
124
|
+
setreadonly?: (object: unknown, readonly: boolean) => void,
|
|
124
125
|
-- Replace one metamethod of `object`'s metatable, returning the original.
|
|
125
126
|
-- (`hookmetamethod`)
|
|
126
|
-
hook
|
|
127
|
+
hook?: <T>(object: T, method: string, hook: AnyFunction) => AnyFunction,
|
|
127
128
|
-- Inside a `__namecall` hook: which method was called.
|
|
128
129
|
-- (`getnamecallmethod`)
|
|
129
|
-
getnamecallmethod
|
|
130
|
+
getnamecallmethod?: () => string,
|
|
130
131
|
}
|
|
131
132
|
|
|
132
133
|
-- ============================================================
|
|
@@ -135,25 +136,25 @@ declare metatable: {
|
|
|
135
136
|
|
|
136
137
|
declare scripts: {
|
|
137
138
|
-- (`getcallingscript`)
|
|
138
|
-
calling
|
|
139
|
+
calling?: () => BaseScript | nil,
|
|
139
140
|
-- (`getscripts`, `getrunningscripts`, `getloadedmodules`)
|
|
140
|
-
all
|
|
141
|
-
running
|
|
142
|
-
loadedmodules
|
|
141
|
+
all?: () => (LocalScript | ModuleScript)[],
|
|
142
|
+
running?: () => (LocalScript | ModuleScript)[],
|
|
143
|
+
loadedmodules?: (excludeCore?: boolean) => ModuleScript[],
|
|
143
144
|
-- (`getscriptfromthread`)
|
|
144
|
-
fromthread
|
|
145
|
+
fromthread?: (thread: thread) => BaseScript | nil,
|
|
145
146
|
-- A script's globals, the way the script itself sees them. (`getsenv`)
|
|
146
|
-
env
|
|
147
|
+
env?: (script: LocalScript | ModuleScript) => { [string]: unknown },
|
|
147
148
|
-- (`getscriptbytecode`, `dumpstring`)
|
|
148
|
-
bytecode
|
|
149
|
+
bytecode?: (script: LocalScript | ModuleScript) => string,
|
|
149
150
|
-- (`getscriptclosure`, `getscriptfunction`)
|
|
150
|
-
closure
|
|
151
|
+
closure?: (script: LocalScript | ModuleScript) => AnyFunction,
|
|
151
152
|
-- (`getscripthash`)
|
|
152
|
-
hash
|
|
153
|
+
hash?: (script: LocalScript | ModuleScript) => string,
|
|
153
154
|
-- A script's bytecode turned back into Luau source. What comes back is
|
|
154
155
|
-- the decompiler's reading of it — names of locals are gone — and on
|
|
155
156
|
-- failure it is a comment saying so rather than an error. (`decompile`)
|
|
156
|
-
decompile
|
|
157
|
+
decompile?: (script: LocalScript | ModuleScript | AnyFunction) => string,
|
|
157
158
|
}
|
|
158
159
|
|
|
159
160
|
-- ============================================================
|
|
@@ -162,9 +163,9 @@ declare scripts: {
|
|
|
162
163
|
|
|
163
164
|
declare identity: {
|
|
164
165
|
-- (`getthreadidentity`, `getidentity`, `getthreadcontext`)
|
|
165
|
-
get
|
|
166
|
+
get?: () => number,
|
|
166
167
|
-- (`setthreadidentity`, `setidentity`, `setthreadcontext`)
|
|
167
|
-
set
|
|
168
|
+
set?: (identity: number) => void,
|
|
168
169
|
}
|
|
169
170
|
|
|
170
171
|
-- ============================================================
|
|
@@ -175,50 +176,50 @@ declare instance: {
|
|
|
175
176
|
-- A reference to the same instance that the game's own code cannot
|
|
176
177
|
-- recognise as yours — what keeps a detection hook from seeing the
|
|
177
178
|
-- instance you hold. (`cloneref`)
|
|
178
|
-
cloneref
|
|
179
|
+
cloneref?: <T>(object: T) => T,
|
|
179
180
|
-- Two references, one instance? (`compareinstances`)
|
|
180
|
-
compare
|
|
181
|
+
compare?: (a: Instance, b: Instance) => boolean,
|
|
181
182
|
-- Every instance in the data model, and those parented to nil.
|
|
182
183
|
-- (`getinstances`, `getnilinstances`)
|
|
183
|
-
all
|
|
184
|
-
nilparented
|
|
184
|
+
all?: () => Instance[],
|
|
185
|
+
nilparented?: () => Instance[],
|
|
185
186
|
-- A hidden container for the executor's own UI, which the game cannot
|
|
186
187
|
-- see. (`gethui`)
|
|
187
|
-
gethui
|
|
188
|
+
gethui?: () => Folder,
|
|
188
189
|
-- Properties the engine hides from scripts: `Instance.Archivable`-style
|
|
189
190
|
-- flags, and anything marked not scriptable. `gethidden` answers the value
|
|
190
191
|
-- and whether it was hidden. (`gethiddenproperty`, `sethiddenproperty`,
|
|
191
192
|
-- `isscriptable`, `setscriptable`)
|
|
192
|
-
gethidden
|
|
193
|
-
sethidden
|
|
194
|
-
isscriptable
|
|
195
|
-
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,
|
|
196
197
|
-- The function assigned to a callback property (`OnServerInvoke`, ...).
|
|
197
198
|
-- (`getcallbackvalue`)
|
|
198
|
-
getcallback
|
|
199
|
+
getcallback?: (object: Instance, property: string) => AnyFunction | nil,
|
|
199
200
|
-- (`fireclickdetector`, `fireproximityprompt`)
|
|
200
|
-
fireclickdetector
|
|
201
|
-
fireproximityprompt
|
|
201
|
+
fireclickdetector?: (object: ClickDetector, distance?: number, event?: string) => void,
|
|
202
|
+
fireproximityprompt?: (prompt: ProximityPrompt) => void,
|
|
202
203
|
-- `toggle` is true (or 0) to begin the touch and false (or 1) to end it.
|
|
203
204
|
-- (`firetouchinterest`)
|
|
204
|
-
firetouch
|
|
205
|
+
firetouch?: (part: BasePart, other: BasePart, toggle: boolean | number) => void,
|
|
205
206
|
-- `game:GetObjects`, which a script may not call itself. (`getobjects`)
|
|
206
|
-
getobjects
|
|
207
|
+
getobjects?: (assetId: string) => Instance[],
|
|
207
208
|
-- Does this client simulate the part's physics? (`isnetworkowner`)
|
|
208
|
-
isnetworkowner
|
|
209
|
+
isnetworkowner?: (part: BasePart) => boolean,
|
|
209
210
|
-- Write the place, or one instance and what is under it, to a file in the
|
|
210
211
|
-- workspace folder. The options are the executor's own (`mode`,
|
|
211
212
|
-- `noscripts`, `FilePath`, ...), so they are left open. (`saveinstance`)
|
|
212
|
-
save
|
|
213
|
+
save?: (target?: Instance | { [string]: unknown }, options?: { [string]: unknown }) => void,
|
|
213
214
|
}
|
|
214
215
|
|
|
215
216
|
declare cache: {
|
|
216
217
|
-- Forget an instance, so the next reference to it is a new one.
|
|
217
|
-
invalidate
|
|
218
|
+
invalidate?: (object: Instance) => void,
|
|
218
219
|
-- Point every future reference to `object` at `newObject` instead.
|
|
219
|
-
replace
|
|
220
|
+
replace?: (object: Instance, newObject: Instance) => void,
|
|
220
221
|
-- (`cache.iscached`)
|
|
221
|
-
iscached
|
|
222
|
+
iscached?: (object: Instance) => boolean,
|
|
222
223
|
}
|
|
223
224
|
|
|
224
225
|
-- ============================================================
|
|
@@ -247,12 +248,12 @@ type AnySignal = { Connect: (self: unknown, callback: (...args: unknown[]) => vo
|
|
|
247
248
|
|
|
248
249
|
declare signal: {
|
|
249
250
|
-- (`getconnections`)
|
|
250
|
-
connections
|
|
251
|
+
connections?: (signal: AnySignal) => Connection[],
|
|
251
252
|
-- Run every Luau connection of a signal now. (`firesignal`)
|
|
252
|
-
fire
|
|
253
|
+
fire?: (signal: AnySignal, ...args: unknown[]) => void,
|
|
253
254
|
-- Send a signal to the server, for the signals that replicate.
|
|
254
255
|
-- (`replicatesignal`)
|
|
255
|
-
replicate
|
|
256
|
+
replicate?: (signal: AnySignal, ...args: unknown[]) => void,
|
|
256
257
|
}
|
|
257
258
|
|
|
258
259
|
-- ============================================================
|
|
@@ -263,24 +264,24 @@ declare signal: {
|
|
|
263
264
|
|
|
264
265
|
declare fs: {
|
|
265
266
|
-- (`readfile`, `writefile`, `appendfile`, `delfile`, `isfile`, `listfiles`)
|
|
266
|
-
read
|
|
267
|
-
write
|
|
268
|
-
append
|
|
269
|
-
delete
|
|
270
|
-
isfile
|
|
271
|
-
list
|
|
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[],
|
|
272
273
|
-- (`makefolder`, `delfolder`, `isfolder`)
|
|
273
|
-
makefolder
|
|
274
|
-
deletefolder
|
|
275
|
-
isfolder
|
|
274
|
+
makefolder?: (path: string) => void,
|
|
275
|
+
deletefolder?: (path: string) => void,
|
|
276
|
+
isfolder?: (path: string) => boolean,
|
|
276
277
|
-- Run a file. (`dofile`)
|
|
277
|
-
dofile
|
|
278
|
+
dofile?: (path: string) => void,
|
|
278
279
|
-- Compile a file without running it, as `loadstring` does a string.
|
|
279
280
|
-- (`loadfile`)
|
|
280
|
-
loadfile
|
|
281
|
+
loadfile?: (path: string, chunkname?: string) => [AnyFunction | nil, string | nil],
|
|
281
282
|
-- A `rbxasset://` id for a file on disk, usable wherever the engine takes
|
|
282
283
|
-- a content id (images, sounds, meshes). (`getcustomasset`)
|
|
283
|
-
getcustomasset
|
|
284
|
+
getcustomasset?: (path: string, noCache?: boolean) => string,
|
|
284
285
|
}
|
|
285
286
|
|
|
286
287
|
-- ============================================================
|
|
@@ -337,7 +338,7 @@ declare http: {
|
|
|
337
338
|
-- }))
|
|
338
339
|
--
|
|
339
340
|
-- (`request`, `http_request`, `http.request`, `syn.request`, `fluxus.request`)
|
|
340
|
-
request
|
|
341
|
+
request?: ((options: HttpRequest) => HttpResponse)
|
|
341
342
|
& ((build: (types: HttpTypes) => HttpBuiltRequest) => HttpResponse),
|
|
342
343
|
}
|
|
343
344
|
|
|
@@ -350,7 +351,7 @@ type WebSocketConnection = {
|
|
|
350
351
|
|
|
351
352
|
declare websocket: {
|
|
352
353
|
-- (`WebSocket.connect`)
|
|
353
|
-
connect
|
|
354
|
+
connect?: (url: string) => WebSocketConnection,
|
|
354
355
|
}
|
|
355
356
|
|
|
356
357
|
-- ============================================================
|
|
@@ -360,21 +361,21 @@ declare websocket: {
|
|
|
360
361
|
declare encoding: {
|
|
361
362
|
-- (`base64encode`, `crypt.base64encode`, `crypt.base64_encode`,
|
|
362
363
|
-- `crypt.base64.encode`, `base64.encode`, and the same for decode)
|
|
363
|
-
base64encode
|
|
364
|
-
base64decode
|
|
364
|
+
base64encode?: (data: string) => string,
|
|
365
|
+
base64decode?: (data: string) => string,
|
|
365
366
|
-- (`lz4compress`, `lz4decompress`)
|
|
366
|
-
lz4compress
|
|
367
|
-
lz4decompress
|
|
367
|
+
lz4compress?: (data: string) => string,
|
|
368
|
+
lz4decompress?: (data: string, size: number) => string,
|
|
368
369
|
}
|
|
369
370
|
|
|
370
371
|
declare crypt: {
|
|
371
372
|
-- The ciphertext and the iv it used.
|
|
372
|
-
encrypt
|
|
373
|
-
decrypt
|
|
374
|
-
hash
|
|
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,
|
|
375
376
|
-- (`crypt.generatebytes`, `crypt.generatekey`)
|
|
376
|
-
generatebytes
|
|
377
|
-
generatekey
|
|
377
|
+
generatebytes?: (size: number) => string,
|
|
378
|
+
generatekey?: () => string,
|
|
378
379
|
}
|
|
379
380
|
|
|
380
381
|
-- ============================================================
|
|
@@ -423,7 +424,7 @@ type Drawing = DrawingLine | DrawingText | DrawingImage | DrawingCircle
|
|
|
423
424
|
|
|
424
425
|
declare drawing: {
|
|
425
426
|
-- (`Drawing.new`)
|
|
426
|
-
new
|
|
427
|
+
new?: ((kind: "Line") => DrawingLine)
|
|
427
428
|
& ((kind: "Text") => DrawingText)
|
|
428
429
|
& ((kind: "Image") => DrawingImage)
|
|
429
430
|
& ((kind: "Circle") => DrawingCircle)
|
|
@@ -431,14 +432,14 @@ declare drawing: {
|
|
|
431
432
|
& ((kind: "Quad") => DrawingQuad)
|
|
432
433
|
& ((kind: "Triangle") => DrawingTriangle),
|
|
433
434
|
-- (`Drawing.Fonts`)
|
|
434
|
-
fonts
|
|
435
|
+
fonts?: { UI: number, System: number, Plex: number, Monospace: number },
|
|
435
436
|
-- Destroy every drawing at once; references to them stop working.
|
|
436
437
|
-- (`cleardrawcache`)
|
|
437
|
-
clear
|
|
438
|
+
clear?: () => void,
|
|
438
439
|
-- (`getrenderproperty`, `setrenderproperty`, `isrenderobj`)
|
|
439
|
-
getproperty
|
|
440
|
-
setproperty
|
|
441
|
-
isdrawing
|
|
440
|
+
getproperty?: (drawing: Drawing, property: string) => unknown,
|
|
441
|
+
setproperty?: (drawing: Drawing, property: string, value: unknown) => void,
|
|
442
|
+
isdrawing?: (object: unknown) => boolean,
|
|
442
443
|
}
|
|
443
444
|
|
|
444
445
|
-- ============================================================
|
|
@@ -448,12 +449,12 @@ declare drawing: {
|
|
|
448
449
|
declare rconsole: {
|
|
449
450
|
-- (`rconsolecreate` ... `rconsoleinput`, and the same without the `r`;
|
|
450
451
|
-- `rconsolename` for `settitle`)
|
|
451
|
-
create
|
|
452
|
-
destroy
|
|
453
|
-
clear
|
|
454
|
-
print
|
|
455
|
-
settitle
|
|
456
|
-
input
|
|
452
|
+
create?: () => void,
|
|
453
|
+
destroy?: () => void,
|
|
454
|
+
clear?: () => void,
|
|
455
|
+
print?: (text: string) => void,
|
|
456
|
+
settitle?: (title: string) => void,
|
|
457
|
+
input?: () => string,
|
|
457
458
|
}
|
|
458
459
|
|
|
459
460
|
-- ============================================================
|
|
@@ -465,23 +466,23 @@ declare rconsole: {
|
|
|
465
466
|
|
|
466
467
|
declare input: {
|
|
467
468
|
-- (`isrbxactive`, `isgameactive`)
|
|
468
|
-
isactive
|
|
469
|
+
isactive?: () => boolean,
|
|
469
470
|
-- (`mouse1click`, `mouse1press`, ...)
|
|
470
|
-
mouse1click
|
|
471
|
-
mouse1press
|
|
472
|
-
mouse1release
|
|
473
|
-
mouse2click
|
|
474
|
-
mouse2press
|
|
475
|
-
mouse2release
|
|
471
|
+
mouse1click?: () => void,
|
|
472
|
+
mouse1press?: () => void,
|
|
473
|
+
mouse1release?: () => void,
|
|
474
|
+
mouse2click?: () => void,
|
|
475
|
+
mouse2press?: () => void,
|
|
476
|
+
mouse2release?: () => void,
|
|
476
477
|
-- (`mousemoveabs`, `mousemoverel`, `mousescroll`)
|
|
477
|
-
mousemoveabs
|
|
478
|
-
mousemoverel
|
|
479
|
-
mousescroll
|
|
478
|
+
mousemoveabs?: (x: number, y: number) => void,
|
|
479
|
+
mousemoverel?: (x: number, y: number) => void,
|
|
480
|
+
mousescroll?: (pixels: number) => void,
|
|
480
481
|
-- Keys are Windows virtual-key codes (`0x57` is W), not `Enum.KeyCode`.
|
|
481
482
|
-- (`keypress`, `keyrelease`, `keyclick`)
|
|
482
|
-
keypress
|
|
483
|
-
keyrelease
|
|
484
|
-
keyclick
|
|
483
|
+
keypress?: (key: number) => void,
|
|
484
|
+
keyrelease?: (key: number) => void,
|
|
485
|
+
keyclick?: (key: number) => void,
|
|
485
486
|
}
|
|
486
487
|
|
|
487
488
|
-- ============================================================
|
|
@@ -526,34 +527,34 @@ declare debug: {
|
|
|
526
527
|
|
|
527
528
|
declare executor: {
|
|
528
529
|
-- The executor's name and version. (`identifyexecutor`, `getexecutorname`)
|
|
529
|
-
identify
|
|
530
|
+
identify?: () => [string, string],
|
|
530
531
|
-- An id for the machine the executor runs on. (`gethwid`)
|
|
531
|
-
hwid
|
|
532
|
+
hwid?: () => string,
|
|
532
533
|
-- (`setfpscap`, `getfpscap`)
|
|
533
|
-
setfpscap
|
|
534
|
-
getfpscap
|
|
534
|
+
setfpscap?: (fps: number) => void,
|
|
535
|
+
getfpscap?: () => number,
|
|
535
536
|
-- (`messagebox`)
|
|
536
|
-
messagebox
|
|
537
|
+
messagebox?: (text: string, caption: string, flags: number) => number,
|
|
537
538
|
}
|
|
538
539
|
|
|
539
540
|
declare clipboard: {
|
|
540
541
|
-- (`setclipboard`, `toclipboard`)
|
|
541
|
-
set
|
|
542
|
+
set?: (text: string) => void,
|
|
542
543
|
-- Roblox Studio's clipboard, of instances. (`setrbxclipboard`)
|
|
543
|
-
setrbx
|
|
544
|
+
setrbx?: (data: string) => boolean,
|
|
544
545
|
}
|
|
545
546
|
|
|
546
547
|
declare teleport: {
|
|
547
548
|
-- Source to run after the next teleport, in the new place.
|
|
548
549
|
-- (`queue_on_teleport`, `queueonteleport`, `queueteleport`)
|
|
549
|
-
queue
|
|
550
|
+
queue?: (code: string) => void,
|
|
550
551
|
}
|
|
551
552
|
|
|
552
553
|
-- Parallel Luau: the actors of the game, and code run inside one — each actor
|
|
553
554
|
-- is a Luau state of its own, which a script outside cannot reach.
|
|
554
555
|
declare actor: {
|
|
555
556
|
-- (`getactors`, `run_on_actor`, `isparallel`)
|
|
556
|
-
all
|
|
557
|
-
run
|
|
558
|
-
isparallel
|
|
557
|
+
all?: () => Actor[],
|
|
558
|
+
run?: (actor: Actor, code: string, ...args: unknown[]) => void,
|
|
559
|
+
isparallel?: () => boolean,
|
|
559
560
|
}
|
package/lowering.mjs
CHANGED
|
@@ -10,6 +10,9 @@
|
|
|
10
10
|
* fs.read("a.txt") -> tilua_sunc.fs.read("a.txt")
|
|
11
11
|
* const files = fs -> local files = tilua_sunc.fs
|
|
12
12
|
*
|
|
13
|
+
* A function the executor has under none of its spellings is `nil` in its
|
|
14
|
+
* namespace, as it would be in a script looking for it by hand.
|
|
15
|
+
*
|
|
13
16
|
* The runtime's functions also answer several Luau values as tilua has them
|
|
14
17
|
* (`executor.identify()` is one array), and `http.request(types => ...)` builds
|
|
15
18
|
* a body that holds what a Luau table cannot.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tilua-types/sunc",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "10.0.0",
|
|
4
4
|
"description": "The script-executor environment as tilua types: sUNC and UNC names (getgenv, writefile, hookfunction, Drawing, ...)",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"files": [
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"lowering": "lowering.mjs"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@tilua-types/roblox": "^
|
|
17
|
+
"@tilua-types/roblox": "^9.0.0"
|
|
18
18
|
},
|
|
19
19
|
"keywords": [
|
|
20
20
|
"tilua",
|
package/runtime/sunc.luau
CHANGED
|
@@ -1,278 +1,277 @@
|
|
|
1
|
-
local __NAME__ = {}
|
|
2
|
-
|
|
3
|
-
-- The namespaces of index.d.tilua — `env`, `file`, `closure`, ... — built from
|
|
4
|
-
-- whatever the executor has. The compiler reads each namespace from here: none
|
|
5
|
-
-- of them is the executor's own global, and most executors have none of them.
|
|
6
|
-
--
|
|
7
|
-
-- Each function is looked up once, as the script starts, under every spelling
|
|
8
|
-
-- executors use for it; the first one there is the one called. With none of
|
|
9
|
-
-- them
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
--
|
|
45
|
-
--
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
--
|
|
228
|
-
--
|
|
229
|
-
--
|
|
230
|
-
--
|
|
231
|
-
--
|
|
232
|
-
--
|
|
233
|
-
-- `
|
|
234
|
-
--
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
copy
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
}
|
|
1
|
+
local __NAME__ = {}
|
|
2
|
+
|
|
3
|
+
-- The namespaces of index.d.tilua — `env`, `file`, `closure`, ... — built from
|
|
4
|
+
-- whatever the executor has. The compiler reads each namespace from here: none
|
|
5
|
+
-- of them is the executor's own global, and most executors have none of them.
|
|
6
|
+
--
|
|
7
|
+
-- Each function is looked up once, as the script starts, under every spelling
|
|
8
|
+
-- executors use for it; the first one there is the one called. With none of
|
|
9
|
+
-- them it is nil — and a name that is there but is not a function (a table, a
|
|
10
|
+
-- stub value) counts as not there. The namespace holds no function the executor
|
|
11
|
+
-- does not have, so `if (fs.write)` says whether it does.
|
|
12
|
+
|
|
13
|
+
local function pick(...)
|
|
14
|
+
for i = 1, select("#", ...) do
|
|
15
|
+
local found = select(i, ...)
|
|
16
|
+
if type(found) == "function" then
|
|
17
|
+
return found
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
return nil
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
-- `t[key]`, where `t` may not be a table at all — `syn.request` in an
|
|
24
|
+
-- executor with no `syn`.
|
|
25
|
+
local function field(t, key)
|
|
26
|
+
if type(t) == "table" then
|
|
27
|
+
return t[key]
|
|
28
|
+
end
|
|
29
|
+
return nil
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
-- A function whose Luau answer is several values, answering them as tilua
|
|
33
|
+
-- has them: one array.
|
|
34
|
+
local function gathered(f)
|
|
35
|
+
if f == nil then
|
|
36
|
+
return nil
|
|
37
|
+
end
|
|
38
|
+
return function(...)
|
|
39
|
+
return { f(...) }
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
-- ============================================================
|
|
44
|
+
-- Namespaces
|
|
45
|
+
-- ============================================================
|
|
46
|
+
|
|
47
|
+
__NAME__.env = {
|
|
48
|
+
getgenv = pick(getgenv),
|
|
49
|
+
getrenv = pick(getrenv),
|
|
50
|
+
getreg = pick(getreg),
|
|
51
|
+
getgc = pick(getgc),
|
|
52
|
+
filtergc = pick(filtergc),
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
__NAME__.closure = {
|
|
56
|
+
hook = pick(hookfunction, replaceclosure),
|
|
57
|
+
restore = pick(restorefunction),
|
|
58
|
+
clone = pick(clonefunction),
|
|
59
|
+
newcclosure = pick(newcclosure),
|
|
60
|
+
iscclosure = pick(iscclosure),
|
|
61
|
+
islclosure = pick(islclosure),
|
|
62
|
+
isexecutorclosure = pick(isexecutorclosure, isourclosure, checkclosure),
|
|
63
|
+
checkcaller = pick(checkcaller),
|
|
64
|
+
hash = pick(getfunctionhash),
|
|
65
|
+
bytecode = pick(getfunctionbytecode),
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
__NAME__.metatable = {
|
|
69
|
+
getraw = pick(getrawmetatable),
|
|
70
|
+
setraw = pick(setrawmetatable),
|
|
71
|
+
isreadonly = pick(isreadonly),
|
|
72
|
+
setreadonly = pick(setreadonly),
|
|
73
|
+
hook = pick(hookmetamethod),
|
|
74
|
+
getnamecallmethod = pick(getnamecallmethod),
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
__NAME__.scripts = {
|
|
78
|
+
calling = pick(getcallingscript),
|
|
79
|
+
all = pick(getscripts),
|
|
80
|
+
running = pick(getrunningscripts),
|
|
81
|
+
loadedmodules = pick(getloadedmodules),
|
|
82
|
+
fromthread = pick(getscriptfromthread),
|
|
83
|
+
env = pick(getsenv),
|
|
84
|
+
bytecode = pick(getscriptbytecode, dumpstring),
|
|
85
|
+
closure = pick(getscriptclosure, getscriptfunction),
|
|
86
|
+
hash = pick(getscripthash),
|
|
87
|
+
decompile = pick(decompile),
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
__NAME__.identity = {
|
|
91
|
+
get = pick(getthreadidentity, getidentity, getthreadcontext),
|
|
92
|
+
set = pick(setthreadidentity, setidentity, setthreadcontext),
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
local gethidden = pick(gethiddenproperty)
|
|
96
|
+
|
|
97
|
+
__NAME__.instance = {
|
|
98
|
+
cloneref = pick(cloneref),
|
|
99
|
+
compare = pick(compareinstances),
|
|
100
|
+
all = pick(getinstances),
|
|
101
|
+
nilparented = pick(getnilinstances),
|
|
102
|
+
gethui = pick(gethui),
|
|
103
|
+
gethidden = gathered(gethidden),
|
|
104
|
+
sethidden = pick(sethiddenproperty),
|
|
105
|
+
isscriptable = pick(isscriptable),
|
|
106
|
+
setscriptable = pick(setscriptable),
|
|
107
|
+
getcallback = pick(getcallbackvalue),
|
|
108
|
+
fireclickdetector = pick(fireclickdetector),
|
|
109
|
+
fireproximityprompt = pick(fireproximityprompt),
|
|
110
|
+
firetouch = pick(firetouchinterest),
|
|
111
|
+
getobjects = pick(getobjects),
|
|
112
|
+
isnetworkowner = pick(isnetworkowner),
|
|
113
|
+
save = pick(saveinstance),
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
__NAME__.cache = {
|
|
117
|
+
invalidate = pick(field(cache, "invalidate")),
|
|
118
|
+
replace = pick(field(cache, "replace")),
|
|
119
|
+
iscached = pick(field(cache, "iscached")),
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
__NAME__.signal = {
|
|
123
|
+
connections = pick(getconnections),
|
|
124
|
+
fire = pick(firesignal),
|
|
125
|
+
replicate = pick(replicatesignal),
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
local loadfileOf = pick(loadfile)
|
|
129
|
+
|
|
130
|
+
__NAME__.fs = {
|
|
131
|
+
read = pick(readfile),
|
|
132
|
+
write = pick(writefile),
|
|
133
|
+
append = pick(appendfile),
|
|
134
|
+
delete = pick(delfile),
|
|
135
|
+
isfile = pick(isfile),
|
|
136
|
+
list = pick(listfiles),
|
|
137
|
+
makefolder = pick(makefolder),
|
|
138
|
+
deletefolder = pick(delfolder),
|
|
139
|
+
isfolder = pick(isfolder),
|
|
140
|
+
dofile = pick(dofile),
|
|
141
|
+
loadfile = loadfileOf and function(path, chunkname)
|
|
142
|
+
local f, message = loadfileOf(path, chunkname)
|
|
143
|
+
return { f, message }
|
|
144
|
+
end or nil,
|
|
145
|
+
getcustomasset = pick(getcustomasset),
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
__NAME__.websocket = {
|
|
149
|
+
connect = pick(field(WebSocket, "connect"), field(WebSocket, "Connect")),
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
__NAME__.encoding = {
|
|
153
|
+
base64encode = pick(base64encode, field(crypt, "base64encode"), field(crypt, "base64_encode"),
|
|
154
|
+
field(field(crypt, "base64"), "encode"), field(base64, "encode"), base64_encode),
|
|
155
|
+
base64decode = pick(base64decode, field(crypt, "base64decode"), field(crypt, "base64_decode"),
|
|
156
|
+
field(field(crypt, "base64"), "decode"), field(base64, "decode"), base64_decode),
|
|
157
|
+
lz4compress = pick(lz4compress),
|
|
158
|
+
lz4decompress = pick(lz4decompress),
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
__NAME__.crypt = {
|
|
162
|
+
encrypt = gathered(pick(field(crypt, "encrypt"))),
|
|
163
|
+
decrypt = pick(field(crypt, "decrypt")),
|
|
164
|
+
hash = pick(field(crypt, "hash")),
|
|
165
|
+
generatebytes = pick(field(crypt, "generatebytes")),
|
|
166
|
+
generatekey = pick(field(crypt, "generatekey")),
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
__NAME__.drawing = {
|
|
170
|
+
new = pick(field(Drawing, "new")),
|
|
171
|
+
fonts = field(Drawing, "Fonts"),
|
|
172
|
+
clear = pick(cleardrawcache),
|
|
173
|
+
getproperty = pick(getrenderproperty),
|
|
174
|
+
setproperty = pick(setrenderproperty),
|
|
175
|
+
isdrawing = pick(isrenderobj),
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
__NAME__.rconsole = {
|
|
179
|
+
create = pick(rconsolecreate, consolecreate),
|
|
180
|
+
destroy = pick(rconsoledestroy, consoledestroy),
|
|
181
|
+
clear = pick(rconsoleclear, consoleclear),
|
|
182
|
+
print = pick(rconsoleprint, consoleprint),
|
|
183
|
+
settitle = pick(rconsolesettitle, rconsolename, consolesettitle),
|
|
184
|
+
input = pick(rconsoleinput, consoleinput),
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
__NAME__.input = {
|
|
188
|
+
isactive = pick(isrbxactive, isgameactive),
|
|
189
|
+
mouse1click = pick(mouse1click),
|
|
190
|
+
mouse1press = pick(mouse1press),
|
|
191
|
+
mouse1release = pick(mouse1release),
|
|
192
|
+
mouse2click = pick(mouse2click),
|
|
193
|
+
mouse2press = pick(mouse2press),
|
|
194
|
+
mouse2release = pick(mouse2release),
|
|
195
|
+
mousemoveabs = pick(mousemoveabs),
|
|
196
|
+
mousemoverel = pick(mousemoverel),
|
|
197
|
+
mousescroll = pick(mousescroll),
|
|
198
|
+
keypress = pick(keypress),
|
|
199
|
+
keyrelease = pick(keyrelease),
|
|
200
|
+
keyclick = pick(keyclick),
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
__NAME__.executor = {
|
|
204
|
+
identify = gathered(pick(identifyexecutor, getexecutorname)),
|
|
205
|
+
hwid = pick(gethwid),
|
|
206
|
+
setfpscap = pick(setfpscap),
|
|
207
|
+
getfpscap = pick(getfpscap),
|
|
208
|
+
messagebox = pick(messagebox),
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
__NAME__.clipboard = {
|
|
212
|
+
set = pick(setclipboard, toclipboard),
|
|
213
|
+
setrbx = pick(setrbxclipboard),
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
__NAME__.teleport = {
|
|
217
|
+
queue = pick(queue_on_teleport, queueonteleport, queueteleport, field(syn, "queue_on_teleport")),
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
__NAME__.actor = {
|
|
221
|
+
all = pick(getactors),
|
|
222
|
+
run = pick(run_on_actor),
|
|
223
|
+
isparallel = pick(isparallel),
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
-- ============================================================
|
|
227
|
+
-- http.request(types => ...)
|
|
228
|
+
-- ============================================================
|
|
229
|
+
--
|
|
230
|
+
-- What a request body can hold that a Luau table cannot: a key whose value
|
|
231
|
+
-- is nil. A body built by a function may hold `types.null` and
|
|
232
|
+
-- `types.undefined` for it, and a body that is a table is sent as JSON —
|
|
233
|
+
-- the language's (`__JSON__`), which writes them as what they say, and
|
|
234
|
+
-- `[]` and `{}` as what they are.
|
|
235
|
+
|
|
236
|
+
local send = pick(request, http_request, field(http, "request"), field(syn, "request"), field(fluxus, "request"))
|
|
237
|
+
|
|
238
|
+
local types = { null = __JSON__.null, undefined = __JSON__.undefined }
|
|
239
|
+
|
|
240
|
+
local function hasHeader(headers, name)
|
|
241
|
+
for key in pairs(headers) do
|
|
242
|
+
if type(key) == "string" and key:lower() == name then
|
|
243
|
+
return true
|
|
244
|
+
end
|
|
245
|
+
end
|
|
246
|
+
return false
|
|
247
|
+
end
|
|
248
|
+
|
|
249
|
+
-- The request a function built, as the executor's `request` takes it.
|
|
250
|
+
local function built(options)
|
|
251
|
+
if options.Body == nil or type(options.Body) == "string" then
|
|
252
|
+
return options
|
|
253
|
+
end
|
|
254
|
+
local copy = {}
|
|
255
|
+
for key, value in pairs(options) do
|
|
256
|
+
copy[key] = value
|
|
257
|
+
end
|
|
258
|
+
copy.Body = __JSON__.encode(options.Body)
|
|
259
|
+
local headers = {}
|
|
260
|
+
for key, value in pairs(options.Headers or {}) do
|
|
261
|
+
headers[key] = value
|
|
262
|
+
end
|
|
263
|
+
if not hasHeader(headers, "content-type") then
|
|
264
|
+
headers["Content-Type"] = "application/json"
|
|
265
|
+
end
|
|
266
|
+
copy.Headers = headers
|
|
267
|
+
return copy
|
|
268
|
+
end
|
|
269
|
+
|
|
270
|
+
__NAME__.http = {
|
|
271
|
+
request = send and function(options)
|
|
272
|
+
if type(options) == "function" then
|
|
273
|
+
return send(built(options(types)))
|
|
274
|
+
end
|
|
275
|
+
return send(options)
|
|
276
|
+
end or nil,
|
|
277
|
+
}
|