@tilua-types/sunc 7.0.1 → 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/README.md CHANGED
@@ -1,14 +1,14 @@
1
1
  # @tilua-types/sunc
2
2
 
3
- The script-executor environment as tilua types — the functions an executor
4
- injects into a script's globals: `getgenv`, `writefile`, `hookfunction`,
5
- `getconnections`, `Drawing`, `request` and the rest.
3
+ The script-executor environment as tilua types — what an executor injects
4
+ into a script: `getgenv`, `writefile`, `hookfunction`, `getconnections`,
5
+ `Drawing`, `request` and the rest, each in a namespace by what it does.
6
6
 
7
7
  Names and shapes follow [sUNC](https://docs.sunc.io) (senS' Unified Naming
8
8
  Convention) and the [UNC standard](https://github.com/unified-naming-convention/NamingStandard)
9
9
  it grew out of. Where the two disagree, sUNC's shape is the one written down;
10
- where only UNC has a name (`crypt`, the `rconsole` family, mouse input), it is
11
- kept, since executors still expose it.
10
+ where only UNC has a name (`crypt`, `rconsole`, mouse input), it is kept,
11
+ since executors still expose it.
12
12
 
13
13
  Depends on [`@tilua-types/roblox`](../roblox), which is loaded along with it:
14
14
  nearly every one of these takes or returns an engine type.
@@ -21,19 +21,88 @@ npm i -D @tilua-types/sunc
21
21
  { "types": ["sunc"], "paths": {}, "sourceMap": null }
22
22
  ```
23
23
 
24
+ ## Namespaces
25
+
26
+ No function is a global of its own. Each is in a namespace, a name the
27
+ namespace already says is not said again, and every name is lowercase, as
28
+ sUNC's are:
29
+
30
+ ```luau
31
+ const genv = env.getgenv()
32
+ fs.write("log.txt", fs.read("in.txt"))
33
+ const original = closure.hook(target, (...args) => print("called"))
34
+ http.request({ Url: url })
35
+ ```
36
+
37
+ The namespaces are not the executor's — no executor has `fs` or `closure`.
38
+ The compiler reads each from the library's runtime, which builds it as the
39
+ script starts from whatever the executor has, under whichever spelling it
40
+ has. A function the executor has under none of them raises "fs.read is not
41
+ available in this executor" when called.
42
+
43
+ | Namespace | Functions (what the executor calls them) |
44
+ | --- | --- |
45
+ | `env` | `getgenv`, `getrenv`, `getreg`, `getgc`, `filtergc` |
46
+ | `closure` | `hook` (`hookfunction`, `replaceclosure`), `restore` (`restorefunction`), `clone` (`clonefunction`), `newcclosure`, `iscclosure`, `islclosure`, `isexecutorclosure` (`isourclosure`, `checkclosure`), `checkcaller`, `hash` (`getfunctionhash`), `bytecode` (`getfunctionbytecode`) |
47
+ | `metatable` | `getraw` / `setraw` (`getrawmetatable` / `setrawmetatable`), `isreadonly`, `setreadonly`, `hook` (`hookmetamethod`), `getnamecallmethod` |
48
+ | `scripts` | `calling` (`getcallingscript`), `all` (`getscripts`), `running` (`getrunningscripts`), `loadedmodules`, `fromthread` (`getscriptfromthread`), `env` (`getsenv`), `bytecode` (`getscriptbytecode`, `dumpstring`), `closure` (`getscriptclosure`, `getscriptfunction`), `hash` (`getscripthash`), `decompile` |
49
+ | `identity` | `get` / `set` (`getthreadidentity`, `getidentity`, `getthreadcontext`, and the setters) |
50
+ | `instance` | `cloneref`, `compare` (`compareinstances`), `all` (`getinstances`), `nilparented` (`getnilinstances`), `gethui`, `gethidden` / `sethidden` (`gethiddenproperty` / `sethiddenproperty`), `isscriptable`, `setscriptable`, `getcallback` (`getcallbackvalue`), `fireclickdetector`, `fireproximityprompt`, `firetouch` (`firetouchinterest`), `getobjects`, `isnetworkowner`, `save` (`saveinstance`) |
51
+ | `cache` | `invalidate`, `replace`, `iscached` |
52
+ | `signal` | `connections` (`getconnections`), `fire` (`firesignal`), `replicate` (`replicatesignal`) |
53
+ | `fs` | `read`, `write`, `append`, `delete` (`delfile`), `isfile`, `list` (`listfiles`), `makefolder`, `deletefolder` (`delfolder`), `isfolder`, `dofile`, `loadfile`, `getcustomasset` |
54
+ | `http` | `request` (`request`, `http_request`, `http.request`, `syn.request`, `fluxus.request`) |
55
+ | `websocket` | `connect` (`WebSocket.connect`) |
56
+ | `encoding` | `base64encode` / `base64decode` (also `crypt.base64encode`, `crypt.base64_encode`, `crypt.base64.encode`, `base64.encode`), `lz4compress`, `lz4decompress` |
57
+ | `crypt` | `encrypt`, `decrypt`, `hash`, `generatebytes`, `generatekey` |
58
+ | `drawing` | `new` (`Drawing.new`), `fonts` (`Drawing.Fonts`), `clear` (`cleardrawcache`), `getproperty` / `setproperty` (`getrenderproperty` / `setrenderproperty`), `isdrawing` (`isrenderobj`) |
59
+ | `rconsole` | `create`, `destroy`, `clear`, `print`, `settitle`, `input` (`rconsole…`, `console…`, `rconsolename`) |
60
+ | `input` | `isactive` (`isrbxactive`, `isgameactive`), `mouse1click` … `mousescroll`, `keypress`, `keyrelease`, `keyclick` |
61
+ | `executor` | `identify` (`identifyexecutor`, `getexecutorname`), `hwid` (`gethwid`), `setfpscap`, `getfpscap`, `messagebox` |
62
+ | `clipboard` | `set` (`setclipboard`, `toclipboard`), `setrbx` (`setrbxclipboard`) |
63
+ | `teleport` | `queue` (`queue_on_teleport`, `queueonteleport`, `queueteleport`, `syn.queue_on_teleport`) |
64
+ | `actor` | `all` (`getactors`), `run` (`run_on_actor`), `isparallel` |
65
+
66
+ The executor's own globals are out of a script's reach: `readfile` or
67
+ `getrawmetatable` written in a script is reported, and is `nil` there, as if
68
+ the script began with `local readfile = nil`. The executor's environment is
69
+ not touched — other scripts share it — so `env.getgenv().readfile` is still
70
+ there for whoever means it.
71
+
72
+ `debug` is the one exception: it is Lua's own global already, and the
73
+ library adds `getconstants`, `getupvalues`, `getprotos` and the rest to it.
74
+
24
75
  ## What you get
25
76
 
26
- - **The globals, typed.** `readfile` gives a `string`, `listfiles` a
27
- `string[]`, `getgenv()` a `{ [string]: unknown }` you can write to.
28
- - **`Drawing.new` knows its shapes.** The argument picks the type:
29
- `Drawing.new("Circle").Radius` is a number, `Drawing.new("Line").From` is a
77
+ - **Typed.** `fs.read` gives a `string`, `fs.list` a `string[]`,
78
+ `env.getgenv()` a `{ [string]: unknown }` you can write to.
79
+ - **`drawing.new` knows its shapes.** The argument picks the type:
80
+ `drawing.new("Circle").Radius` is a number, `drawing.new("Line").From` is a
30
81
  `Vector2`, and asking a line for its radius is an error.
31
- - **Hooks keep the type they replace.** `hookfunction(f, hook)` returns `f`'s
82
+ - **Hooks keep the type they replace.** `closure.hook(f, hook)` returns `f`'s
32
83
  own type, so the saved original is still called the way `f` was.
33
- - **`debug` adds to Lua's.** `debug.getconstants` and `debug.traceback` are
34
- both there: a library that declares a name again extends it.
35
- - **Signals.** `getconnections(part.Touched)` gives `Connection[]`, each with
36
- `Function`, `Thread`, `Fire`, `Disconnect` and the rest.
84
+ - **One value.** What Luau answers as several values is one array:
85
+ `const [name, version] = executor.identify()`.
86
+ - **Signals.** `signal.connections(part.Touched)` gives `Connection[]`, each
87
+ with `Function`, `Thread`, `Fire`, `Disconnect` and the rest.
88
+ - **Bodies Luau cannot write.** A Luau table has no key whose value is nil.
89
+ Given a function, `http.request` hands it placeholders for one, and writes
90
+ them out as the request goes:
91
+
92
+ ```luau
93
+ http.request(types => ({
94
+ Url: url,
95
+ Method: "POST",
96
+ -- {"meta":{},"name":"x","tags":[],"team":null}
97
+ Body: { name: "x", team: types.null, gone: types.undefined, tags: [], meta: {} },
98
+ }))
99
+ ```
100
+
101
+ `types.null` is JSON's `null`; `types.undefined` is left out of an object
102
+ and `null` in an array, as JavaScript's. A `Body` that is a table is sent
103
+ as JSON — `[]` an array and `{}` an object, as `HttpService:JSONEncode`
104
+ writes them under tilua — with `Content-Type: application/json` unless the
105
+ headers name one; a string is sent as it is.
37
106
 
38
107
  ## Caveats
39
108