Interpreter

loreline.Interpreter (Class)

Main interpreter class for Loreline scripts. This class is responsible for executing a parsed Loreline script, managing the runtime state, and interacting with the host application through handler functions.

Instance Members

translations: Null<Map>

Optional translations map (localization key -> translated string literal). When set, evaluateString() substitutes tagged text with translated versions.


stringLiteralProcessors: Array<Function>

Pluggable processors that transform string literals before evaluation. Each processor receives an NStringLiteral and returns a (possibly transformed) NStringLiteral.


start(?beatName: String): Void

Starts script execution from the beginning or a specific beat.

Name Type Default Description
beatName String (optional) Optional name of the beat to start from. If null, execution starts from the first beat or a beat named "_" if it exists.

save(): SaveData
Returns
SaveData

restore(saveData: SaveData): Void

Restores the interpreter state from a SaveData object. This allows resuming execution from a previously saved state.

Name Type Description
saveData SaveData The SaveData object containing the serialized state

resume(): Void

Resumes execution after restoring state. This should be called after restore() to continue execution.


getCharacter(name: String): Any

Gets a character by name.

Name Type Description
name String The name of the character to get
Returns Description
Any The character's fields or null if the character doesn't exist

getCharacterField(character: String, name: String): Any

Gets a specific field of a character.

Name Type Description
character String The name of the character
name String The name of the field to get
Returns Description
Any The field value or null if the character or field doesn't exist

setCharacterField(character: String, name: String, value: Any): Void

Sets a specific field on a character.

Name Type Description
character String The name of the character
name String The name of the field to set
value Any The value of the field to set

getStateField(name: String): Any
Name Type
name String
Returns
Any

setStateField(name: String, value: Any): Void

Sets a state field by name, resolving from the current scope outward. Walks the execution stack from innermost scope to outermost to find the field, then falls back to the top-level state if not found anywhere.

Name Type Description
name String The name of the field to set
value Any The value to set

getTopLevelStateField(name: String): Any

Gets a field from the top-level state directly.

Name Type Description
name String The name of the field to get
Returns Description
Any The field value or null if the field doesn't exist

setTopLevelStateField(name: String, value: Any): Void

Sets a field on the top-level state directly.

Name Type Description
name String The name of the field to set
value Any The value to set

currentNode(): AstNode

Returns the current node being executed. During a dialogue callback, this returns the dialogue statement node. During a choice callback, this returns the choice statement node.

Returns Description
AstNode The current AST node or null if no node is being executed

currentNodeFilePath(rootPath: String): String

Returns the file path of the file containing the current node. Uses the Lens to walk up through import statements and resolve the path relative to the given root file path.

Name Type
rootPath String
Returns
String

resolveBeatByName(name: String, ?scopeLevel: Int = -1): Null<NBeatDecl>

Resolves a beat by name against the RUNTIME scope walk (registered nested beats first, then top-level beats). Only used as fallback for node-less contexts (function code, engine helpers); node-anchored resolution goes through resolveBeatRefFromNode (lexical).

Name Type Default
name String
scopeLevel Int -1
Returns
Null<NBeatDecl>

resolveBeatRefByName(name: String): Null<RuntimeBeatRef>

Resolves a beat by name like resolveBeatByName, but also builds the scope chain to capture for a beat reference: the resolution path from the root up to and including the declaring scope (empty for top-level beats). Used to create RuntimeBeatRef values.

Name Type
name String
Returns
Null<RuntimeBeatRef>

resolveBeatRefFromNode(name: String, node: Node): Null<RuntimeBeatRef>

Resolves a beat by name from the given node's LEXICAL position, using the same resolution as the editor (Lens): innermost enclosing beat outward, order-independent, nested beats shadowing outer and top-level ones. When the resolved beat's declaring scope is live on the stack, the returned reference captures that scope chain (like beat references do), so the beat keeps its lexical context when invoked.

Falls back to the runtime scope walk only when no node is available (function code and engine helpers).

Name Type Description
name String The beat name to resolve
node Node The node used as lexical anchor (null in node-less contexts)
Returns
Null<RuntimeBeatRef>

new(script: Script, handleDialogue: DialogueHandler, handleChoice: ChoiceHandler, handleFinish: FinishHandler, ?options: InterpreterOptions): Void

Creates a new Loreline script interpreter.

Name Type Default Description
script Script The parsed script to execute
handleDialogue DialogueHandler Function to call when displaying dialogue text
handleChoice ChoiceHandler Function to call when presenting choices
handleFinish FinishHandler Function to call when execution finishes
options InterpreterOptions (optional) Additional options

