pub struct MacroRuntime { /* private fields */ }Expand description
Reusable runtime for JavaScript-backed macros and post-compile hooks.
Each invocation spins up a fresh embedded engine instance (runtime +
context) with the configured Limits and helper surface, evaluates the
script, and tears the engine down. The runtime itself is reusable, but no
JavaScript state is shared across invocations.
Implementations§
Source§impl MacroRuntime
impl MacroRuntime
Sourcepub fn new(limits: Limits) -> Self
pub fn new(limits: Limits) -> Self
Creates a runtime with the given resource limits and an empty helper set.
Sourcepub fn set_helpers(&mut self, helpers: Helpers)
pub fn set_helpers(&mut self, helpers: Helpers)
Replaces the helper surface (constant objects) used by subsequent invocations.
Sourcepub fn run_macro(
&self,
source: &str,
args: &[MacroArg],
script_name: &str,
) -> Result<MacroResult, MacroError>
pub fn run_macro( &self, source: &str, args: &[MacroArg], script_name: &str, ) -> Result<MacroResult, MacroError>
Executes a macro script.
source is the script’s text (the file content the frontend resolved
from __script__("...")). args are injected as var declarations;
script_name is used for error attribution and must be the resolved
script path/name the frontend knows.
Returns the string completion value as the expanded text, or a structured error.
Sourcepub fn run_hook(
&self,
source: &str,
content: &str,
script_name: &str,
) -> Result<MacroResult, MacroError>
pub fn run_hook( &self, source: &str, content: &str, script_name: &str, ) -> Result<MacroResult, MacroError>
Executes a post-compile hook script against content.
Mirrors the OverPy #!postCompileHook ABI (src/compiler/tokenizer.ts):
the script receives the content JSON-escaped as
var content = "..."; and must return the transformed content as a
string. This works against synthetic/content inputs now; wiring to
actual Workshop emission is lowering-dependent.