Rebecca Turner
7ef296d43a
Feature: Allow tools to accept arrays of values as an array (#4085)
Previously, a tool that that registered itself as having an array parameter
had each element of the array registered as a variable, but it did not
register the array parameter itself. This meant that it was only really
useful with fixed length arrays.
This patch adds a variable for the array itself that lives alongside the
existing args. I don't expect this to have any backward compatiblity
concerns.
Repro:
```stscript
// this requires lalib to function |
/let key=schema {
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "string",
"properties": {
"example": {
"type": "array",
"contains": {
"type": "string"
}
}
},
"required": [
"example"
]
} ||
/tools-register name=YourFunc description="filler" parameters={{var::schema}} {:
/let ex {: /try {: /return {{var::arg.example}} :} :}() | /= ex.isException | /if rule=not left={{pipe}} else={:
/console-log {{var::ex}}
:} {:
/console-log "arg.example: {{var::arg.example}}" |
/foreach {{var::arg.example}} {: /console-log "#{{var::index}}: {{var::item}}" :}
:} |
/try {: /return {{var::arg.example.0}} :} | /console-log "arg.example.0: {{pipe}}" |
/try {: /return {{var::arg.example.1}} :} | /console-log "arg.example.1: {{pipe}}" |
/try {: /return {{var::arg.example.2}} :} | /console-log "arg.example.2: {{pipe}}" |
/try {: /return {{var::arg.example.3}} :} | /console-log "arg.example.3: {{pipe}}" |
:} ||
/let key=params {
"example": [
"test1", "test2", "test3"
]
} |
/tools-invoke parameters={{var::params}} YourFunc
```
Currently produces:
```
[/console-log] arg.example: {"isException":true,"exception":"No such variable: \"arg.example\""}
[/console-log] arg.example.0: {"isException":false,"result":"test1"}
[/console-log] arg.example.1: {"isException":false,"result":"test2"}
[/console-log] arg.example.2: {"isException":false,"result":"test3"}
[/console-log] arg.example.3: {"isException":true,"exception":"No such variable: \"arg.example.3\""}
```
With this patch it produces:
```
[/console-log] arg.example: ["test1","test2","test3"]
[/console-log] #0: test1
[/console-log] #1: test2
[/console-log] #2: test3
[/console-log] arg.example.0: {"isException":false,"result":"test1"}
[/console-log] arg.example.1: {"isException":false,"result":"test2"}
[/console-log] arg.example.2: {"isException":false,"result":"test3"}
[/console-log] arg.example.3: {"isException":true,"exception":"No such variable: \"arg.example.3\""}
```
2025-06-02 10:54:10 +03:00
..
2025-06-01 20:07:33 +03:00
2025-06-01 18:15:06 +03:00
2025-05-24 00:35:58 +03:00
2025-06-01 13:56:34 +03:00
2025-03-18 18:15:59 +02:00
2025-05-04 22:05:15 +03:00
2025-03-19 20:00:33 +02:00
2025-02-28 22:44:10 +02:00
2025-02-28 10:26:03 +02:00
2025-04-25 00:51:47 +01:00
2025-05-12 14:26:18 +09:00
2025-06-01 15:04:16 +03:00
2025-03-27 20:46:27 +02:00
2025-05-29 11:56:59 +02:00
2025-06-01 13:56:34 +03:00
2024-09-27 01:19:45 +03:00
2025-05-26 11:10:47 +00:00
2025-05-29 21:21:53 +03:00
2025-04-28 18:55:10 +07:00
2025-02-28 21:55:48 +02:00
2025-04-26 01:47:07 +03:00
2025-04-05 21:54:01 +03:00
2025-05-19 20:30:03 +03:00
2025-05-29 11:56:59 +02:00
2025-06-01 15:04:16 +03:00
2025-05-29 11:56:59 +02:00
2025-05-29 11:56:59 +02:00
2025-06-01 20:07:33 +03:00
2025-05-24 00:02:48 +03:00
2025-05-16 23:53:37 +03:00
2025-05-29 11:56:59 +02:00
2025-05-28 20:37:50 +03:00
2025-05-21 19:25:14 +09:00
2025-05-28 20:45:35 +03:00
2025-05-16 19:57:56 +03:00
2025-04-04 13:53:56 +00:00
2025-06-01 20:07:33 +03:00
2025-03-14 20:15:04 +02:00
2025-05-04 18:17:44 +02:00
2025-05-29 11:56:59 +02:00
2025-04-28 00:14:57 +03:00
2025-05-29 11:56:59 +02:00
2025-05-10 05:42:15 -05:00
2025-05-11 11:07:13 +03:00
2025-05-22 20:10:53 +03:00
2025-06-02 10:54:10 +03:00
2025-05-17 16:50:02 +03:00
2025-05-26 01:20:28 +03:00
2025-03-19 21:10:42 +02:00
2025-05-29 21:21:53 +03:00
2025-05-29 11:56:59 +02:00