Private Members

script: Script

The script being executed.


handleDialogue: DialogueHandler

User-defined dialogue handler, which takes care of displaying the dialogues.


handleChoice: ChoiceHandler

User-defined choice handler, which takes care of displaying the choices and providing a response to the interpreter.


handleFinish: FinishHandler

User-defined finish handler, which is called when the current execution has finished.


topLevelState: RuntimeState

The top level state, which is shared across the whole script execution.


topLevelCharacters: Map

Top level characters can be referenced and their state can also be modified from anywhere in the script.


topLevelBeats: Map

All the top level beats available, by beat name (their identifier in the script).


States associated to a specific node id. These are persistent, like the top level state, but are only available from where they have been declared and the sub-scopes. If some state fields already existed in a parent scope, the parent ones will be shadowed by the child ones.


topLevelFunctions: Map

Top level functions available by default in this script.


stringHelpers: Map

arrayHelpers: Map

mapHelpers: Map

beatHelpers: Map

builtins: Functions

Built-in functions instance, giving access to RNG for alternative blocks.


The current execution stack, which consists of scopes added on top of one another. Each scope can have its own local beats and temporary states.


lens: Lens

The lens instance allowing to get more information about the AST.


strictAccess: Bool

Tells whether access is strict or not. If set to true, trying to read or write an undefined variable will throw an error.


currentScope: RuntimeScope

Current scope associated with current execution state.


currentInsertion: RuntimeInsertion

Current insertion associated with current scope or a parent scope, with current execution state.


nextScopeId: Int

The next scope id to assign when pushing a new scope. Every time we reset the stack, this counter is also reset.


nextInsertionId: Int

The next insertion id to assign when creating a new insertion. Every time we reset the stack, this counter is also reset.


syncCallbacks: Array<Function>

List of pending callbacks that should be run synchronously.


flushing: Bool

Internal flag to know if we are currently flushing sync callbacks (to prevent unexpected recursive flushes).


finishTrigger: EvalNext

Keep track of which callback is the one that would trigger finish.


beatToResume: NBeatDecl

When loading saved data and failing to restore a full stack of scope, this contains the beat to resume as fallback. That beat will always be a top level beat.


pendingChoiceOptions: Array<ChoiceOption>

When a choice with insertions is waiting for user input, this holds the collected options. Persisted in save data so that on restore, insertion bodies are not re-evaluated (which would cause side effects to run twice).


debug(expr: Dynamic): Dynamic
Name Type
expr Dynamic
Returns
Dynamic

insertionAtOrBelow(scopeLevel: Int): RuntimeInsertion

Nearest insertion carried by a scope at or below the given stack level.

Name Type
scopeLevel Int
Returns
RuntimeInsertion

removeCurrentInsertion(): Void

customCreateFields(interpreter: Interpreter, type: String, node: Node): Any

A custom instanciator to create fields objects.

Name Type
interpreter Interpreter
type String
node Node
Returns
Any

inferImplicitCharactersFromRootBeat(): Void

Registers an implicit (empty) character for every dialogue speaker mentioned inside the default unnamed beat ("_"), unless a top-level character or state field already uses that name. Runs after explicit declarations are initialized so it never overrides them.


resumeFromLevel(scopeLevel: Int, next: Function): Void
Name Type
scopeLevel Int
next Function

eachResolutionScope(startIndex: Int, visit: Function): Void

Walks scopes for name resolution, innermost to outermost, starting at startIndex (-1 for the innermost scope). When a scope carries a captured chain (the closure boundary of a beat invoked through a beat reference), the walk diverts into that chain (innermost to outermost, recursively) and then STOPS, skipping the scopes below the boundary: resolution inside a ref-invoked beat is lexical, not dynamic. visit returns true to stop the walk.

Name Type
startIndex Int
visit Function

walkResolutionScopes(scopes: Array<RuntimeScope>, startIndex: Int, visit: Function): Void
Name Type
scopes Array<RuntimeScope>
startIndex Int
visit Function

serializeScope(scope: RuntimeScope, insertions: Dynamic): SaveDataScope

Serializes a scope to save data.

Name Type Description
scope RuntimeScope The scope to serialize
insertions Dynamic
Returns Description
SaveDataScope The serialized scope data

serializeInsertion(insertion: RuntimeInsertion, insertions: Dynamic): Null<Int>
Name Type
insertion RuntimeInsertion
insertions Dynamic
Returns
Null<Int>

