The Lua sandbox
Your app runs in Lua 5.5 with the parts that reach outside the app left
out. It reaches files, other apps and the screen only through
datumhue.* and the handles it is given.
What differs from plain Lua
Most Lua code runs as it would anywhere else: string, table, math,
utf8 and coroutines are all there, and both string.sub(s, 1, 3) and
s:sub(1, 3) work. Lua standard library
lists every global your app starts with. These parts differ:
| Part | In your app |
|---|---|
os, io, dofile, loadstring | not there: files come through the handles in datumhue.args, and time from datumhue.time |
require | loads the modules of your own package and of the packages it depends on, never a file by path (Modules and dependencies) |
load | compiles text only: a binary chunk returns nil and a message |
math.random | each app has a generator of its own; math.randomseed makes its sequence repeat |
__gc | a finalizer runs some time after nothing reaches its table, as in Lua; when your app ends itself, those of the tables it still has run once, and when it crashes or another app ends it, none run |
Compiled Lua loads only from the Lua files of a sealed package. Code
your app passes to datumhue.app.spawn as code, or loads from a
granted file with Dir:require or File:require, compiles as text, as
load compiles it.
One app, one Lua
Each app has a Lua state of its own. Globals, modules and random numbers are never shared between apps, and nothing your app sets is seen by another. Apps that need to share data send messages or share documents (Messages, events and shared state).
Every app runs in the same workstation process, kept apart by the
sandbox rather than by the operating system. Every app's Lua memory but
the first app's has a limit, and the data an app holds through handles,
such as images and data tables, is outside it, so one app can still use
up the workstation's memory and stall the others. A string that would
take your app past its limit, made by string.rep, another string
function, table.concat or .., raises not enough memory before it is
made, and pcall catches it.
A coroutine works as in plain Lua, with one difference: a suspending call inside it pauses your whole app, not just the coroutine (Waiting).
See also
Reference used on this page: datumhue.args datumhue.time datumhue.app.spawn Dir:require File:require