@silverbulletmd/silverbullet 2.9.0 → 2.10.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 +36 -23
- package/client/plugos/hooks/syscall.ts +24 -10
- package/client/plugos/syscalls/asset.ts +61 -23
- package/client/plugos/syscalls/clientStore.ts +32 -6
- package/client/plugos/syscalls/client_code_widget.ts +9 -4
- package/client/plugos/syscalls/code_widget.ts +26 -11
- package/client/plugos/syscalls/config.ts +146 -30
- package/client/plugos/syscalls/datastore.ts +146 -40
- package/client/plugos/syscalls/editor.ts +1432 -711
- package/client/plugos/syscalls/event.ts +46 -13
- package/client/plugos/syscalls/fetch.ts +123 -82
- package/client/plugos/syscalls/index.ts +242 -116
- package/client/plugos/syscalls/jsonschema.ts +107 -8
- package/client/plugos/syscalls/language.ts +38 -12
- package/client/plugos/syscalls/markdown.ts +166 -50
- package/client/plugos/syscalls/mq.ts +93 -20
- package/client/plugos/syscalls/schema_introspection.ts +33 -0
- package/client/plugos/syscalls/service_registry.ts +74 -20
- package/client/plugos/syscalls/shell.ts +51 -20
- package/client/plugos/syscalls/space.ts +169 -113
- package/client/plugos/syscalls/sync.ts +50 -19
- package/client/plugos/syscalls/system.ts +236 -139
- package/client/plugos/system.ts +21 -5
- package/client/space_lua/api_documentation.ts +107 -0
- package/client/space_lua/ast.ts +13 -0
- package/client/space_lua/eval.ts +12 -4
- package/client/space_lua/parse.ts +243 -108
- package/client/space_lua/pretty_print.ts +128 -54
- package/client/space_lua/query_collection.ts +4 -4
- package/client/space_lua/render_widget.ts +156 -0
- package/client/space_lua/runtime.ts +83 -22
- package/client/space_lua/stdlib/crypto.ts +8 -3
- package/client/space_lua/stdlib/encoding.ts +27 -9
- package/client/space_lua/stdlib/js.ts +137 -22
- package/client/space_lua/stdlib/load.ts +24 -15
- package/client/space_lua/stdlib/math.ts +323 -118
- package/client/space_lua/stdlib/net.ts +57 -9
- package/client/space_lua/stdlib/os.ts +111 -44
- package/client/space_lua/stdlib/space_lua.ts +344 -20
- package/client/space_lua/stdlib/string.ts +282 -104
- package/client/space_lua/stdlib/string_pack.ts +58 -19
- package/client/space_lua/stdlib/table.ts +195 -40
- package/client/space_lua/stdlib.ts +335 -93
- package/client/space_lua/syscalls.ts +270 -0
- package/dist/plug-compile.js +1 -1
- package/package.json +3 -3
- package/plug-api/lib/ref.ts +96 -0
- package/plug-api/lib/shortcut.ts +2 -1
- package/plug-api/syscalls/config.ts +5 -3
- package/plug-api/syscalls/editor.ts +16 -0
- package/plug-api/syscalls/index.ts +17 -1
- package/plug-api/syscalls/jsonschema.ts +9 -0
- package/plug-api/syscalls/lua.ts +7 -0
- package/plug-api/syscalls/shell.ts +0 -1
- package/plug-api/syscalls/system.ts +7 -0
- package/plug-api/system_mock.ts +2 -2
- package/plug-api/types/index.ts +52 -1
- package/plug-api/types/manifest.ts +22 -4
- package/plug-api/ui/cx.ts +1 -3
- package/plug-api/ui/index.ts +3 -0
- package/plug-api/ui/panel_styles.ts +4 -3
- package/plug-api/ui/slugify.ts +44 -0
- package/client/plugos/syscalls/lua.ts +0 -81
|
@@ -23,26 +23,32 @@ export const mathApi = new LuaTable({
|
|
|
23
23
|
pi: Math.PI,
|
|
24
24
|
|
|
25
25
|
// math.type(x) => "integer" | "float" | nil
|
|
26
|
-
type: new LuaBuiltinFunction(
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
if (typeof x === "number") {
|
|
37
|
-
if (!Number.isFinite(x) || isNegativeZero(x)) {
|
|
26
|
+
type: new LuaBuiltinFunction({
|
|
27
|
+
callback: (_sf, x?: any) => {
|
|
28
|
+
if (x === undefined) {
|
|
29
|
+
throw new LuaRuntimeError(
|
|
30
|
+
"bad argument #1 to 'math.type' (value expected)",
|
|
31
|
+
_sf,
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
if (isTaggedFloat(x)) {
|
|
38
35
|
return "float";
|
|
39
36
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
37
|
+
if (typeof x === "number") {
|
|
38
|
+
if (!Number.isFinite(x) || isNegativeZero(x)) {
|
|
39
|
+
return "float";
|
|
40
|
+
}
|
|
41
|
+
return Number.isInteger(x) ? "integer" : "float";
|
|
42
|
+
}
|
|
43
|
+
if (typeof x === "bigint") {
|
|
44
|
+
return "integer";
|
|
45
|
+
}
|
|
46
|
+
return null;
|
|
47
|
+
},
|
|
48
|
+
description:
|
|
49
|
+
"Returns `integer` or `float` for a number, or `nil` for other values.",
|
|
50
|
+
parameters: [{ name: "x", description: "Value to inspect." }],
|
|
51
|
+
returns: [{ type: "string|nil", description: "Numeric subtype or `nil`." }],
|
|
46
52
|
}),
|
|
47
53
|
|
|
48
54
|
/**
|
|
@@ -50,21 +56,29 @@ export const mathApi = new LuaTable({
|
|
|
50
56
|
* with that value. Otherwise returns nil.
|
|
51
57
|
* Strings are NOT accepted — only Lua number values.
|
|
52
58
|
*/
|
|
53
|
-
tointeger: new LuaBuiltinFunction(
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
59
|
+
tointeger: new LuaBuiltinFunction({
|
|
60
|
+
callback: (_sf, x?: any) => {
|
|
61
|
+
if (typeof x === "number") {
|
|
62
|
+
return Number.isInteger(x) && Number.isFinite(x) ? x : null;
|
|
63
|
+
}
|
|
64
|
+
if (isTaggedFloat(x)) {
|
|
65
|
+
const n = x.value;
|
|
66
|
+
return Number.isInteger(n) && Number.isFinite(n) ? n : null;
|
|
67
|
+
}
|
|
68
|
+
if (typeof x === "string") {
|
|
69
|
+
const n = untagNumber(x); // Number(x) coerces the string
|
|
70
|
+
if (Number.isNaN(n) || !Number.isFinite(n) || !Number.isInteger(n))
|
|
71
|
+
return null;
|
|
72
|
+
return n;
|
|
73
|
+
}
|
|
74
|
+
return null;
|
|
75
|
+
},
|
|
76
|
+
description:
|
|
77
|
+
"Converts a value to an integer when it has an exact finite integral representation.",
|
|
78
|
+
parameters: [{ name: "x", description: "Value to convert." }],
|
|
79
|
+
returns: [
|
|
80
|
+
{ type: "integer|nil", description: "Converted integer or `nil`." },
|
|
81
|
+
],
|
|
68
82
|
}),
|
|
69
83
|
|
|
70
84
|
/**
|
|
@@ -76,122 +90,305 @@ export const mathApi = new LuaTable({
|
|
|
76
90
|
* math.random(1,n). The call math.random(0) produces an integer
|
|
77
91
|
* with all bits (pseudo)random.
|
|
78
92
|
*/
|
|
79
|
-
random: new LuaBuiltinFunction(
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
93
|
+
random: new LuaBuiltinFunction({
|
|
94
|
+
callback: (_sf, m?: number, n?: number) => {
|
|
95
|
+
if (m !== undefined) m = untagNumber(m);
|
|
96
|
+
if (n !== undefined) n = untagNumber(n);
|
|
97
|
+
try {
|
|
98
|
+
return prng.random(m, n);
|
|
99
|
+
} catch (e: any) {
|
|
100
|
+
throw new LuaRuntimeError(e.message, _sf);
|
|
101
|
+
}
|
|
102
|
+
},
|
|
103
|
+
description:
|
|
104
|
+
"Returns a pseudo-random float or an integer in a requested inclusive range.",
|
|
105
|
+
signatures: [
|
|
106
|
+
"math.random(): number",
|
|
107
|
+
"math.random(n): integer",
|
|
108
|
+
"math.random(m, n): integer",
|
|
109
|
+
],
|
|
110
|
+
parameters: [
|
|
111
|
+
{ name: "m", type: "integer", optional: true },
|
|
112
|
+
{ name: "n", type: "integer", optional: true },
|
|
113
|
+
],
|
|
114
|
+
returns: [{ type: "number", description: "Pseudo-random result." }],
|
|
115
|
+
examples: [
|
|
116
|
+
{
|
|
117
|
+
code: "print(math.random())\nprint(math.random(10))\nprint(math.random(5, 10))",
|
|
118
|
+
},
|
|
119
|
+
],
|
|
87
120
|
}),
|
|
88
121
|
/**
|
|
89
122
|
* Seeds the pseudo-random generator. With no arguments, uses a
|
|
90
123
|
* time-based seed. Returns the two seed integers used (Lua 5.4 contract).
|
|
91
124
|
*/
|
|
92
|
-
randomseed: new LuaBuiltinFunction(
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
125
|
+
randomseed: new LuaBuiltinFunction({
|
|
126
|
+
callback: (_sf, x?: number, y?: number) => {
|
|
127
|
+
if (x !== undefined) x = untagNumber(x);
|
|
128
|
+
if (y !== undefined) y = untagNumber(y);
|
|
129
|
+
const [s1, s2] = prng.randomseed(x, y);
|
|
130
|
+
return new LuaMultiRes([s1, s2]);
|
|
131
|
+
},
|
|
132
|
+
description:
|
|
133
|
+
"Seeds the pseudo-random generator and returns the two seeds used.",
|
|
134
|
+
signatures: [
|
|
135
|
+
"math.randomseed(): integer, integer",
|
|
136
|
+
"math.randomseed(x, y): integer, integer",
|
|
137
|
+
],
|
|
138
|
+
parameters: [
|
|
139
|
+
{ name: "x", type: "integer", optional: true },
|
|
140
|
+
{ name: "y", type: "integer", optional: true },
|
|
141
|
+
],
|
|
142
|
+
returns: [
|
|
143
|
+
{ type: "integer", description: "First seed." },
|
|
144
|
+
{ type: "integer", description: "Second seed." },
|
|
145
|
+
],
|
|
97
146
|
}),
|
|
98
147
|
|
|
99
148
|
// Basic functions
|
|
100
|
-
abs: new LuaBuiltinFunction(
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
),
|
|
106
|
-
|
|
107
|
-
Math.
|
|
108
|
-
|
|
149
|
+
abs: new LuaBuiltinFunction({
|
|
150
|
+
callback: (_sf, x: number) => Math.abs(untagNumber(x)),
|
|
151
|
+
description: "Returns the absolute value of `x`.",
|
|
152
|
+
parameters: [{ name: "x", type: "number" }],
|
|
153
|
+
returns: [{ type: "number" }],
|
|
154
|
+
}),
|
|
155
|
+
ceil: new LuaBuiltinFunction({
|
|
156
|
+
callback: (_sf, x: number) => Math.ceil(untagNumber(x)),
|
|
157
|
+
description: "Returns the smallest integer greater than or equal to `x`.",
|
|
158
|
+
parameters: [{ name: "x", type: "number" }],
|
|
159
|
+
returns: [{ type: "integer" }],
|
|
160
|
+
}),
|
|
161
|
+
floor: new LuaBuiltinFunction({
|
|
162
|
+
callback: (_sf, x: number) => Math.floor(untagNumber(x)),
|
|
163
|
+
description: "Returns the largest integer less than or equal to `x`.",
|
|
164
|
+
parameters: [{ name: "x", type: "number" }],
|
|
165
|
+
returns: [{ type: "integer" }],
|
|
166
|
+
}),
|
|
167
|
+
max: new LuaBuiltinFunction({
|
|
168
|
+
callback: (_sf, ...args: number[]) => Math.max(...args.map(untagNumber)),
|
|
169
|
+
description: "Returns the greatest of its arguments.",
|
|
170
|
+
signatures: ["math.max(x, ...): number"],
|
|
171
|
+
returns: [{ type: "number" }],
|
|
172
|
+
}),
|
|
173
|
+
min: new LuaBuiltinFunction({
|
|
174
|
+
callback: (_sf, ...args: number[]) => Math.min(...args.map(untagNumber)),
|
|
175
|
+
description: "Returns the least of its arguments.",
|
|
176
|
+
signatures: ["math.min(x, ...): number"],
|
|
177
|
+
returns: [{ type: "number" }],
|
|
178
|
+
}),
|
|
109
179
|
|
|
110
180
|
// Rounding and remainder
|
|
111
|
-
fmod: new LuaBuiltinFunction(
|
|
112
|
-
(_sf, x: number, y: number) => untagNumber(x) % untagNumber(y),
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
181
|
+
fmod: new LuaBuiltinFunction({
|
|
182
|
+
callback: (_sf, x: number, y: number) => untagNumber(x) % untagNumber(y),
|
|
183
|
+
description:
|
|
184
|
+
"Returns the remainder of `x / y` with the quotient rounded toward zero.",
|
|
185
|
+
parameters: [
|
|
186
|
+
{ name: "x", type: "number" },
|
|
187
|
+
{ name: "y", type: "number" },
|
|
188
|
+
],
|
|
189
|
+
returns: [{ type: "number" }],
|
|
190
|
+
}),
|
|
191
|
+
modf: new LuaBuiltinFunction({
|
|
192
|
+
callback: (_sf, x: number) => {
|
|
193
|
+
const xn = untagNumber(x);
|
|
194
|
+
const int = Math.trunc(xn);
|
|
195
|
+
// Guarantee that the `frac` part is always Lua float
|
|
196
|
+
const frac = makeLuaFloat(xn - int);
|
|
197
|
+
return new LuaMultiRes([int, frac]);
|
|
198
|
+
},
|
|
199
|
+
description: "Splits `x` into its integral and fractional parts.",
|
|
200
|
+
parameters: [{ name: "x", type: "number" }],
|
|
201
|
+
returns: [
|
|
202
|
+
{ type: "integer", description: "Integral part." },
|
|
203
|
+
{ type: "float", description: "Fractional part." },
|
|
204
|
+
],
|
|
205
|
+
examples: [{ code: "local integer, fraction = math.modf(3.14)" }],
|
|
120
206
|
}),
|
|
121
207
|
|
|
122
208
|
// Returns m and e such that x = m * 2^e, 0.5 <= |m| < 1 (or m=0 when x=0).
|
|
123
209
|
// e is an integer. Mirrors C99/Lua.
|
|
124
210
|
// Special cases: frexp(0) = (0, 0); frexp(+-inf/nan) = (x, 0).
|
|
125
|
-
frexp: new LuaBuiltinFunction(
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
211
|
+
frexp: new LuaBuiltinFunction({
|
|
212
|
+
callback: (_sf, x: number) => {
|
|
213
|
+
const xn = untagNumber(x);
|
|
214
|
+
if (xn === 0 || !Number.isFinite(xn) || Number.isNaN(xn)) {
|
|
215
|
+
return new LuaMultiRes([xn, 0]);
|
|
216
|
+
}
|
|
217
|
+
const abs = Math.abs(xn);
|
|
218
|
+
let e = Math.floor(Math.log2(abs)) + 1;
|
|
219
|
+
let m = xn / 2 ** e;
|
|
220
|
+
if (Math.abs(m) >= 1.0) {
|
|
221
|
+
e += 1;
|
|
222
|
+
m /= 2;
|
|
223
|
+
}
|
|
224
|
+
if (Math.abs(m) < 0.5) {
|
|
225
|
+
e -= 1;
|
|
226
|
+
m *= 2;
|
|
227
|
+
}
|
|
228
|
+
return new LuaMultiRes([m, e]);
|
|
229
|
+
},
|
|
230
|
+
description:
|
|
231
|
+
"Decomposes `x` into a normalized fraction and a power-of-two exponent.",
|
|
232
|
+
parameters: [{ name: "x", type: "number" }],
|
|
233
|
+
returns: [
|
|
234
|
+
{ type: "number", description: "Fraction." },
|
|
235
|
+
{ type: "integer", description: "Exponent." },
|
|
236
|
+
],
|
|
142
237
|
}),
|
|
143
238
|
|
|
144
239
|
// Returns m * 2^e (the inverse of frexp). Mirrors C99/Lua.
|
|
145
|
-
ldexp: new LuaBuiltinFunction(
|
|
146
|
-
(_sf, m: number, e: number) =>
|
|
147
|
-
|
|
240
|
+
ldexp: new LuaBuiltinFunction({
|
|
241
|
+
callback: (_sf, m: number, e: number) =>
|
|
242
|
+
untagNumber(m) * 2 ** untagNumber(e),
|
|
243
|
+
description: "Returns `m * 2^e`, the inverse of `math.frexp`.",
|
|
244
|
+
parameters: [
|
|
245
|
+
{ name: "m", type: "number" },
|
|
246
|
+
{ name: "e", type: "integer" },
|
|
247
|
+
],
|
|
248
|
+
returns: [{ type: "number" }],
|
|
249
|
+
}),
|
|
148
250
|
|
|
149
251
|
// Power and logarithms
|
|
150
|
-
exp: new LuaBuiltinFunction(
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
}
|
|
155
|
-
|
|
252
|
+
exp: new LuaBuiltinFunction({
|
|
253
|
+
callback: (_sf, x: number) => Math.exp(untagNumber(x)),
|
|
254
|
+
description: "Returns `e` raised to `x`.",
|
|
255
|
+
parameters: [{ name: "x", type: "number" }],
|
|
256
|
+
returns: [{ type: "number" }],
|
|
257
|
+
}),
|
|
258
|
+
log: new LuaBuiltinFunction({
|
|
259
|
+
callback: (_sf, x: number, base?: number) => {
|
|
260
|
+
if (base === undefined) {
|
|
261
|
+
return Math.log(untagNumber(x));
|
|
262
|
+
}
|
|
263
|
+
return Math.log(untagNumber(x)) / Math.log(untagNumber(base));
|
|
264
|
+
},
|
|
265
|
+
description:
|
|
266
|
+
"Returns the logarithm of `x`, using the natural base unless another base is supplied.",
|
|
267
|
+
parameters: [
|
|
268
|
+
{ name: "x", type: "number" },
|
|
269
|
+
{ name: "base", type: "number", optional: true },
|
|
270
|
+
],
|
|
271
|
+
returns: [{ type: "number" }],
|
|
272
|
+
examples: [{ code: "print(math.log(100, 10)) -- 2" }],
|
|
156
273
|
}),
|
|
157
274
|
// Power function (deprecated in Lua 5.4 but retained for compatibility)
|
|
158
|
-
pow: new LuaBuiltinFunction(
|
|
159
|
-
(_sf, x: number, y: number) => untagNumber(x) ** untagNumber(y),
|
|
160
|
-
|
|
161
|
-
|
|
275
|
+
pow: new LuaBuiltinFunction({
|
|
276
|
+
callback: (_sf, x: number, y: number) => untagNumber(x) ** untagNumber(y),
|
|
277
|
+
description: "Returns `x` raised to the power `y`.",
|
|
278
|
+
parameters: [
|
|
279
|
+
{ name: "x", type: "number" },
|
|
280
|
+
{ name: "y", type: "number" },
|
|
281
|
+
],
|
|
282
|
+
returns: [{ type: "number" }],
|
|
283
|
+
deprecated: "Use the `^` operator instead.",
|
|
284
|
+
}),
|
|
285
|
+
sqrt: new LuaBuiltinFunction({
|
|
286
|
+
callback: (_sf, x: number) => Math.sqrt(untagNumber(x)),
|
|
287
|
+
description: "Returns the square root of `x`.",
|
|
288
|
+
parameters: [{ name: "x", type: "number" }],
|
|
289
|
+
returns: [{ type: "number" }],
|
|
290
|
+
}),
|
|
162
291
|
|
|
163
292
|
// Trigonometric functions
|
|
164
|
-
cos: new LuaBuiltinFunction(
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
293
|
+
cos: new LuaBuiltinFunction({
|
|
294
|
+
callback: (_sf, x: number) => Math.cos(untagNumber(x)),
|
|
295
|
+
description: "Returns the cosine of `x` radians.",
|
|
296
|
+
parameters: [{ name: "x", type: "number" }],
|
|
297
|
+
returns: [{ type: "number" }],
|
|
298
|
+
}),
|
|
299
|
+
sin: new LuaBuiltinFunction({
|
|
300
|
+
callback: (_sf, x: number) => Math.sin(untagNumber(x)),
|
|
301
|
+
description: "Returns the sine of `x` radians.",
|
|
302
|
+
parameters: [{ name: "x", type: "number" }],
|
|
303
|
+
returns: [{ type: "number" }],
|
|
304
|
+
}),
|
|
305
|
+
tan: new LuaBuiltinFunction({
|
|
306
|
+
callback: (_sf, x: number) => Math.tan(untagNumber(x)),
|
|
307
|
+
description: "Returns the tangent of `x` radians.",
|
|
308
|
+
parameters: [{ name: "x", type: "number" }],
|
|
309
|
+
returns: [{ type: "number" }],
|
|
310
|
+
}),
|
|
311
|
+
acos: new LuaBuiltinFunction({
|
|
312
|
+
callback: (_sf, x: number) => Math.acos(untagNumber(x)),
|
|
313
|
+
description: "Returns the arc cosine of `x` in radians.",
|
|
314
|
+
parameters: [{ name: "x", type: "number" }],
|
|
315
|
+
returns: [{ type: "number" }],
|
|
316
|
+
}),
|
|
317
|
+
asin: new LuaBuiltinFunction({
|
|
318
|
+
callback: (_sf, x: number) => Math.asin(untagNumber(x)),
|
|
319
|
+
description: "Returns the arc sine of `x` in radians.",
|
|
320
|
+
parameters: [{ name: "x", type: "number" }],
|
|
321
|
+
returns: [{ type: "number" }],
|
|
322
|
+
}),
|
|
323
|
+
atan: new LuaBuiltinFunction({
|
|
324
|
+
callback: (_sf, y: number, x?: number) => {
|
|
325
|
+
if (x === undefined) {
|
|
326
|
+
return Math.atan(untagNumber(y));
|
|
327
|
+
}
|
|
328
|
+
return Math.atan2(untagNumber(y), untagNumber(x));
|
|
329
|
+
},
|
|
330
|
+
description:
|
|
331
|
+
"Returns the arc tangent of `y/x` in radians, using `1` for omitted `x`.",
|
|
332
|
+
parameters: [
|
|
333
|
+
{ name: "y", type: "number" },
|
|
334
|
+
{ name: "x", type: "number", optional: true },
|
|
335
|
+
],
|
|
336
|
+
returns: [{ type: "number" }],
|
|
174
337
|
}),
|
|
175
338
|
|
|
176
339
|
// Hyperbolic functions (deprecated in Lua 5.4 but retained for compatibility)
|
|
177
|
-
cosh: new LuaBuiltinFunction(
|
|
178
|
-
|
|
179
|
-
|
|
340
|
+
cosh: new LuaBuiltinFunction({
|
|
341
|
+
callback: (_sf, x: number) => Math.cosh(untagNumber(x)),
|
|
342
|
+
description: "Returns the hyperbolic cosine of `x`.",
|
|
343
|
+
parameters: [{ name: "x", type: "number" }],
|
|
344
|
+
returns: [{ type: "number" }],
|
|
345
|
+
deprecated: "Retained for compatibility with older Lua versions.",
|
|
346
|
+
}),
|
|
347
|
+
sinh: new LuaBuiltinFunction({
|
|
348
|
+
callback: (_sf, x: number) => Math.sinh(untagNumber(x)),
|
|
349
|
+
description: "Returns the hyperbolic sine of `x`.",
|
|
350
|
+
parameters: [{ name: "x", type: "number" }],
|
|
351
|
+
returns: [{ type: "number" }],
|
|
352
|
+
deprecated: "Retained for compatibility with older Lua versions.",
|
|
353
|
+
}),
|
|
354
|
+
tanh: new LuaBuiltinFunction({
|
|
355
|
+
callback: (_sf, x: number) => Math.tanh(untagNumber(x)),
|
|
356
|
+
description: "Returns the hyperbolic tangent of `x`.",
|
|
357
|
+
parameters: [{ name: "x", type: "number" }],
|
|
358
|
+
returns: [{ type: "number" }],
|
|
359
|
+
deprecated: "Retained for compatibility with older Lua versions.",
|
|
360
|
+
}),
|
|
180
361
|
|
|
181
362
|
// Additional utility
|
|
182
|
-
deg: new LuaBuiltinFunction(
|
|
183
|
-
(_sf, x: number) => (untagNumber(x) * 180) / Math.PI,
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
363
|
+
deg: new LuaBuiltinFunction({
|
|
364
|
+
callback: (_sf, x: number) => (untagNumber(x) * 180) / Math.PI,
|
|
365
|
+
description: "Converts an angle from radians to degrees.",
|
|
366
|
+
parameters: [{ name: "x", type: "number" }],
|
|
367
|
+
returns: [{ type: "number" }],
|
|
368
|
+
examples: [{ code: "print(math.deg(math.pi)) -- 180" }],
|
|
369
|
+
}),
|
|
370
|
+
rad: new LuaBuiltinFunction({
|
|
371
|
+
callback: (_sf, x: number) => (untagNumber(x) * Math.PI) / 180,
|
|
372
|
+
description: "Converts an angle from degrees to radians.",
|
|
373
|
+
parameters: [{ name: "x", type: "number" }],
|
|
374
|
+
returns: [{ type: "number" }],
|
|
375
|
+
}),
|
|
376
|
+
ult: new LuaBuiltinFunction({
|
|
377
|
+
callback: (_sf, m: number, n: number) => {
|
|
378
|
+
return untagNumber(m) >>> 0 < untagNumber(n) >>> 0;
|
|
379
|
+
},
|
|
380
|
+
description: "Compares two integers as unsigned 32-bit values.",
|
|
381
|
+
parameters: [
|
|
382
|
+
{ name: "m", type: "integer" },
|
|
383
|
+
{ name: "n", type: "integer" },
|
|
384
|
+
],
|
|
385
|
+
returns: [{ type: "boolean" }],
|
|
386
|
+
examples: [{ code: "print(math.ult(2, 3)) -- true" }],
|
|
190
387
|
}),
|
|
191
388
|
|
|
192
389
|
// Keep the cosineSimilarity utility function
|
|
193
|
-
cosineSimilarity: new LuaBuiltinFunction(
|
|
194
|
-
(sf, vecA: LuaTable | number[], vecB: LuaTable | number[]) => {
|
|
390
|
+
cosineSimilarity: new LuaBuiltinFunction({
|
|
391
|
+
callback: (sf, vecA: LuaTable | number[], vecB: LuaTable | number[]) => {
|
|
195
392
|
if (vecA instanceof LuaTable) {
|
|
196
393
|
vecA = vecA.toJSArray();
|
|
197
394
|
}
|
|
@@ -215,5 +412,13 @@ export const mathApi = new LuaTable({
|
|
|
215
412
|
|
|
216
413
|
return dotProduct / (Math.sqrt(normA) * Math.sqrt(normB));
|
|
217
414
|
},
|
|
218
|
-
|
|
415
|
+
description:
|
|
416
|
+
"Returns the cosine similarity between two equal-length numeric vectors.",
|
|
417
|
+
parameters: [
|
|
418
|
+
{ name: "vecA", type: "table" },
|
|
419
|
+
{ name: "vecB", type: "table" },
|
|
420
|
+
],
|
|
421
|
+
returns: [{ type: "number", description: "Cosine similarity." }],
|
|
422
|
+
examples: [{ code: "print(math.cosineSimilarity({1, 2, 3}, {4, 5, 6}))" }],
|
|
423
|
+
}),
|
|
219
424
|
});
|
|
@@ -7,8 +7,8 @@ import { fsEndpoint } from "../../spaces/constants.ts";
|
|
|
7
7
|
import { LuaNativeJSFunction, LuaTable } from "../runtime.ts";
|
|
8
8
|
|
|
9
9
|
export const netApi = new LuaTable({
|
|
10
|
-
proxyFetch: new LuaNativeJSFunction(
|
|
11
|
-
async (
|
|
10
|
+
proxyFetch: new LuaNativeJSFunction({
|
|
11
|
+
callback: async (
|
|
12
12
|
url: string,
|
|
13
13
|
options: ProxyFetchRequest = {},
|
|
14
14
|
): Promise<ProxyFetchResponse> => {
|
|
@@ -70,24 +70,72 @@ export const netApi = new LuaTable({
|
|
|
70
70
|
body: body,
|
|
71
71
|
};
|
|
72
72
|
},
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
73
|
+
description:
|
|
74
|
+
"Performs an HTTP request through the SilverBullet server to avoid browser CORS restrictions.",
|
|
75
|
+
signatures: ["net.proxyFetch(url, options?)"],
|
|
76
|
+
parameters: [
|
|
77
|
+
{ name: "url", type: "string", description: "URL to request." },
|
|
78
|
+
{
|
|
79
|
+
name: "options",
|
|
80
|
+
type: "table",
|
|
81
|
+
description:
|
|
82
|
+
"Optional method, headers, body, and responseEncoding values.",
|
|
83
|
+
optional: true,
|
|
84
|
+
},
|
|
85
|
+
],
|
|
86
|
+
returns: [
|
|
87
|
+
{
|
|
88
|
+
type: "table",
|
|
89
|
+
description: "Response status, headers, decoded body, and ok flag.",
|
|
90
|
+
},
|
|
91
|
+
],
|
|
92
|
+
see: "API/net",
|
|
93
|
+
}),
|
|
94
|
+
readURI: new LuaNativeJSFunction({
|
|
95
|
+
callback: (
|
|
96
|
+
uri: string,
|
|
97
|
+
options: { uri?: string; encoding?: string } = {},
|
|
98
|
+
) => {
|
|
76
99
|
options.uri = uri;
|
|
77
100
|
return client.clientSystem.serviceRegistry.invokeBestMatch(
|
|
78
101
|
`net.readURI:${uri}`,
|
|
79
102
|
options,
|
|
80
103
|
);
|
|
81
104
|
},
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
105
|
+
description: "Reads content from a URI using the best matching service.",
|
|
106
|
+
signatures: ["net.readURI(uri, options?)"],
|
|
107
|
+
parameters: [
|
|
108
|
+
{ name: "uri", type: "string", description: "URI to read." },
|
|
109
|
+
{
|
|
110
|
+
name: "options",
|
|
111
|
+
type: "table",
|
|
112
|
+
description: "Optional service-specific values such as encoding.",
|
|
113
|
+
optional: true,
|
|
114
|
+
},
|
|
115
|
+
],
|
|
116
|
+
returns: [{ description: "Content returned by the matching service." }],
|
|
117
|
+
see: "API/net",
|
|
118
|
+
}),
|
|
119
|
+
writeURI: new LuaNativeJSFunction({
|
|
120
|
+
callback: (uri: string, content: string | Uint8Array) => {
|
|
85
121
|
return client.clientSystem.serviceRegistry.invokeBestMatch(
|
|
86
122
|
`net.writeURI:${uri}`,
|
|
87
123
|
{ uri, content },
|
|
88
124
|
);
|
|
89
125
|
},
|
|
90
|
-
|
|
126
|
+
description: "Writes content to a URI using the best matching service.",
|
|
127
|
+
signatures: ["net.writeURI(uri, content)"],
|
|
128
|
+
parameters: [
|
|
129
|
+
{ name: "uri", type: "string", description: "URI to write." },
|
|
130
|
+
{
|
|
131
|
+
name: "content",
|
|
132
|
+
type: "string|userdata",
|
|
133
|
+
description: "Text or binary content to write.",
|
|
134
|
+
},
|
|
135
|
+
],
|
|
136
|
+
returns: [{ description: "Result returned by the matching service." }],
|
|
137
|
+
see: "API/net",
|
|
138
|
+
}),
|
|
91
139
|
});
|
|
92
140
|
|
|
93
141
|
// Utility functions
|