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

The Toolbox

Lua is a small language, and its standard library is small too. It has no JSON, no real regular expressions, no way to list a folder, and no way to run a program without going through a shell. Scripts written in plain Lua tend to fill those gaps by calling out to Python or sed, which brings back every problem airsl exists to solve.

So airsl adds twelve modules of its own, all under the airsstack table:

airsstack
├── text          json · regex
├── files         path · fs · glob
├── the system    env · proc
├── utilities     time · hash
└── the outside   stdio · hook · ext

json, regex and ext need nothing at all. The rest ask first, because they reach outside the script: the disk, the environment, other programs, the clock, the current folder, or the standard streams. Some ask for a grant of a place or a name. Others ask for a member of host access, a short list of things a script may use that confined holds and pure does not. Host access is described in chapter 3.

ModuleNeeds a grant?
json, regex, extnever
fsread or write grant, for every function; a relative path also needs cwd
envthe variable's name
procthe program's name
globonly glob.walk, which reads folders; a relative root also needs cwd
hashonly hash.hash_file, which reads a file; a relative path also needs cwd
pathonly path.absolute of a relative path: cwd
timenow and monotonic: clock. parse with a pattern that names a time zone: zones
stdioread, lines: stdin. write: stdout. error: stderr. isatty: the stream it asks about
hookpayload: stdin. emit, context: stdout

This chapter is a tour, one small example per page. For the full list of functions, see the module appendix. env and proc were covered in chapter 3, and ext belongs to chapter 8.

Throughout this chapter, local a = airsstack is used to keep lines short. It is an ordinary Lua variable that refers to the same table.