serializeChoiceOption(option: ChoiceOption, insertions: Dynamic): SaveDataChoiceOption
Name Type
option ChoiceOption
insertions Dynamic
Returns
SaveDataChoiceOption

serializeTextTag(tag: TextTag): SaveDataTextTag
Name Type
tag TextTag
Returns
SaveDataTextTag

serializeState(state: RuntimeState): SaveDataState

Serializes a state to save data.

Name Type Description
state RuntimeState The state to serialize
Returns Description
SaveDataState The serialized state data

serializeCharacters(): Dynamic

Serializes all top-level characters to save data.

Returns Description
Dynamic Object mapping character names to their serialized states

serializeNodeStates(): Dynamic

Serializes all node states to save data.

Returns Description
Dynamic Object mapping node IDs to their serialized states

serializeBeatReference(beat: NBeatDecl): SaveDataBeat

Serializes a beat reference for save data.

Name Type Description
beat NBeatDecl The beat to reference
Returns Description
SaveDataBeat The serialized beat reference

serializeNodeReference(node: AstNode): SaveDataNode

Serializes a node reference for save data.

Name Type Description
node AstNode The node to reference
Returns Description
SaveDataNode The serialized node reference

serializeCharacter(character: RuntimeCharacter): SaveDataCharacter

Serializes a character for save data.

Name Type Description
character RuntimeCharacter The character to serialize
Returns Description
SaveDataCharacter The serialized character data

serializeFields(fields: Any, ?originalFields: Any): SaveDataFields

Serializes fields for save data. Only fields that have changed from their original values are included.

Name Type Default Description
fields Any The fields to serialize
originalFields Any (optional) The original field values for comparison
Returns Description
SaveDataFields The serialized fields data

serializeValue(value: Any): Null<Any>

Serializes a value for save data. Handles recursive serialization of objects and arrays.

Name Type Description
value Any The value to serialize
Returns Description
Null<Any> The serialized value

resumeNode(node: AstNode, scopeLevel: Int, next: Function): Void

Core function that resumes execution from a given scope. Works by recreating the execution flow as if we had been running from the beginning.

Name Type Description
node AstNode The node to resume from
scopeLevel Int The scope level to resume at
next Function Callback to call when the node execution completes

resumeNodeBody(node: AstNode, scopeLevel: Int, body: Array<AstNode>, next: Function): Void

Resumes execution of a node body.

Name Type Description
node AstNode The node containing the body
scopeLevel Int The scope level to resume at
body Array<AstNode> The body to execute
next Function Callback to call when the body execution completes

resumeBeatRun(beat: NBeatDecl, scopeLevel: Int, next: Function): Void

Resumes execution of a beat.

Name Type Description
beat NBeatDecl The beat to resume
scopeLevel Int The scope level to resume at
next Function Callback to call when the beat execution completes

resumeChoiceOption(option: NChoiceOption, scopeLevel: Int, next: Function): Void

Resumes execution of a choice option.

Name Type Description
option NChoiceOption The choice option to resume
scopeLevel Int The scope level to resume at
next Function Callback to call when the option execution completes

resumeChoice(choice: NChoiceStatement, scopeLevel: Int, next: Function): Void

Resumes execution of a choice

Name Type
choice NChoiceStatement
scopeLevel Int
next Function

resumeIf(ifStmt: NIfStatement, scopeLevel: Int, next: Function): Void

Resumes execution of an if statement.

Name Type Description
ifStmt NIfStatement The if statement to resume
scopeLevel Int The scope level to resume at
next Function Callback to call when the if statement execution completes

resumeAlternative(alt: NAlternative, scopeLevel: Int, next: Function): Void

Resumes execution of an alternative block.

Name Type Description
alt NAlternative The alternative node to resume
scopeLevel Int The scope level to resume at
next Function Callback to call when execution completes

resumeCall(call: NCall, scopeLevel: Int, next: Function): Void

Resumes execution of a beat call.

Name Type Description
call NCall The call node to resume
scopeLevel Int The scope level to resume at
next Function Callback to call when the call execution completes

resumeBeatCall(call: NBeatCall, scopeLevel: Int, next: Function): Void

Resumes execution through a dynamic beat call statement (beat(expr)). The restored child scope already knows which beat it was running (restored by node id), so no expression re-evaluation is needed.

Name Type Description
call NBeatCall The beat call node to resume
scopeLevel Int The scope level to resume at
next Function Callback to call when the call execution completes

restoreStack(savedStack: Array<SaveDataScope>, ?savedInsertions: Dynamic, ?restoredInsertions: Map): Bool

