mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-26 08:26:04 +00:00
Scripts: #include and the other preprocessor lines run, and $.evalFile runs a file
Before a script runs, `script.run` reads its preprocessor lines (`#` or `//@` at the start of a line, outside strings and comments): - `#include` and `//@include` put another file's text in place of the line, looked for beside the including file, then in each `#includepath` folder, then in each `JSINCLUDE` folder. A later `#includepath` replaces the list. - `#script` names the run unless `name` is given; `#target` takes any value; `#strict off` is taken. `#strict on`, `#targetengine` and `#engine` are refused as unsupported, and any other `#name` as unknown. `$.evalFile(path, timeout?)` runs a file in the same global environment and returns its last value, `$.fileName` is the file being run and `$.includePath` the include folders. A script run from a file reads these files only in its folder and the folders below it. Paths with a `..` name, links or junctions that lead out, device names, streams and network paths are refused; a script given as text reads none. A run reads at most 64 files 16 levels deep, 32 MiB of source in all and 1,024 paths looked up. An error in an included or evaluated file is reported at that file's line and column, and the report's new `file` field names it. Docs: docs/mcp.md (script.run, Script Console), docs/target-app-parity.md.
This commit is contained in:
+39
-4
@@ -1549,7 +1549,7 @@ describes that menu item. Pass exactly one of `path` and `source`. A `path` must
|
||||
case. A `.jsxbin` file or text that starts with `@JSXBIN@` is compiled and ends with an error, as does text that is
|
||||
not UTF-8. The language is ES5.1, except that identifiers take the characters Unicode's `ID_Start` and
|
||||
`ID_Continue` properties allow, as later editions define them, and may use `\u{...}` escapes. The script reaches the
|
||||
app through the global object `vc`, and writes to the Script Console through `$`:
|
||||
app through the global object `vc`, and writes to the Script Console and runs other files through `$`:
|
||||
|
||||
- `vc.run(id, params)` runs a command and returns its result. A command that fails throws an error the script can
|
||||
catch. The documents and the session state the command changed, preferences included, go back, and any file it
|
||||
@@ -1561,9 +1561,41 @@ app through the global object `vc`, and writes to the Script Console through `$`
|
||||
- `vc.log(value)` adds a value to the report and a line to the Script Console.
|
||||
- `$.write(...values)` writes the values to the Script Console with no separator, each as `String(value)` gives it, and
|
||||
`$.writeln(...values)` does the same and ends the line. Each call counts as a host call.
|
||||
- `$.evalFile(path, timeout?)` runs the file `path` names, relative to the file being run, in the same global
|
||||
environment, so its functions and variables stay defined, and returns its last value (`undefined` for an empty
|
||||
file). Its preprocessor lines are read as the script's are. `timeout` is a number of milliseconds from 0; the file
|
||||
is read at once and `timeout` is not waited on. The run's fuel and limits apply to the file. An empty path, a
|
||||
missing file and a refused path throw errors the script can catch.
|
||||
- `$.fileName` is the file being run, which is the file `$.evalFile` is running while it runs, and is empty for a
|
||||
script given as `source`. `$.includePath` is the current `#includepath` list, separated by `;`.
|
||||
- `vc.args` is the `args` object.
|
||||
- `vc.api.version` is `"1.0"`, and `vc.api.has(feature)` says whether the API has a feature.
|
||||
|
||||
Before any of the script runs, its preprocessor lines are read. The help page
|
||||
https://extendscript.docsforadobe.dev/extendscript-tools-features/preprocessor-directives/ describes these lines, and
|
||||
https://extendscript.docsforadobe.dev/extendscript-tools-features/dollar-object/ describes `$.evalFile`, `$.fileName`
|
||||
and `$.includePath`. A line counts when it starts with `#` or `//@`, after blanks only, outside strings and comments.
|
||||
VectorCraft reads them by these rules of its own:
|
||||
|
||||
- `#include "file"` and `//@include "file"` put the text of that file in place of the line. A value with spaces or
|
||||
punctuation goes in single or double quotes. The file is looked for beside the file that includes it, then in each
|
||||
`#includepath` folder in turn, then in each folder of the `JSINCLUDE` environment variable (absolute folders
|
||||
separated by `;`). The included file must be a whole script on its own. A file may be included again after its
|
||||
earlier inclusion has ended, and a file that includes itself, directly or through others, is an error.
|
||||
- `#includepath "a;b"` sets the folders `#include` looks in, separated by `;`. A relative folder is relative to the
|
||||
folder of the file that includes. A later `#includepath` replaces the list.
|
||||
- `#script "name"` names the run in the report and the Script Console, unless `name` is given. A `#script` line in an
|
||||
included file does not rename the run.
|
||||
- `#target` takes any value and does not change how the script runs. `#strict off` is taken.
|
||||
- `#strict on`, `#targetengine` and `#engine` end the run with an unsupported-directive error, and any other `#name`
|
||||
with an unknown-directive error. A `//@` line with another name is a comment.
|
||||
- A script run from a file reads its included files and the files `$.evalFile` runs only in that file's folder and
|
||||
the folders below it. A path with a `..` name, a path that leads out of the folder through a link or a junction, a
|
||||
Windows device name or stream, and a computer on the network are refused, and so is every path for a script given as
|
||||
`source`. A `JSINCLUDE` folder outside the script's folder is passed over.
|
||||
- A missing or refused included file ends the run before any of it runs. An error in an included file or a file `$.evalFile`
|
||||
ran is reported at that file's line and column, and the report's `file` names the file.
|
||||
|
||||
The run is one transaction. When the script ends, each document it changed gets one undo step named Run Script. A
|
||||
run that changes no document adds no undo step. The journal records each command the run finished, as it records
|
||||
commands run one at a time. A preference the run changed takes the run's value, and a preference changed in the app
|
||||
@@ -1590,7 +1622,8 @@ VectorCraft sets these limits itself:
|
||||
|
||||
| Limit | Value |
|
||||
|-------|-------|
|
||||
| Source text | 8 MiB |
|
||||
| Source text | 8 MiB a file, 32 MiB in all |
|
||||
| Included and evaluated files | 64 in all, 16 levels deep, 1,024 paths looked up |
|
||||
| Heap | 256 MiB (128 MiB on the web) |
|
||||
| Host calls | 2,000,000 |
|
||||
| `maxFuel`, instructions in all | 1 to 100,000,000,000; 1,000,000,000 by default |
|
||||
@@ -1607,7 +1640,8 @@ In the app, a script past the growth limit stops at a question to continue or to
|
||||
with an error at that limit. The headless reply is `{ok: true, name, changed, written, log, fuelUsed, hostCalls,
|
||||
runTimeMs, timingAvailable, hostCallCounts, slowestCommands, console}`. In the app the reply is `{running: true,
|
||||
name}`, and the report appears later as `scriptReport` in `ui.inspect`. The report of a failed run has the same
|
||||
fields after `kind`, `message`, `line`, `column` and `fuelLeft`. `answers` takes only an empty object, since scripts
|
||||
fields after `kind`, `message`, `line`, `column`, `file` (when the error is in another file than the script) and
|
||||
`fuelLeft`. `answers` takes only an empty object, since scripts
|
||||
have no prompts yet.
|
||||
|
||||
- `runTimeMs` is the time the script ran, its commands included. Waits between frames and for a person's answer are
|
||||
@@ -1626,7 +1660,8 @@ vectorcraft-cli run --cmd script.run --params '{"path": "Tidy Layers.js", "args"
|
||||
```
|
||||
|
||||
Window › Script Console shows the session's script lines, oldest first: each run's start, its `$.write` and
|
||||
`$.writeln` output, its `vc.log` entries, its uncaught error as `name:line:column: message`, its end, and a report of
|
||||
`$.writeln` output, its `vc.log` entries, its uncaught error as `name:line:column: message` (or `name: file:line:column: message` when the error is in another
|
||||
file), its end, and a report of
|
||||
its time, host calls and slowest commands. Each line shows the run's number and the script's name. Line feeds,
|
||||
carriage returns and the two together break lines, and other control characters show as their Unicode Control
|
||||
Pictures. The console keeps at most 2,048 lines and 1 MiB of text and drops the oldest lines past that. A line longer
|
||||
|
||||
Reference in New Issue
Block a user