@@ -24,6 +24,7 @@ class KtsScript : Script<EvaluationResult?> {
2424 private val securityManager: ScriptSecurityManager = StandardSecurityManager ()
2525 private var functionManager: ScriptFunctionManager = StandardFunctionManager ()
2626 private var constantManager: ScriptConstantManager = StandardConstantManager ()
27+ private val extraScript = mutableListOf<String >()
2728
2829 override fun getSecurityManager () = securityManager
2930
@@ -39,18 +40,27 @@ class KtsScript : Script<EvaluationResult?> {
3940 this .constantManager = constantManager
4041 }
4142
43+ override fun addExtraScript (script : String ) {
44+ extraScript.add(script)
45+ }
46+
4247 @Throws(ScriptException ::class )
4348 override fun eval (script : String ): EvaluationResult ? {
4449 val host = BasicJvmScriptingHost ()
4550 val bridge = KtsBridge (this )
4651
47- val source = StringScriptSource (KtsPreludeBuilder .build(this , script))
52+ val source = StringScriptSource (KtsPreludeBuilder .build(this , buildString {
53+ // Building full script including extra script code
54+ for (extra in extraScript) {
55+ append(" $extra \n " )
56+ }
57+ append(script)
58+ }))
59+
4860 val result = host.eval(
4961 source,
5062 KtsScriptCompilationConfiguration (securityManager),
51- KtsScriptEvaluationConfiguration .with {
52- providedProperties(mapOf (" __bridge__" to bridge))
53- }
63+ KtsScriptEvaluationConfiguration (bridge)
5464 )
5565
5666 if (result is ResultWithDiagnostics .Success ) {
@@ -71,5 +81,4 @@ class KtsScript : Script<EvaluationResult?> {
7181 }
7282 return null
7383 }
74-
7584}
0 commit comments