Restores the execution stack from saved data.

Name Type Default Description
savedStack Array<SaveDataScope> The saved stack data
savedInsertions Dynamic (optional) The saved insertions map (keyed by insertion ID)
restoredInsertions Map (optional)
Returns Description
Bool True if the stack was restored successfully, false otherwise

restoreScopeItem(savedScope: SaveDataScope, savedInsertions: Dynamic, restoredInsertions: Map): RuntimeScope

Restores a single scope from saved data, including its insertion reference. Used by both restoreStack() (for the main stack) and restoreInsertion() (for insertion stacks).

Name Type Description
savedScope SaveDataScope The saved scope data
savedInsertions Dynamic The saved insertions map
restoredInsertions Map Cache of already-restored insertions (for circular reference handling)
Returns Description
RuntimeScope The restored scope, or null if restoration failed

restoreInsertion(insertionId: Int, savedInsertions: Dynamic, restoredInsertions: Map): RuntimeInsertion

Restores a RuntimeInsertion from serialized data. Uses a cache to handle circular references (insertion.stack contains scopes that reference the same insertion).

Name Type Description
insertionId Int The insertion ID to restore
savedInsertions Dynamic The saved insertions map
restoredInsertions Map Cache of already-restored insertions
Returns Description
RuntimeInsertion The restored insertion, or null if not found

restoreChoiceOption(saved: SaveDataChoiceOption, savedInsertions: Dynamic, restoredInsertions: Map): ChoiceOption

Restores a ChoiceOption from serialized data.

Name Type Description
saved SaveDataChoiceOption The saved choice option data
savedInsertions Dynamic The saved insertions map
restoredInsertions Map Cache of already-restored insertions
Returns Description
ChoiceOption The restored choice option, or null if node resolution failed

restoreBeatToResume(savedStack: Array<SaveDataScope>): NBeatDecl

Finds the top-level beat to resume from if stack restoration fails.

Name Type Description
savedStack Array<SaveDataScope> The saved stack data
Returns Description
NBeatDecl The beat to resume from, or null if none can be found

restoreNode(savedNode: SaveDataNode, savedBeatId: NodeId, beat: NBeatDecl): AstNode

Restores a node from a saved reference.

Name Type Description
savedNode SaveDataNode The saved node reference
savedBeatId NodeId The ID of the beat in the saved data
beat NBeatDecl The restored beat
Returns Description
AstNode The restored node, or null if it couldn't be found

restoreBeat(beatRef: SaveDataBeat): NBeatDecl

Restores a beat from a saved reference.

Name Type Description
beatRef SaveDataBeat The saved beat reference
Returns Description
NBeatDecl The restored beat, or null if it couldn't be found

restoreState(state: RuntimeState, data: SaveDataState): RuntimeState

Restores a state from saved data.

Name Type Description
state RuntimeState The state to restore into, or null to create a new one
data SaveDataState The saved state data
Returns Description
RuntimeState The restored state

restoreCharacters(data: Dynamic): Void

Restores characters from saved data.

Name Type Description
data Dynamic The saved character data

restoreNodeStates(data: Dynamic): Void

Restores node states from saved data.

Name Type Description
data Dynamic The saved node state data

restoreCharacter(character: RuntimeCharacter, data: SaveDataCharacter): RuntimeCharacter

Restores a character from saved data.

Name Type Description
character RuntimeCharacter The character to restore into, or null to create a new one
data SaveDataCharacter The saved character data
Returns Description
RuntimeCharacter The restored character

restoreFields(target: Any, savedFields: SaveDataFields): Any

Restores fields from saved data.

Name Type Description
target Any The target object to restore into, or null to create a new one
savedFields SaveDataFields The saved field data
Returns Description
Any The object with restored fields

restoreValue(value: Any): Any

Restores a value from its saved form. Handles recursive restoration of objects and arrays.

Name Type Description
value Any The saved value
Returns Description
Any The restored value

initializeTopLevelFunctions(functions: FunctionsMap): Void

Initializes top-level functions available to the script. This includes built-in functions and any user-provided functions.

Name Type Description
functions FunctionsMap Optional map of additional functions to make available

registerTopLevelFunction(key: String, func: Any): Void

Registers a single host-provided function under key.

