Florian Magin
07/23/2021, 10:45 AMobj as a "Binding", like wrapping the entire .kts Script I want to evaluate in a with (obj){ } block?Florian Magin
07/23/2021, 10:58 AM.kts Script. The underlying Kotlin kernel is being passed a certain object as an implicitReceiver, and now I want to run this .kts Script with the same kind of object as an implicitReceiver so it works without changesilya.chernikov
07/28/2021, 3:41 PMimplicitReceiver you mentioned above is a part of this customization, and the jupyter kernel uses exactly this API), but you'll need to add your own script definition and run your scripts with your definition accordingly, so it will not work with a default .kts files. You can have a look at the sample implementation here - https://github.com/Kotlin/kotlin-script-examples/tree/master/jvm/simple-main-ktsFlorian Magin
07/28/2021, 3:54 PM.kts file"Florian Magin
07/28/2021, 3:55 PMilya.chernikov
07/28/2021, 4:05 PMkotlinc or kotlin cli tools as hosts, the problem arises - how to distinguish between different types of scripts (or scripts with different customizations). This is done by default with the filename extension, and recommended schema is to use double extension, e.g. .main.kts. In this schema the "default .kts" script is a basic script without any specific customization, and these hosts and IntelliJ will handle it accordingly, so you cannot add e.g an implicit receiver to this script and run it with the kotlinc.
On the other hand, if you'll write a proper definition jar, e.g. as in the example I linked above, and will give your script a dedicated filename extension, you can run it via kotlinc and even get some basic IntelliJ support.Florian Magin
07/28/2021, 4:06 PMval engine = ScriptEngineManager(this.javaClass.classLoader).getEngineByExtension("kts")
val script = sourceFile.getFile(false).readText(Charsets.UTF_8)
val x = engine.eval(script)Florian Magin
07/28/2021, 4:07 PMScriptEngineManager(this.javaClass.classLoader).getEngineByExtension(".mynewextension")Florian Magin
07/28/2021, 4:09 PMFlorian Magin
07/28/2021, 4:09 PMilya.chernikov
07/28/2021, 4:09 PMsimple-main-kts one.Florian Magin
07/28/2021, 4:10 PMilya.chernikov
07/28/2021, 4:12 PMFlorian Magin
07/28/2021, 4:14 PM.kts scripts) in KotlinFlorian Magin
07/28/2021, 4:15 PMevalFile Method from the tests seems fairly close to what I was looking forFlorian Magin
07/28/2021, 4:40 PM@Suppress("unused")
@KotlinScript(
fileExtension = "ghidra.kts",
compilationConfiguration = SimpleMainKtsScriptDefinition::class,
evaluationConfiguration = MainKtsEvaluationConfiguration::class
)
abstract class SimpleMainKtsScript(val args: Array<String>)
work if I want to pass a specific object as an implicitReceiver to the compilationConfiguration?ilya.chernikov
07/28/2021, 5:07 PMSimpleMainKtsScriptDefinition class and add implicitReceiver to the configuration.
You'll need your copy of the evaluation configuration too, since you'll need to provide the implicit receiver on the evaluation.Florian Magin
07/28/2021, 5:09 PMFlorian Magin
07/28/2021, 5:09 PMFlorian Magin
07/28/2021, 5:10 PM