How it works
What SCUA does differently, in twelve diagrams.
Most of SCUA reads like the scripting languages you know. These are the parts that work differently underneath. Each diagram plays once when it scrolls into view, and can be replayed.
1. State that moves
Running state is one block of bytes
A SCUA program is made of partitions. Each keeps everything it owns in one region of memory, and the references inside that region are relative, so they stay valid wherever the region is placed. Saving a partition is copying those bytes. Loading one on another machine is copying them back.
There is no save code to write and none to forget to update. For data that must outlive the code that made it, a separate typed save carries a version number, is checked as it loads, and is upgraded by the migrate hooks you write.
2. Sessions that sleep
While a session waits, it can be a stored object
Because a session is one block of bytes, a host can freeze it, drop it from memory and keep the blob in object storage. When a message arrives the host loads it again. The script does not know it happened.
The manual's measurements, on Apple silicon: a session holding 16 records freezes to about 7 KB in a few thousandths of a millisecond. One holding 32,768 records is about 8 MB and takes about 3 ms each way.
3. Access by grant
A script starts with nothing, and is given what it needs
Files, the network, the environment, the terminal, running other programs, opening a port: each is a separate capability, and none is on by default. A grant can be narrow. One folder, a list of host names, one address to bind.
Grants come from command-line flags, from a permissions file, or from the host program when
SCUA is embedded. In the file, false is a refusal that --allow-all
cannot override. A project's own manifest never grants anything.
4. Budgets
Untrusted code runs on a work and memory budget
A sandbox compiles source at run time into a partition with no capabilities. It also gets a
count of operations it may run each turn and a cap on memory. When either runs out the code is
stopped from outside, and the caller receives an error value whose kind says which limit was hit: out_of_fuel or out_of_memory.
The same limits exist for whole programs: --max-ops for one turn,
--max-total-ops for the run, and --max-mem for the memory of the
program and all its actors.
5. Actors
No shared state, so no locks
A partition's state is private and its handlers run one message at a time. Messages are copied, so two partitions never hold the same mutable value. That is what lets the runtime put partitions on different cores without your code taking a lock.
tell sends and moves on. ask waits for the reply and takes a timeout.
A new partition costs about 2.3 KB, and one that has handled a message about 12 KB.
6. Requests that wait
A handler that waits does not hold the thread
The HTTP server runs each request with its own state, as if in a partition of its own. When a
handler waits on a database, a file or another service, it steps aside and the server answers
other requests. The handler is an ordinary function, with no async or
await.
7. Views by audience
Each field says who may see it
A record field can carry a gate, which names the audiences allowed to see it.
project builds the view for one audience, through nested records and lists. A
field the audience may not see is left out of the result, so it is not in what you send.
8. Inside a frame
The host program stays in charge of time
Embedded in a C or C++ program, SCUA does nothing until it is called. The host loads a script once, calls into it when it wants, and decides when the scripts' pending turns run. Scripts reach the host through the functions it chose to expose.
9. One record per tool
The schema and the checks come from one declaration
A command-line tool declares its arguments as a record. scua schema turns that
record into the JSON Schema a model reads, and sys.parse_args checks what arrives
against the same record before the tool's own code runs.
10. Layered files
Patches and mods override files by name
Paths that start with res: are the program's shipped data: levels, templates,
schemas. They are read from a stack of layers, a folder in development and pack files in a
release, and each layer mounted later sits above the ones before it.
Resources are read-only and are kept apart from the user's files, so a user's folder can never replace what the program shipped.
11. Speed
An interpreter at Lua's pace, and a JIT on top
Every program starts on the interpreter. Loops and functions that run often are compiled to
native code while the program runs, on x86-64 and ARM64. The JIT is on by default, and
--jit=off turns it off.
The three rows above come from the ten-row "realistic" tier of our suite. Across all ten, SCUA with the JIT took 0.64 times as long as LuaJIT on this machine, and the interpreter 0.85 times as long as Lua 5.4. In the tier of everyday shapes the other tiers missed, SCUA took 1.15 times as long as LuaJIT.
12. Packages
Installing a package cannot run code on your machine
In many languages a package can run its own script the moment you install it. SCUA's package manager only downloads files and checks them. It records a hash for every file, and the runtime checks the files against that record each time the program runs.
See it run
The playground runs the real compiler in your browser.