Host functions registered via the public API are documented to receive (interpreter, args). The core calls functions with the script arguments spread positionally (like built-ins), so on bindings without a native adapter we wrap each one to re-collect those into an array and prepend the interpreter. Bindings with their own adapter (JVM/C#/C++) don't set the loreline_auto_wrap_functions define and store the function as-is.

Name Type
key String
func Any

initializeStringLiteralProcessors(processors: Array<Function>): Void
Name Type
processors Array

initializeTopLevelFunction(func: NFunctionDecl): Void
Name Type
func NFunctionDecl

wrapNext(cb: Function): EvalNext

Wraps a callback function to control whether it executes synchronously or asynchronously. This is crucial for managing the execution flow of the script.

Name Type Description
cb Function The callback to wrap
Returns Description
EvalNext An EvalNext object controlling the callback's execution

flush(): Void

Flushes all pending synchronous callbacks. This ensures that all pending operations are completed before continuing.


pop(): Bool

Pops the top scope from the execution stack.

Returns Description
Bool True if a scope was popped, false if the stack was already empty

push(scope: RuntimeScope): Void

Pushes a new scope onto the execution stack.

Name Type Description
scope RuntimeScope The scope to push

initializeTopLevelState(state: NStateDecl): Void

Initializes a top-level state declaration. Evaluates all fields and stores their values.

Name Type Description
state NStateDecl The state declaration to initialize

initializeTopLevelBeat(beat: NBeatDecl): Void

Initializes a top-level beat declaration. Registers the beat in the top-level beats map.

Name Type Description
beat NBeatDecl The beat declaration to initialize

initializeTopLevelCharacter(character: NCharacterDecl): Void

Initializes a top-level character declaration. Creates a new character state and evaluates all fields.

Name Type Description
character NCharacterDecl The character declaration to initialize

initializeState(state: NStateDecl, scope: RuntimeScope): Void

Initializes a state declaration within a scope. Evaluates all fields and stores their values.

Name Type Description
state NStateDecl The state declaration to initialize
scope RuntimeScope The scope in which to initialize the state

evaluateBeatArgs(beat: NBeatDecl, args: Null<Array<NExpr>>, pos: Position): Null<Array<Any>>

Evaluates transition/insertion/call arguments in the caller scope and checks arity against the target beat's declared parameters. Returns the evaluated values, or null when there are no arguments.

Name Type Description
beat NBeatDecl The target beat
args Null<Array<NExpr>> The argument expressions, if any
pos Position Position used to report arity errors
Returns
Null<Array<Any>>

seedBeatParams(scope: RuntimeScope, beat: NBeatDecl, values: Null<Array<Any>>): Void

Seeds beat parameters as beat-scoped temporary state on the given scope. Missing arguments get their default value (evaluated now, in the new scope, so defaults can read outer state), or null.

Name Type Description
scope RuntimeScope The freshly pushed scope of the beat being run
beat NBeatDecl The beat being run
values Null<Array<Any>> Evaluated argument values, or null

finish(): Void

Finishes script execution and calls the finish handler.


transitionToBeat(beat: NBeatDecl, ?argValues: Array<Any>, ?capturedChain: Array<RuntimeScope>): Void

Transitions to a new beat, clearing the current execution stack.

Name Type Default Description
beat NBeatDecl The beat to transition to
argValues Array<Any> (optional)
capturedChain Array<RuntimeScope> (optional)

evalNode(node: AstNode, next: Function): Void

Evaluates a node, dispatching to the appropriate handler based on node type.

Name Type Description
node AstNode The node to evaluate
next Function Callback to call when evaluation completes

evalBeatDecl(beat: NBeatDecl, next: Function): Void

Evaluates a beat declaration. Adds the beat to the current scope so it can be referenced by other nodes.

Name Type Description
beat NBeatDecl The beat declaration to evaluate
next Function Callback to call when evaluation completes

evalNodeBody(beat: NBeatDecl, node: AstNode, body: Array<AstNode>, ?insertion: RuntimeInsertion, ?argValues: Array<Any>, ?capturedChain: Array<RuntimeScope>, next: Function): Void

Evaluates a node body by creating a new scope and executing each node in sequence.

Name Type Default Description
beat NBeatDecl The parent beat
node AstNode The node containing the body
body Array<AstNode> The body to execute
insertion RuntimeInsertion (optional) If any, the insertion related to this evaluation
argValues Array<Any> (optional)
capturedChain Array<RuntimeScope> (optional)
next Function Callback to call when execution completes

evalBeatRun(beat: NBeatDecl, next: Function, ?argValues: Array<Any>, ?capturedChain: Array<RuntimeScope>): Void

Evaluates a beat by executing its body.

Name Type Default Description
beat NBeatDecl The beat to evaluate
next Function Callback to call when evaluation completes
argValues Array<Any> (optional)
capturedChain Array<RuntimeScope> (optional)

evalStateDecl(state: NStateDecl, next: Function): Void

Evaluates a state declaration. Initializes the state fields with their evaluated values.

Name Type Description
state NStateDecl The state declaration to evaluate
next Function Callback to call when evaluation completes

evalText(text: NTextStatement, next: Function): Void

Evaluates a text statement by evaluating the content and calling the dialogue handler.

Name Type Description
text NTextStatement The text statement to evaluate
next Function Callback to call when evaluation completes

evalDialogue(dialogue: NDialogueStatement, next: Function): Void

Evaluates a dialogue statement by evaluating the content and calling the dialogue handler.

Name Type Description
dialogue NDialogueStatement The dialogue statement to evaluate
next Function Callback to call when evaluation completes

evalChoice(choice: NChoiceStatement, next: Function): Void

Evaluates a choice statement by evaluating the options and calling the choice handler.

Name Type Description
choice NChoiceStatement The choice statement to evaluate
next Function Callback to call when evaluation completes

presentChoice(choice: NChoiceStatement, options: Array<ChoiceOption>, next: Function): Void

Phase 2 of choice evaluation: present collected options to the user and handle their selection.

Name Type Description
choice NChoiceStatement The AST choice statement node
options Array<ChoiceOption> The collected choice options
next Function Callback to call when evaluation completes

evalChoiceOptionsAndInsertions(beat: NBeatDecl, choice: NChoiceStatement, result: Array<ChoiceOption>, next: Function, ?startIndex: Int, ?isChoiceRoot: Bool = true): Void
Name Type Default
beat NBeatDecl
choice NChoiceStatement
result Array<ChoiceOption>
next Function
startIndex Int (optional)
isChoiceRoot Bool true

evalInsertion(insertion: RuntimeInsertion, next: Function): Void
Name Type
insertion RuntimeInsertion
next Function

evalBeatCall(call: NBeatCall, next: Function): Void

Evaluates a dynamic beat call statement: beat(expr, args...). Runs the resolved beat as a stack-preserving call, carrying the captured scope chain when the target is a beat reference.

Name Type Description
call NBeatCall The beat call node to evaluate
next Function Callback to call when evaluation completes

evalChoiceOption(option: NChoiceOption, next: Function): Void

Evaluates a choice option by executing its body.

Name Type Description
option NChoiceOption The choice option to evaluate
next Function Callback to call when evaluation completes

evalIf(ifStmt: NIfStatement, next: Function): Void

Evaluates an if statement by evaluating the condition and executing the appropriate branch.

Name Type Description
ifStmt NIfStatement The if statement to evaluate
next Function Callback to call when evaluation completes

evalAlternative(alt: NAlternative, next: Function): Void

Evaluates an alternative block (sequence, cycle, once, pick, shuffle).

Name Type Description
alt NAlternative The alternative node to evaluate
next Function Callback to call when evaluation completes

evalShuffledItems(alt: NAlternative, indices: Array<Int>, idx: Int, next: Function): Void

Executes alternative items in shuffled order, one at a time.

Name Type
alt NAlternative
indices Array<Int>
idx Int
next Function

getBeatVisitCount(beat: NBeatDecl): Int

Gets the visit count for a beat from nodeStates.

Name Type
beat NBeatDecl
Returns
Int

incrementBeatVisitCount(beat: NBeatDecl): Void

Increments the visit count for a beat in nodeStates.

Name Type
beat NBeatDecl

getAlternativeVisitCount(alt: NAlternative): Int

Gets the visit count for an alternative block from nodeStates.

Name Type
alt NAlternative
Returns
Int

setAlternativeVisitCount(alt: NAlternative, count: Int): Void

Sets the visit count for an alternative block in nodeStates.

Name Type
alt NAlternative
count Int

isChoiceOptionChosen(option: NChoiceOption): Bool

Returns whether a once-only choice option has already been chosen.

Name Type
option NChoiceOption
Returns
Bool

setChoiceOptionChosen(option: NChoiceOption): Void

Marks a once-only choice option as chosen in nodeStates.

Name Type
option NChoiceOption

evalAssignment(assign: NAssign, next: Function): Void

Evaluates an assignment by resolving the target, evaluating the value, and applying the assignment.

Name Type Description
assign NAssign The assignment to evaluate
next Function Callback to call when evaluation completes

isOriginalScriptExpression(expr: NExpr): Bool

Determines whether an expression is an "original script expression" - meaning it only depends on values directly present in the script and not on runtime state.

Original script expressions can be evaluated at parse time and safely stored as default values, as they don't depend on dynamic context like variables or function calls that might change during runtime.

Name Type Description
expr NExpr The expression to check
Returns Description
Bool True if the expression only depends on literal values in the script

isBeatCall(node: AstNode, ?scopeLevel: Int = -1): Bool

Determines if a node is a beat call. A beat call is a special function call that executes a beat instead of a normal function.

Name Type Default Description
node AstNode The node to check
scopeLevel Int -1 Optional scope level to search in (defaults to current scope)
Returns Description
Bool True if the node is a beat call

isDynamicCallForm(call: NCall): Bool

Returns true if the call is the dynamic call(target, args...) special form: a bare call identifier that isn't shadowed by any script binding.

Name Type
call NCall
Returns
Bool

captureChainForBeat(beat: NBeatDecl): Array<RuntimeScope>

Builds the scope chain to capture for a lexically resolved beat: the live scopes from root up to and including the beat's declaring scope, honoring closure boundaries. Returns an empty array when the beat is top-level or its declaring scope is not live (chainless).

Name Type
beat NBeatDecl
Returns
Array<RuntimeScope>

resolveDynamicBeatTarget(value: Any, node: AstNode): RuntimeBeatRef

Resolves a runtime value to a beat reference, for dynamic targets like beat(expr), -> beat(expr) and + beat(expr). Accepts a beat reference (keeps its captured chain), a beat value (wrapped without capture), or a string resolved lexically from the node's position (capturing the declaring chain when it is live, exactly like static name resolution).

Name Type Description
value Any The evaluated target value
node AstNode Node used as lexical anchor and to report errors
Returns
RuntimeBeatRef

beatNotFoundError(name: String, node: AstNode): RuntimeError

Builds the error for an unresolved beat name. When the name exists somewhere else in the script (another scope), the error teaches the beat-reference workflow instead of just failing.

Name Type
name String
node AstNode
Returns
RuntimeError

resolveBeatRefFromCall(call: NCall): Null<RuntimeBeatRef>

Resolves a call node to a beat reference if the call's target is a bare identifier naming a beat (lexical resolution from the call's position). This allows handling beat calls differently from regular function calls.

