@@ -82,14 +82,19 @@ export class Interpreter {
8282 }
8383
8484 async evalAsync ( codeOrAst : string | AstBlock , scope : Record < string , unknown > = { }
85- , entryFunctionName : string = '' , moduleName : string = 'main.jspy' ) : Promise < unknown > {
85+ , entryFunctionName : string = '' , moduleName : string = 'main.jspy'
86+ , ctxInitialized ?: ( ctx : BlockContext ) => void ) : Promise < unknown > {
8687 const ast = ( typeof codeOrAst === 'string' ) ? this . parse ( codeOrAst as string , moduleName ) : codeOrAst as AstBlock ;
8788 const evaluator = new EvaluatorAsync ( ) ;
8889 const blockContext = {
8990 moduleName : moduleName ,
9091 blockScope : new Scope ( scope )
9192 } as BlockContext ;
9293
94+ if ( typeof ctxInitialized === 'function' ) {
95+ ctxInitialized ( blockContext ) ;
96+ }
97+
9398 blockContext . blockScope . set ( 'printExecutionContext' , ( ) => console . log ( blockContext . blockScope . getScope ( ) ) ) ;
9499 blockContext . blockScope . set ( 'getExecutionContext' , ( ) => blockContext . blockScope . getScope ( ) ) ;
95100 this . _lastExecutionContext = blockContext . blockScope . getScope ( ) ;
@@ -126,7 +131,7 @@ export class Interpreter {
126131 * Compatibility method (with v1). !
127132 */
128133 async evaluate ( script : string , context : object = { } , entryFunctionName : string = ''
129- , moduleName : string = 'main.jspy' ) : Promise < any > {
134+ , moduleName : string = 'main.jspy' , ctxInitialized ?: ( ctx : BlockContext ) => void ) : Promise < any > {
130135 if ( ! script || ! script . length ) { return null ; }
131136 const ast = this . parse ( script , moduleName ) ;
132137
@@ -138,7 +143,7 @@ export class Interpreter {
138143 ...context
139144 } as Record < string , unknown > ;
140145
141- return await this . evalAsync ( ast , globalScope , entryFunctionName , moduleName ) ;
146+ return await this . evalAsync ( ast , globalScope , entryFunctionName , moduleName , ctxInitialized ) ;
142147 }
143148
144149 registerPackagesLoader ( loader : PackageLoader ) : Interpreter {
0 commit comments