Hello,
Do you know, how is better to pass parameter (in general case - class instance) to the Kotlin Script?
I have script, which defines internally Map<String, ()->SomeResult>
.
I’d like to have an ability to run string script with parameter to execute the target function from map.
What I tried:
- Put custom object into the scripting context. And looks like Kotlin Scripting engine changes class names, so I’m unable to find the generated class via reflection by name.
- I tried also to create the interface and next put the generated class into the script. Next I thank that class can be found by looking up all classes from the ClassLoader (it is single who implements the target interface). However, looks like because of JVM optimisations, that class wasn’t loaded into memory, so lookup was failed.
- I tried to add my code into the top of script, however
import
statements should be upper than any code, so this idea was failed. - My script should return the result, so I couldn’t add code into the end of file.
So, does anybody know, how can I pass parameter to the Kotlin Script?