@silverbulletmd/silverbullet 2.9.0 → 2.11.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 +38 -25
- package/client/asset_bundle/bundle.ts +0 -1
- package/client/config.ts +343 -0
- package/client/markdown_parser/constants.ts +3 -1
- package/client/plugos/hooks/command.ts +0 -5
- package/client/plugos/hooks/event.ts +0 -6
- package/client/plugos/hooks/mq.ts +0 -3
- package/client/plugos/hooks/slash_command.ts +1 -7
- package/client/plugos/hooks/syscall.ts +24 -14
- package/client/plugos/manifest_cache.ts +0 -32
- package/client/plugos/plug.ts +0 -3
- package/client/plugos/plug_compile.ts +3 -13
- package/client/plugos/sandboxes/worker_sandbox.ts +19 -9
- 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 +1518 -722
- package/client/plugos/syscalls/event.ts +44 -13
- package/client/plugos/syscalls/fetch.ts +120 -83
- package/client/plugos/syscalls/icon.ts +46 -0
- package/client/plugos/syscalls/index.ts +267 -121
- package/client/plugos/syscalls/jsonschema.ts +107 -9
- package/client/plugos/syscalls/language.ts +38 -12
- package/client/plugos/syscalls/markdown.ts +166 -50
- package/client/plugos/syscalls/mq.ts +92 -20
- package/client/plugos/syscalls/navigator.ts +143 -0
- package/client/plugos/syscalls/schema_introspection.ts +33 -0
- package/client/plugos/syscalls/search.ts +44 -0
- package/client/plugos/syscalls/service_registry.ts +74 -20
- package/client/plugos/syscalls/shell.ts +51 -21
- package/client/plugos/syscalls/space.ts +412 -113
- package/client/plugos/syscalls/sync.ts +103 -20
- package/client/plugos/syscalls/system.ts +274 -139
- package/client/plugos/system.ts +28 -10
- package/client/plugos/worker_runtime.ts +0 -2
- package/client/space_lua/aggregates.ts +0 -16
- package/client/space_lua/api_documentation.ts +107 -0
- package/client/space_lua/ast.ts +13 -5
- package/client/space_lua/ast_narrow.ts +0 -5
- package/client/space_lua/budget.ts +113 -0
- package/client/space_lua/budget_ui.ts +49 -0
- package/client/space_lua/eval.ts +125 -92
- package/client/space_lua/labels.ts +0 -4
- package/client/space_lua/numeric.ts +0 -5
- package/client/space_lua/parse.ts +243 -125
- package/client/space_lua/pretty_print.ts +128 -54
- package/client/space_lua/quarantine.ts +127 -0
- package/client/space_lua/query_collection.ts +7 -51
- package/client/space_lua/query_env.ts +0 -2
- package/client/space_lua/render_lua_markdown.ts +2 -7
- package/client/space_lua/render_widget.ts +173 -0
- package/client/space_lua/runtime.ts +133 -92
- package/client/space_lua/stdlib/crypto.ts +8 -3
- package/client/space_lua/stdlib/encoding.ts +27 -9
- package/client/space_lua/stdlib/format.ts +0 -12
- package/client/space_lua/stdlib/js.ts +136 -23
- package/client/space_lua/stdlib/load.ts +24 -16
- package/client/space_lua/stdlib/math.ts +331 -133
- package/client/space_lua/stdlib/net.ts +57 -13
- package/client/space_lua/stdlib/os.ts +111 -54
- package/client/space_lua/stdlib/pattern.ts +10 -15
- package/client/space_lua/stdlib/space_lua.ts +344 -21
- package/client/space_lua/stdlib/string.ts +282 -104
- package/client/space_lua/stdlib/string_pack.ts +58 -22
- package/client/space_lua/stdlib/table.ts +195 -45
- package/client/space_lua/stdlib.ts +354 -125
- package/client/space_lua/syscalls.ts +270 -0
- package/client/space_lua/tonumber.ts +0 -9
- package/dist/plug-compile.js +2 -3
- package/package.json +15 -5
- package/plug-api/lib/async.ts +1 -6
- package/plug-api/lib/collation.ts +22 -0
- package/plug-api/lib/crypto.ts +16 -15
- package/plug-api/lib/dates.ts +33 -0
- package/plug-api/lib/fuzzy.ts +282 -0
- package/plug-api/lib/json.ts +0 -6
- package/plug-api/lib/limited_map.ts +0 -2
- package/plug-api/lib/link_write.ts +27 -0
- package/plug-api/{ui → lib}/panel_styles.ts +4 -3
- package/plug-api/lib/ref.ts +124 -5
- package/plug-api/lib/resolve.ts +0 -1
- package/plug-api/lib/resolve_path.ts +290 -0
- package/plug-api/lib/shortcut.ts +17 -1
- package/plug-api/lib/tags.ts +0 -3
- package/plug-api/lib/transclusion.ts +28 -1
- package/plug-api/lib/tree.ts +0 -5
- package/plug-api/lib/yaml.ts +3 -42
- package/plug-api/syscall.ts +1 -5
- package/plug-api/syscalls/config.ts +7 -5
- package/plug-api/syscalls/editor.ts +70 -208
- package/plug-api/syscalls/icon.ts +18 -0
- package/plug-api/syscalls/index.ts +39 -5
- package/plug-api/syscalls/jsonschema.ts +9 -0
- package/plug-api/syscalls/lua.ts +7 -0
- package/plug-api/syscalls/search.ts +11 -0
- package/plug-api/syscalls/shell.ts +0 -1
- package/plug-api/syscalls/space.ts +122 -5
- package/plug-api/syscalls/sync.ts +23 -2
- package/plug-api/syscalls/system.ts +53 -0
- package/plug-api/syscalls.ts +2 -0
- package/plug-api/system_mock.ts +15 -2
- package/plug-api/types/client.ts +4 -3
- package/plug-api/types/datastore.ts +11 -2
- package/plug-api/types/index.ts +62 -1
- package/plug-api/types/manifest.ts +22 -4
- package/plug-api/types/profile.ts +13 -0
- package/plug-api/types/revisions.ts +67 -0
- package/plug-api/ui/cx.ts +1 -3
- package/plug-api/ui/description.ts +64 -0
- package/plug-api/ui/hover.ts +69 -0
- package/plug-api/ui/index.ts +61 -2
- package/plug-api/ui/scroll.ts +30 -0
- package/plug-api/ui/slugify.ts +44 -0
- package/plug-api/ui/tree_model.ts +263 -0
- package/plug-api/ui/tree_types.ts +66 -0
- package/plug-api/ui/use_fit_collapse.ts +67 -0
- package/plugs/builtin_plugs.ts +0 -1
- package/plugs/index/types.ts +9 -0
- package/client/plugos/syscalls/lua.ts +0 -81
- package/plug-api/lib/memory_cache.ts +0 -21
|
@@ -58,8 +58,14 @@ export const tableApi = new LuaTable({
|
|
|
58
58
|
* @param j - The end index.
|
|
59
59
|
* @returns The concatenated string.
|
|
60
60
|
*/
|
|
61
|
-
concat: new LuaBuiltinFunction(
|
|
62
|
-
async (
|
|
61
|
+
concat: new LuaBuiltinFunction({
|
|
62
|
+
callback: async (
|
|
63
|
+
sf,
|
|
64
|
+
tbl: LuaTable | any[],
|
|
65
|
+
sep?: string,
|
|
66
|
+
i?: number,
|
|
67
|
+
j?: number,
|
|
68
|
+
) => {
|
|
63
69
|
sep = sep ?? "";
|
|
64
70
|
i = i ?? 1;
|
|
65
71
|
if (j === undefined || j === null) {
|
|
@@ -108,7 +114,16 @@ export const tableApi = new LuaTable({
|
|
|
108
114
|
}
|
|
109
115
|
return out.join(sep);
|
|
110
116
|
},
|
|
111
|
-
|
|
117
|
+
description:
|
|
118
|
+
"Concatenates table elements from `i` through `j` using an optional separator.",
|
|
119
|
+
parameters: [
|
|
120
|
+
{ name: "table", type: "table" },
|
|
121
|
+
{ name: "sep", type: "string", optional: true },
|
|
122
|
+
{ name: "i", type: "integer", optional: true },
|
|
123
|
+
{ name: "j", type: "integer", optional: true },
|
|
124
|
+
],
|
|
125
|
+
returns: [{ type: "string" }],
|
|
126
|
+
}),
|
|
112
127
|
|
|
113
128
|
/**
|
|
114
129
|
* Inserts an element into a table at a specified position.
|
|
@@ -116,8 +131,8 @@ export const tableApi = new LuaTable({
|
|
|
116
131
|
* @param posOrValue - The position or value to insert.
|
|
117
132
|
* @param value - The value to insert.
|
|
118
133
|
*/
|
|
119
|
-
insert: new LuaBuiltinFunction(
|
|
120
|
-
async (
|
|
134
|
+
insert: new LuaBuiltinFunction({
|
|
135
|
+
callback: async (
|
|
121
136
|
sf,
|
|
122
137
|
tbl: LuaTable | any[],
|
|
123
138
|
posOrValue: number | any,
|
|
@@ -159,15 +174,38 @@ export const tableApi = new LuaTable({
|
|
|
159
174
|
|
|
160
175
|
await luaSet(tbl, pos, v, sf);
|
|
161
176
|
},
|
|
162
|
-
|
|
177
|
+
description:
|
|
178
|
+
"Inserts a value at a position, shifting later elements, or appends it when no position is supplied.",
|
|
179
|
+
signatures: [
|
|
180
|
+
"table.insert(table, value)",
|
|
181
|
+
"table.insert(table, pos, value)",
|
|
182
|
+
],
|
|
183
|
+
parameters: [
|
|
184
|
+
{ name: "table", type: "table" },
|
|
185
|
+
{
|
|
186
|
+
name: "posOrValue",
|
|
187
|
+
description: "Insertion position or appended value.",
|
|
188
|
+
},
|
|
189
|
+
{
|
|
190
|
+
name: "value",
|
|
191
|
+
description: "Value for positional insertion.",
|
|
192
|
+
optional: true,
|
|
193
|
+
},
|
|
194
|
+
],
|
|
195
|
+
examples: [
|
|
196
|
+
{
|
|
197
|
+
code: 'local fruits = {"apple", "orange"}\ntable.insert(fruits, 2, "banana")\nprint(table.concat(fruits, ", "))',
|
|
198
|
+
},
|
|
199
|
+
],
|
|
200
|
+
}),
|
|
163
201
|
|
|
164
202
|
/**
|
|
165
203
|
* Removes an element from a table at a specified position.
|
|
166
204
|
* @param tbl - The table to remove the element from.
|
|
167
205
|
* @param pos - The position of the element to remove.
|
|
168
206
|
*/
|
|
169
|
-
remove: new LuaBuiltinFunction(
|
|
170
|
-
async (sf, tbl: LuaTable | any[], pos?: number) => {
|
|
207
|
+
remove: new LuaBuiltinFunction({
|
|
208
|
+
callback: async (sf, tbl: LuaTable | any[], pos?: number) => {
|
|
171
209
|
if (Array.isArray(tbl)) {
|
|
172
210
|
const n = tbl.length;
|
|
173
211
|
const p = pos ?? n;
|
|
@@ -202,7 +240,19 @@ export const tableApi = new LuaTable({
|
|
|
202
240
|
|
|
203
241
|
return v;
|
|
204
242
|
},
|
|
205
|
-
|
|
243
|
+
description:
|
|
244
|
+
"Removes and returns an element, shifting later elements down.",
|
|
245
|
+
parameters: [
|
|
246
|
+
{ name: "table", type: "table" },
|
|
247
|
+
{
|
|
248
|
+
name: "pos",
|
|
249
|
+
type: "integer",
|
|
250
|
+
description: "Position; defaults to the last element.",
|
|
251
|
+
optional: true,
|
|
252
|
+
},
|
|
253
|
+
],
|
|
254
|
+
returns: [{ description: "Removed value." }],
|
|
255
|
+
}),
|
|
206
256
|
|
|
207
257
|
/**
|
|
208
258
|
* Moves elements from table a1 into table a2 (defaults to a1).
|
|
@@ -215,8 +265,8 @@ export const tableApi = new LuaTable({
|
|
|
215
265
|
* @param a2 - Destination table (defaults to a1).
|
|
216
266
|
* @returns a2.
|
|
217
267
|
*/
|
|
218
|
-
move: new LuaBuiltinFunction(
|
|
219
|
-
async (
|
|
268
|
+
move: new LuaBuiltinFunction({
|
|
269
|
+
callback: async (
|
|
220
270
|
sf,
|
|
221
271
|
a1: LuaTable | any[],
|
|
222
272
|
f: number,
|
|
@@ -224,12 +274,10 @@ export const tableApi = new LuaTable({
|
|
|
224
274
|
t: number,
|
|
225
275
|
a2?: LuaTable | any[],
|
|
226
276
|
) => {
|
|
227
|
-
// a2 defaults to a1
|
|
228
277
|
if (a2 === undefined || a2 === null) {
|
|
229
278
|
a2 = a1;
|
|
230
279
|
}
|
|
231
280
|
|
|
232
|
-
// Empty range: nothing to do, return destination
|
|
233
281
|
if (e < f) {
|
|
234
282
|
return a2;
|
|
235
283
|
}
|
|
@@ -252,7 +300,22 @@ export const tableApi = new LuaTable({
|
|
|
252
300
|
|
|
253
301
|
return a2;
|
|
254
302
|
},
|
|
255
|
-
|
|
303
|
+
description:
|
|
304
|
+
"Moves an inclusive element range to a destination table while handling overlaps.",
|
|
305
|
+
parameters: [
|
|
306
|
+
{ name: "a1", type: "table", description: "Source table." },
|
|
307
|
+
{ name: "f", type: "integer", description: "First source index." },
|
|
308
|
+
{ name: "e", type: "integer", description: "Last source index." },
|
|
309
|
+
{ name: "t", type: "integer", description: "Destination start index." },
|
|
310
|
+
{
|
|
311
|
+
name: "a2",
|
|
312
|
+
type: "table",
|
|
313
|
+
description: "Destination table; defaults to `a1`.",
|
|
314
|
+
optional: true,
|
|
315
|
+
},
|
|
316
|
+
],
|
|
317
|
+
returns: [{ type: "table", description: "Destination table." }],
|
|
318
|
+
}),
|
|
256
319
|
|
|
257
320
|
/**
|
|
258
321
|
* Sorts a table.
|
|
@@ -260,8 +323,8 @@ export const tableApi = new LuaTable({
|
|
|
260
323
|
* @param comp - The comparison function.
|
|
261
324
|
* @returns The sorted table.
|
|
262
325
|
*/
|
|
263
|
-
sort: new LuaBuiltinFunction(
|
|
264
|
-
async (sf, tbl: LuaTable | any[], comp?: ILuaFunction) => {
|
|
326
|
+
sort: new LuaBuiltinFunction({
|
|
327
|
+
callback: async (sf, tbl: LuaTable | any[], comp?: ILuaFunction) => {
|
|
265
328
|
if (Array.isArray(tbl)) {
|
|
266
329
|
return await asyncQuickSort(tbl, async (a, b) => {
|
|
267
330
|
if (comp) {
|
|
@@ -311,7 +374,19 @@ export const tableApi = new LuaTable({
|
|
|
311
374
|
|
|
312
375
|
return tbl;
|
|
313
376
|
},
|
|
314
|
-
|
|
377
|
+
description:
|
|
378
|
+
"Sorts a table in place using ascending order or an optional comparison function.",
|
|
379
|
+
parameters: [
|
|
380
|
+
{ name: "table", type: "table" },
|
|
381
|
+
{ name: "comp", type: "function", optional: true },
|
|
382
|
+
],
|
|
383
|
+
returns: [{ type: "table", description: "The sorted table in Space Lua." }],
|
|
384
|
+
examples: [
|
|
385
|
+
{
|
|
386
|
+
code: "local numbers = {3, 1, 2}\ntable.sort(numbers, function(a, b) return a > b end)",
|
|
387
|
+
},
|
|
388
|
+
],
|
|
389
|
+
}),
|
|
315
390
|
|
|
316
391
|
/**
|
|
317
392
|
* Returns the keys of a table.
|
|
@@ -319,11 +394,17 @@ export const tableApi = new LuaTable({
|
|
|
319
394
|
* @param tbl - The table to get the keys from.
|
|
320
395
|
* @returns The keys of the table.
|
|
321
396
|
*/
|
|
322
|
-
keys: new LuaBuiltinFunction(
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
397
|
+
keys: new LuaBuiltinFunction({
|
|
398
|
+
callback: (_sf, tbl: LuaTable | LuaEnv | any) => {
|
|
399
|
+
if (tbl.keys) {
|
|
400
|
+
return tbl.keys();
|
|
401
|
+
}
|
|
402
|
+
return Object.keys(tbl);
|
|
403
|
+
},
|
|
404
|
+
description:
|
|
405
|
+
"Returns an array containing all keys of a table or JavaScript object.",
|
|
406
|
+
parameters: [{ name: "table", type: "table" }],
|
|
407
|
+
returns: [{ type: "table", description: "Array of keys." }],
|
|
327
408
|
}),
|
|
328
409
|
|
|
329
410
|
/**
|
|
@@ -333,13 +414,12 @@ export const tableApi = new LuaTable({
|
|
|
333
414
|
* @param value - The value to check for.
|
|
334
415
|
* @returns True if the value is in the table, false otherwise.
|
|
335
416
|
*/
|
|
336
|
-
includes: new LuaBuiltinFunction(
|
|
337
|
-
(sf, tbl: LuaTable | any[], value: LuaValue) => {
|
|
417
|
+
includes: new LuaBuiltinFunction({
|
|
418
|
+
callback: (sf, tbl: LuaTable | any[], value: LuaValue) => {
|
|
338
419
|
if (!tbl) {
|
|
339
420
|
return false;
|
|
340
421
|
}
|
|
341
422
|
if (tbl instanceof LuaTable) {
|
|
342
|
-
// Iterate over the table
|
|
343
423
|
for (const key of tbl.keys()) {
|
|
344
424
|
if (luaEquals(tbl.get(key), value)) {
|
|
345
425
|
return true;
|
|
@@ -355,7 +435,14 @@ export const tableApi = new LuaTable({
|
|
|
355
435
|
sf,
|
|
356
436
|
);
|
|
357
437
|
},
|
|
358
|
-
|
|
438
|
+
description:
|
|
439
|
+
"Returns whether any table value is Lua-equal to a requested value.",
|
|
440
|
+
parameters: [
|
|
441
|
+
{ name: "table", type: "table" },
|
|
442
|
+
{ name: "value", description: "Value to find." },
|
|
443
|
+
],
|
|
444
|
+
returns: [{ type: "boolean" }],
|
|
445
|
+
}),
|
|
359
446
|
|
|
360
447
|
/**
|
|
361
448
|
* Returns a new table from an old one, only with selected keys
|
|
@@ -363,11 +450,13 @@ export const tableApi = new LuaTable({
|
|
|
363
450
|
* @param keys a list of keys to select from the table, if keys[0] is a table or array, assumed to contain the keys to select
|
|
364
451
|
* @returns a new table with only the selected keys
|
|
365
452
|
*/
|
|
366
|
-
select: new LuaBuiltinFunction(
|
|
367
|
-
|
|
368
|
-
|
|
453
|
+
select: new LuaBuiltinFunction({
|
|
454
|
+
callback: (
|
|
455
|
+
sf,
|
|
456
|
+
tbl: LuaTable | Record<string, any>,
|
|
457
|
+
...keys: LuaValue[]
|
|
458
|
+
) => {
|
|
369
459
|
if (Array.isArray(keys[0])) {
|
|
370
|
-
// First argument is key array, let's unpack
|
|
371
460
|
keys = keys[0];
|
|
372
461
|
} else if (keys[0] instanceof LuaTable) {
|
|
373
462
|
keys = keys[0].toJSArray();
|
|
@@ -383,20 +472,50 @@ export const tableApi = new LuaTable({
|
|
|
383
472
|
}
|
|
384
473
|
return resultTable;
|
|
385
474
|
},
|
|
386
|
-
|
|
475
|
+
description: "Copies selected keys from a table into a new table.",
|
|
476
|
+
signatures: [
|
|
477
|
+
"table.select(table, ...keys): table",
|
|
478
|
+
"table.select(table, keys): table",
|
|
479
|
+
],
|
|
480
|
+
parameters: [
|
|
481
|
+
{ name: "table", type: "table" },
|
|
482
|
+
{
|
|
483
|
+
name: "keys",
|
|
484
|
+
description: "Individual keys or one array-like table of keys.",
|
|
485
|
+
},
|
|
486
|
+
],
|
|
487
|
+
returns: [{ type: "table" }],
|
|
488
|
+
examples: [
|
|
489
|
+
{
|
|
490
|
+
code: '${query[[\n from p = index.pages()\n limit 3\n select table.select(p, "name", "lastModified")\n]]}',
|
|
491
|
+
language: "markdown",
|
|
492
|
+
},
|
|
493
|
+
],
|
|
494
|
+
}),
|
|
387
495
|
|
|
388
496
|
/**
|
|
389
497
|
* Returns a new table with all arguments stored in keys 1, 2, ..., n
|
|
390
498
|
* and t.n = n (the total number of arguments).
|
|
391
499
|
*/
|
|
392
|
-
pack: new LuaBuiltinFunction(
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
500
|
+
pack: new LuaBuiltinFunction({
|
|
501
|
+
callback: async (sf, ...args: any[]) => {
|
|
502
|
+
const tbl = new LuaTable();
|
|
503
|
+
const n = args.length;
|
|
504
|
+
for (let i = 0; i < n; i++) {
|
|
505
|
+
await luaSet(tbl, i + 1, args[i], sf);
|
|
506
|
+
}
|
|
507
|
+
void tbl.rawSet("n", n);
|
|
508
|
+
return tbl;
|
|
509
|
+
},
|
|
510
|
+
description:
|
|
511
|
+
"Packs all arguments into a table with a count stored in field `n`.",
|
|
512
|
+
signatures: ["table.pack(...): table"],
|
|
513
|
+
returns: [
|
|
514
|
+
{
|
|
515
|
+
type: "table",
|
|
516
|
+
description: "Arguments at integer keys plus field `n`.",
|
|
517
|
+
},
|
|
518
|
+
],
|
|
400
519
|
}),
|
|
401
520
|
|
|
402
521
|
/**
|
|
@@ -404,8 +523,8 @@ export const tableApi = new LuaTable({
|
|
|
404
523
|
* i defaults to 1, j defaults to #t (honours __len).
|
|
405
524
|
* Empty range returns no values (null), not an empty multi-res.
|
|
406
525
|
*/
|
|
407
|
-
unpack: new LuaBuiltinFunction(
|
|
408
|
-
async (sf, tbl: LuaTable | any[], i?: number, j?: number) => {
|
|
526
|
+
unpack: new LuaBuiltinFunction({
|
|
527
|
+
callback: async (sf, tbl: LuaTable | any[], i?: number, j?: number) => {
|
|
409
528
|
i = i === undefined || i === null ? 1 : i;
|
|
410
529
|
if (j === undefined || j === null) {
|
|
411
530
|
j = Array.isArray(tbl)
|
|
@@ -425,7 +544,18 @@ export const tableApi = new LuaTable({
|
|
|
425
544
|
}
|
|
426
545
|
return new LuaMultiRes(result);
|
|
427
546
|
},
|
|
428
|
-
|
|
547
|
+
description:
|
|
548
|
+
"Returns the table values from index `i` through `j` as separate results.",
|
|
549
|
+
parameters: [
|
|
550
|
+
{ name: "table", type: "table" },
|
|
551
|
+
{ name: "i", type: "integer", optional: true },
|
|
552
|
+
{ name: "j", type: "integer", optional: true },
|
|
553
|
+
],
|
|
554
|
+
returns: [{ description: "One result per selected element." }],
|
|
555
|
+
examples: [
|
|
556
|
+
{ code: 'local second, third = table.unpack({"a", "b", "c"}, 2, 3)' },
|
|
557
|
+
],
|
|
558
|
+
}),
|
|
429
559
|
|
|
430
560
|
// Non-standard Lua functions
|
|
431
561
|
/**
|
|
@@ -435,8 +565,8 @@ export const tableApi = new LuaTable({
|
|
|
435
565
|
* @param fromIndex - The index to start searching from.
|
|
436
566
|
* @returns Lua multi value of index, value, or nil if no element is found.
|
|
437
567
|
*/
|
|
438
|
-
find: new LuaBuiltinFunction(
|
|
439
|
-
async (
|
|
568
|
+
find: new LuaBuiltinFunction({
|
|
569
|
+
callback: async (
|
|
440
570
|
sf,
|
|
441
571
|
tbl: LuaTable | any[],
|
|
442
572
|
criteriaFn: ILuaFunction,
|
|
@@ -457,5 +587,25 @@ export const tableApi = new LuaTable({
|
|
|
457
587
|
}
|
|
458
588
|
return null;
|
|
459
589
|
},
|
|
460
|
-
|
|
590
|
+
description:
|
|
591
|
+
"Finds the first array element accepted by a predicate and returns its index and value.",
|
|
592
|
+
parameters: [
|
|
593
|
+
{ name: "table", type: "table" },
|
|
594
|
+
{
|
|
595
|
+
name: "criteriaFn",
|
|
596
|
+
type: "function",
|
|
597
|
+
description: "Predicate called with each value.",
|
|
598
|
+
},
|
|
599
|
+
{ name: "fromIndex", type: "integer", optional: true },
|
|
600
|
+
],
|
|
601
|
+
returns: [
|
|
602
|
+
{ type: "integer|nil", description: "Matching index or `nil`." },
|
|
603
|
+
{ description: "Matching value." },
|
|
604
|
+
],
|
|
605
|
+
examples: [
|
|
606
|
+
{
|
|
607
|
+
code: "local index, value = table.find({1, 2, 3, 4}, function(n) return n % 2 == 0 end)",
|
|
608
|
+
},
|
|
609
|
+
],
|
|
610
|
+
}),
|
|
461
611
|
});
|