@@ -57,7 +57,7 @@ export class Interpreter {
5757 eval (
5858 codeOrAst : string | AstBlock ,
5959 scope : Record < string , unknown > = { } ,
60- entryFunctionName = '' ,
60+ entryFunctionName : string | [ string , ... unknown [ ] ] = '' ,
6161 moduleName = 'main.jspy'
6262 ) : unknown {
6363 const ast =
@@ -81,18 +81,20 @@ export class Interpreter {
8181 if ( ! entryFunctionName || ! entryFunctionName . length ) {
8282 return result ;
8383 } else {
84- const func = blockContext . blockScope . get ( entryFunctionName ) ;
84+ const funcName = Array . isArray ( entryFunctionName ) ? entryFunctionName [ 0 ] : entryFunctionName as string
85+ const funcParams = Array . isArray ( entryFunctionName ) ? entryFunctionName . slice ( 1 ) : [ ]
86+ const func = blockContext . blockScope . get ( funcName ) ;
8587 if ( typeof func !== 'function' ) {
8688 throw Error ( `Function ${ entryFunctionName } does not exists or not a function` ) ;
8789 }
88- return func ( ) ;
90+ return func ( ... funcParams ) ;
8991 }
9092 }
9193
9294 async evalAsync (
9395 codeOrAst : string | AstBlock ,
9496 scope : Record < string , unknown > = { } ,
95- entryFunctionName = '' ,
97+ entryFunctionName : string | [ string , ... unknown [ ] ] = '' ,
9698 moduleName = 'main.jspy' ,
9799 ctxInitialized ?: ( ctx : BlockContext ) => void
98100 ) : Promise < unknown > {
@@ -146,11 +148,14 @@ export class Interpreter {
146148 if ( ! entryFunctionName || ! entryFunctionName . length ) {
147149 return result ;
148150 } else {
149- const func = blockContext . blockScope . get ( entryFunctionName ) ;
151+ const funcName = Array . isArray ( entryFunctionName ) ? entryFunctionName [ 0 ] : entryFunctionName as string
152+ const funcParams = Array . isArray ( entryFunctionName ) ? entryFunctionName . slice ( 1 ) : [ ]
153+
154+ const func = blockContext . blockScope . get ( funcName ) ;
150155 if ( typeof func !== 'function' ) {
151156 throw Error ( `Function ${ entryFunctionName } does not exists or not a function` ) ;
152157 }
153- return await func ( ) ;
158+ return await func ( ... funcParams ) ;
154159 }
155160 }
156161
@@ -160,7 +165,7 @@ export class Interpreter {
160165 async evaluate (
161166 script : string ,
162167 context : Record < string , unknown > = { } ,
163- entryFunctionName = '' ,
168+ entryFunctionName : string | [ string , ... unknown [ ] ] = '' ,
164169 moduleName = 'main.jspy' ,
165170 ctxInitialized ?: ( ctx : BlockContext ) => void
166171 ) : Promise < unknown > {
0 commit comments