Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Provisional API: This reference documents current compiler behavior. Compatibility is not yet promised.

src/script.x

Build-once execution of x2c scripts.

Functions

FunctionSummary
script_cache_rootReturns the per-user cache root: X2C_CACHE_DIR, XDG_CACHE_HOME/x2c, or ~/.cache/x2c, whichever is set first, or NULL when none is.
script_preparePoints request at its script’s cache directory and executes the cached executable when it is current; that path does not return.
script_runExecutes a script that script_prepare pointed at the cache and the caller built; that path does not return.

Functions

script_cache_root

String script_cache_root(void)

Returns the per-user cache root: X2C_CACHE_DIR, XDG_CACHE_HOME/x2c, or ~/.cache/x2c, whichever is set first, or NULL when none is.

Source: src/script.x:24

script_prepare

int script_prepare(CliRequest c)

Points request at its script’s cache directory and executes the cached executable when it is current; that path does not return. Otherwise it locks the directory against concurrent builds of the same script, removes the entries of scripts that no longer exist, and returns 0; the caller builds request and calls script_run. A --clean request removes the script’s entry and returns 1.

Source: src/script.x:70

script_run

int script_run(CliRequest c)

Executes a script that script_prepare pointed at the cache and the caller built; that path does not return. A dry run prints the action and returns zero.

Source: src/script.x:108

Design notes

x2c script builds each script into its own directory under the per-user cache. When everything the executable was built from is unchanged, a run executes it before any compiler state loads. Otherwise the build runs under a lock on that directory, publishes the executable, and executes it.