Name Type Description
call NCall The call node to resolve
Returns Description
Null<RuntimeBeatRef> The beat reference if found, null otherwise

evalCall(call: NCall, next: Function): Void

Evaluates a call node. If the call references a beat, it executes the beat. Otherwise, it evaluates it as a regular function call.

Name Type Description
call NCall The call node to evaluate
next Function Callback to call when evaluation completes

evalTransition(transition: NTransition): Void

Evaluates a transition node. Transitions cause execution to jump to a different beat, clearing the current execution stack.

Name Type Description
transition NTransition The transition node to evaluate

getTranslatedString(node: AstNode, str: NStringLiteral): NStringLiteral

If translations are available, checks for a hash comment on the node and returns the translated string literal if found. Otherwise returns the original string.

Walks the import ancestor chain from the node's own file up to root, trying each scoped key in turn. A translation defined in an ancestor's .<lang>.lor file applies to descendants that don't translate the same key themselves. Siblings (non-ancestor files) never share translations.

Name Type
node AstNode
str NStringLiteral
Returns
NStringLiteral

findHashCommentId(node: AstNode, str: NStringLiteral): Null<String>
Name Type
node AstNode
str NStringLiteral
Returns
Null<String>

evaluateString(str: NStringLiteral): AnonStruct

Evaluates a string literal into text with tags. This handles interpolation and tag processing.

