@@ -57,7 +57,7 @@ export class Interpreter {
57
57
eval (
58
58
codeOrAst : string | AstBlock ,
59
59
scope : Record < string , unknown > = { } ,
60
- entryFunctionName = '' ,
60
+ entryFunctionName : string | [ string , ... unknown [ ] ] = '' ,
61
61
moduleName = 'main.jspy'
62
62
) : unknown {
63
63
const ast =
@@ -81,18 +81,20 @@ export class Interpreter {
81
81
if ( ! entryFunctionName || ! entryFunctionName . length ) {
82
82
return result ;
83
83
} 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 ) ;
85
87
if ( typeof func !== 'function' ) {
86
88
throw Error ( `Function ${ entryFunctionName } does not exists or not a function` ) ;
87
89
}
88
- return func ( ) ;
90
+ return func ( ... funcParams ) ;
89
91
}
90
92
}
91
93
92
94
async evalAsync (
93
95
codeOrAst : string | AstBlock ,
94
96
scope : Record < string , unknown > = { } ,
95
- entryFunctionName = '' ,
97
+ entryFunctionName : string | [ string , ... unknown [ ] ] = '' ,
96
98
moduleName = 'main.jspy' ,
97
99
ctxInitialized ?: ( ctx : BlockContext ) => void
98
100
) : Promise < unknown > {
@@ -146,11 +148,14 @@ export class Interpreter {
146
148
if ( ! entryFunctionName || ! entryFunctionName . length ) {
147
149
return result ;
148
150
} 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 ) ;
150
155
if ( typeof func !== 'function' ) {
151
156
throw Error ( `Function ${ entryFunctionName } does not exists or not a function` ) ;
152
157
}
153
- return await func ( ) ;
158
+ return await func ( ... funcParams ) ;
154
159
}
155
160
}
156
161
@@ -160,7 +165,7 @@ export class Interpreter {
160
165
async evaluate (
161
166
script : string ,
162
167
context : Record < string , unknown > = { } ,
163
- entryFunctionName = '' ,
168
+ entryFunctionName : string | [ string , ... unknown [ ] ] = '' ,
164
169
moduleName = 'main.jspy' ,
165
170
ctxInitialized ?: ( ctx : BlockContext ) => void
166
171
) : Promise < unknown > {
0 commit comments