Expand description
Rhai engine construction for the plugin runtime.
build_engine returns a single shared Arc<rhai::Engine>
configured per docs/specs/plugin-api.md §Resource ceilings and
§Host-registered APIs. Every plugin segment invokes call_fn on
this shared engine with its compiled AST; the engine is not
recreated per plugin or per render.
Sandboxing posture (plugin-api.md §Requirements → Functional):
- No filesystem or network functions registered → unknown-symbol
errors at script parse/runtime for any
fs::*/http::*call. importandevalsymbols disabled → scripts cannot load other files or compile strings at runtime.- Resource limits cap operations, call depth, expression nesting, and string / array / map size.
Wallclock-timeout enforcement (via on_progress) is the segment
wrapper’s job — it owns the per-render Instant — not the engine’s.
This module enforces operation-count limits only.
Constants§
- DEFAULT_
RENDER_ DEADLINE_ MS - Default per-render wallclock budget per
plugin-api.md§Resource ceilings. - LOG_
LINES_ PER_ PLUGIN - Maximum
log()lines per plugin per process. Higher counts get silently dropped to keep a chatty plugin from flooding stderr. - MAX_
ARRAY_ SIZE - Max length of any rhai array.
- MAX_
CALL_ LEVELS - Max call depth for user-defined functions.
- MAX_
EXPR_ DEPTH - Max expression nesting (functions, other).
- MAX_
MAP_ SIZE - Max entry count of any rhai map.
- MAX_
OPERATIONS - Max script operations per plugin invocation.
- MAX_
STRING_ SIZE - Max length of any rhai string.
Functions§
- build_
engine - Build the shared rhai engine used by every plugin segment. Returns
an
Arcso the consumer’s layout engine can clone cheaply into each segment adapter that wraps acrate::CompiledPlugin. The engine is immutable after this call. - current_
plugin_ id_ snapshot - Snapshot of the current thread’s
CURRENT_PLUGIN_ID. Same niche asrender_deadline_snapshot. - install_
warn_ emitter - Install the host’s warn-emitter. The
OnceLockkeeps the first installation authoritative so consumers likelinesmith-core::runtime::plugins::load_pluginscan call this from aOnce::call_oncewithout worrying about racing tests. - is_
deadline_ abort - True when
errwas produced by the per-render wallclock deadline aborting the script (the engine’son_progresscallback). Lets the consumer-side segment wrapper distinguish a host-imposed timeout from a script-issuedthrow/runtime error without reaching for the host-only marker type directly. - render_
deadline_ snapshot - Snapshot of the current thread’s
RENDER_DEADLINE. Used by the segment wrapper’sdebug_assert!leak-check and by tests; the production render path doesn’t need to read the deadline back. - set_
current_ plugin_ id - Tag the active plugin so the host
log()function can attribute output for rate-limiting. PassNoneto clear after the render. - set_
render_ deadline - Install a per-render deadline visible to the engine’s
on_progresscallback. PassNoneto clear after the render completes.