Name Type Description
str NStringLiteral The string literal to evaluate
Returns Description
AnonStruct Object containing the evaluated text and any tags

pluralPipeProcess(str: NStringLiteral): NStringLiteral

Processes plural pipe syntax in string literal parts. Transforms word1|word2 and (text1|text2) patterns in Raw parts preceded by Expr parts into synthetic NCall nodes that invoke the plural() function.

Name Type
str NStringLiteral
Returns
NStringLiteral

rawTextHasUnescapedPipe(text: String): Bool
Name Type
text String
Returns
Bool

transformPipeRaw(text: String, countExpr: NExpr, pos: Position, parts: Array<NStringPart>): Void
Name Type
text String
countExpr NExpr
pos Position
parts Array<NStringPart>

makePluralCall(countExpr: NExpr, singular: String, pluralForm: String, pos: Position): NCall
Name Type
countExpr NExpr
singular String
pluralForm String
pos Position
Returns
NCall

stripStringIndent(content: String): String
Name Type
content String
Returns
String

stripStringComments(content: String): String
Name Type
content String
Returns
String

evaluateCondition(expr: NExpr): Bool

Evaluates a condition expression for an if statement or choice option. Converts the result to a boolean according to Loreline's rules.

Name Type Description
expr NExpr The condition expression to evaluate
Returns Description
Bool True if the condition evaluates to a truthy value

