Skip to main content

MacroRuntime

Struct MacroRuntime 

Source
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

Source

pub fn new(limits: Limits) -> Self

Creates a runtime with the given resource limits and an empty helper set.

Source

pub fn set_helpers(&mut self, helpers: Helpers)

Replaces the helper surface (constant objects) used by subsequent invocations.

Source

pub fn limits(&self) -> &Limits

The configured resource limits.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Debug for MacroRuntime

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.