Skip to main content

Module engine

Module engine 

Source
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.
  • import and eval symbols 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 Arc so the layout engine can clone cheaply into each RhaiSegment. The engine is immutable after this call.
set_current_plugin_id
Tag the active plugin so the host log() function can attribute output for rate-limiting. Pass None to clear after the render.
set_render_deadline
Install a per-render deadline visible to the engine’s on_progress callback. Pass None to clear after the render completes.