diff --git a/src/vm.ts b/src/vm.ts index 9294a35..e0b122e 100644 --- a/src/vm.ts +++ b/src/vm.ts @@ -11,22 +11,25 @@ import { */ export type ScriptType = "action" | "render"; -export type Proc = (state: Vm, argv: TextPiece[]) => TextPiece; +export type Proc = ( + state: Vm, + argv: TextPiece[] +) => TextPiece; /** * State for running a script in. */ -export type Vm = { +export type Vm = { /** Mutability status */ mode: ScriptType; /** Implementations of commands scripts can run */ - commands: Record; + commands: Record>; /** Markup to render / output */ output: string; -}; +} & Context; -function evaluateWord( - state: Vm, +function evaluateWord( + state: Vm, word: Word | InterpolatedPiece ): TextWord | BareWord | HtmlWord { if ("bare" in word || "text" in word || "html" in word) { @@ -50,8 +53,8 @@ function evaluateWord( * @param onReturn callback optionally invoked with the return word for each top-level command (not triggered by command substitutions) * @returns the return word of the final command in the script, or empty text if the script is empty. */ -export function runNoctl( - state: Vm, +export function runNoctl( + state: Vm, script: Script, onReturn?: (word: TextPiece) => void ): TextPiece {