callFunctionValue(fn: Any, args: Array<Any>, pos: Position, next: Function): Any

Invokes an already-resolved function value with evaluated arguments. Handles async results and wraps errors, exactly like standalone function calls always did.

Name Type Description
fn Any The function value to invoke
args Array<Any> Evaluated argument values
pos Position Position used to report errors
next Function Optional callback for asynchronous execution
Returns Description
Any The result of the function call

resolvesExistingBinding(name: String): Bool

Returns true if the given bare identifier resolves to any existing binding: scope temporary state, node state, top level state field, character, function or beat. Unlike resolveAccess(), this never auto-creates anything and never throws.

Name Type
name String
Returns
Bool

evaluateDynamicCall(call: NCall, next: Function): Any

Evaluates the call(target, args...) special form: the first argument resolves to a FUNCTION (a function value, or a string naming one), called with the remaining arguments. Beats are rejected with a hint to use beat(...) instead.

Name Type Description
call NCall The call node (target is the bare call identifier)
next Function Optional callback for asynchronous execution
Returns Description
Any The function result

evaluateFunctionCall(call: NCall, next: Function): Any

Evaluates a function call in an expression context. If next is provided, the function may execute asynchronously. If next is null, the function must execute synchronously.

Name Type Description
call NCall The function call node to evaluate
next Function Optional callback for asynchronous execution
Returns Description
Any The result of the function call

evaluateArrayLiteral(expr: Array<Dynamic>): Any

Evaluates an array literal to a runtime array. Each element is evaluated recursively.

Name Type Description
expr Array<Dynamic> The array literal expression to evaluate
Returns Description
Any The resulting array

evaluateObjectLiteral(expr: Array<NObjectField>): Any

Evaluates an object literal to a runtime object. Each field value is evaluated recursively.

Name Type Description
expr Array<NObjectField> The object literal expression to evaluate
Returns Description
Any The resulting object

evaluateExpression(expr: NExpr): Any

Evaluates an expression to its runtime value. This is the core expression evaluation function that handles all expression types.

Name Type Description
expr NExpr The expression to evaluate
Returns Description
Any The runtime value of the expression

readAccess(access: Anonymous): Any

Reads the value from a runtime access. This handles field access, array access, character access, and function access.

Name Type Description
access Anonymous The runtime access to read
Returns Description
Any The value at the access location

writeAccess(access: Anonymous, value: Any): Void

Writes a value to a runtime access location. This handles field access and array access. Character and function access cannot be written to.

Name Type Description
access Anonymous The runtime access to write to
value Any The value to write

resolveAssignmentTarget(target: NExpr): Anonymous

Resolves an assignment target to a runtime access. This is used to determine where to write a value in an assignment.

Name Type Description
target NExpr The target expression to resolve
Returns Description
Anonymous The runtime access to write to

resolveAccess(access: NAccess, ?target: NExpr, name: String): Anonymous

Resolves an access expression to a runtime access. This handles finding variables, character fields, and functions in the appropriate scopes.

Name Type Default Description
access NAccess The access expression to resolve
target NExpr (optional) Optional target object for field access
name String The name to access
Returns Description
Anonymous The resolved runtime access

getTypeName(t: Anonymous): String

Helper for getting human-readable type names in errors

Name Type Description
t Anonymous The type to get a name for
Returns Description
String A human-readable name for the type

performOperation(op: Anonymous, left: Dynamic, right: Dynamic, pos: Position): Any

Performs a binary operation on two values. Handles arithmetic, comparison, and logical operations.

Name Type Description
op Anonymous The operator to apply
left Dynamic The left operand
right Dynamic The right operand
pos Position The source position for error reporting
Returns Description
Any The result of the operation

valueToString(value: Any): String

Converts a value to its string representation. Used for string interpolation and output.

Name Type Description
value Any The value to convert to a string
Returns Description
String The string representation of the value

valueToStringImpl(value: Any, seen: Array<Any>): String
Name Type
value Any
seen Array<Any>
Returns
String

printLoreline(node: Node): String
Name Type
node Node
Returns
String

Metadata

Name Parameters
:allow loreline.lorscript.Interp
:expose -