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

B. Module Reference

Every module lives under the root table, airsstack unless the host renamed it. Every module is present under every preset. A call that needs a grant the script does not have raises an error that names what was granted.

json

No grant needed.

FunctionReturns
encode(value)compact JSON text; object keys sorted
encode_pretty(value)indented JSON text; object keys sorted
decode(text)a Lua value; null becomes a marker that is not nil and encodes back as null; [] becomes a table that encodes back as []

regex

No grant needed. Syntax is that of Rust's regex crate.

FunctionReturns
is_match(pattern, text)true or false
find(pattern, text)the first match, or nil
find_all(pattern, text)a list of every match
captures(pattern, text)groups of the first match by number and by name, or nil
replace(pattern, text, with)text with the first match replaced; $1 and $name refer to groups
replace_all(pattern, text, with)text with every match replaced
split(pattern, text)a list of the pieces between matches
compile(pattern)a table with all the functions above, bound to pattern

path

Works on strings only, and always writes /. Needs no grant, except that absolute(p) of a relative path needs the cwd member of host access.

FunctionReturns
join(a, b, …)the parts joined with /
dirname(p), basename(p)the folder part, the last part
stem(p), ext(p)the last part without, and only, its extension; ext gives "" when there is none
normalize(p)p with . and .. resolved as text; not a containment check
relative_to(p, base)p relative to base; an error if p is not under base
is_absolute(p)true or false
absolute(p)p made absolute against the current folder

fs

Needs a read or write grant for the path, as listed. A relative path also needs the cwd member of host access.

FunctionGrantReturns
read(p)readthe file's contents
read_lines(p)reada list of lines, without line endings
write(p, text)writenothing; replaces the file
append(p, text)writenothing; adds to the end
atomic_write(p, text)writenothing; readers never see a half-written file
create_exclusive(p, text)writetrue if this call created the file, false if it existed
exists(p), is_file(p), is_dir(p)readtrue or false
stat(p)read{ kind, size, modified, readonly }
list(p)readsorted names in the folder
walk(p)readsorted paths of everything below the folder, relative to it
mkdir(p)writenothing; creates missing parents too
remove(p), remove_dir(p)writenothing
copy(from, to)read from, write tonothing
rename(from, to)write bothnothing
same_content(a, b)read bothtrue if the files hold the same bytes
canonicalize(p)readthe real absolute path, symlinks followed
tempfile(), tempdir()write, on the system temp folderthe new path

glob

A relative root for walk also needs the cwd member of host access.

FunctionGrantReturns
match(pattern, path)nonetrue or false
walk(root, pattern)read rootsorted matching paths, relative to root

* and ? stop at /. **/ matches any number of folders, including none. {a,b} matches either.

env

Needs each variable's name to be granted.

FunctionReturns
get(name)the value, or nil if granted but unset
all()a table of every granted variable that is set
set(name, value)nothing; seen by later get calls and by programs proc runs, never by the host

proc

Needs each program's name to be granted.

FunctionReturns
run({program, arg, …}){ status, stdout, stderr }; a non-zero status is not an error
which(program)the full path that would run, or nil

time

now() and monotonic() need the clock member of host access. parse needs the zones member when its pattern names a time zone, and nothing otherwise. format needs nothing.

FunctionReturns
now()whole seconds since 1970
format(seconds [, pattern])text in UTC; the default is like 2023-11-14T22:13:20Z
parse(text [, pattern])seconds since 1970
monotonic()a reading in seconds, for measuring time between two readings

hash

A relative path for hash_file also needs the cwd member of host access.

FunctionGrantReturns
sha256(text)nonehex
sha1(text)nonehex; for compatibility with existing names only
hex(text)nonethe bytes of text as hex
hash_file(p)readthe SHA-256 of the file, as hex

stdio

read and lines need the stdin member of host access, write needs stdout, and error needs stderr. isatty needs the member for the stream it names.

FunctionReturns
read()all of standard input
lines()all of standard input, as a list of lines
write(text)nothing; writes to standard output with nothing added
error(text)nothing; writes to standard error with nothing added
isatty([stream])whether "stdin", "stdout" (the default) or "stderr" is a terminal

hook

payload() needs the stdin member of host access. context and emit need stdout.

FunctionReturns
payload()standard input decoded as JSON; an empty table for empty input
context(event, text)nothing; prints the reply that adds text to the agent's context
emit(value)nothing; prints value as JSON

ext

No grant needed. Only useful inside a registered extension.

FunctionReturns
on(event, handler)nothing; registers handler for an event the host declared
granted()the grants and limits this script actually received