Skip to content

Eval and Imports

sarr-io edited this page Sep 20, 2026 · 4 revisions

Eval and Imports

Eval views

Trusted code selects a view from direct entry members:

local pa = require("pa")
local view = { read = self.read }
return pa.eval(view, sources, input)

Each view value must be the exact corresponding direct entry function. Aliases, arbitrary closures, nested paths, and imported functions are rejected. Passing self selects every direct member; the entry's root call is never selected.

Eval environment

Each source runs in a fresh restricted state. It receives:

local self, input = ...

The environment contains restricted base functions, math, string, table, and utf8. callable(table, function) installs only a locked __call metamethod. General metatable access, pa, package, filesystem, native and dynamic loaders, protected calls, and coroutines are unavailable.

require(name) resolves only caller-provided Imports. A source may return nil, a boolean, number, string, or acyclic table. Non-string results are rendered as Lua text.

Sources

The source table runs independently and concurrently, returning results in source order:

{
    { true,  "complete" },
    { false, "eval:2: unexpected symbol near ')'" },
}

Each result is a pcall-style { ok, value } tuple. On success, value is the rendered output; on failure, it is the diagnostic string. Ordinary source failures do not discard successful siblings. Cancellation, allocation, and runtime setup failures remain call-level failures. Diagnostics are bounded by the Eval state quota.

Imports

An Import is another configured Agent supplied by the embedder. Trusted code can load it with ordinary require:

local peer = require("peer")
return peer(input)

Eval can load the same Import by name. Its root call and direct members remain available. An Agent cannot import itself, and duplicate Import names are rejected. The embedder owns the actual Import graph and each Import's config.

Clone this wiki locally