cedric
08/02/2019, 12:23 AMfun gitComplete(line: String, cursorIndex: Int): List<String> {
val words = line.split(" ")
if (words[0] == "git") return listOf("commit", "status")
else return emptyList()
}
val result = if (args.size == 2) gitComplete(args[0], args[1].toInt())
else emptyList()
result
The script above returns a valid result (a list of strings), but if I remove the intermediate result
variable:
fun gitComplete(line: String, cursorIndex: Int): List<String> {
val words = line.split(" ")
if (words[0] == "git") return listOf("commit", "status")
else return emptyList()
}
if (args.size == 2) gitComplete(args[0], args[1].toInt())
else emptyList()
then the result of the evaluation by the engine is null
.jdemeulenaere
08/02/2019, 2:06 PMcedric
08/02/2019, 5:55 PM// ~/t/a.kts
fun hello() = "hello"
hello()
and
$ kotlinc -script ~/t/a.kts
exception: java.lang.ArrayIndexOutOfBoundsException: Index 10912 out of bounds for length 10912
at org.jetbrains.org.objectweb.asm.ClassReader.readUnsignedShort(ClassReader.java:2464)
jdemeulenaere
08/06/2019, 9:50 AMjdemeulenaere
08/07/2019, 12:08 PMefemoney
08/08/2019, 10:12 AM@DependsOn
or is it still Ivy for now? Like can we add maven repositories with the repo annotation?DALDEI
08/09/2019, 7:07 AMjdemeulenaere
08/09/2019, 10:53 AMjdemeulenaere
08/09/2019, 11:57 AMaltavir
08/10/2019, 2:42 PMExpecting 'hostConfiguration' property in the script compilation configuration for the script KtFile: script.kts
I tried to somehow provide this hostConfiguration
, but I just do not understand how it works.
My configuration looks like this:
val workspaceScriptConfiguration = ScriptCompilationConfiguration {
baseClass(Any::class)
implicitReceivers(WorkspaceBuilder::class)
defaultImports("hep.dataforge.workspace.*")
jvm {
dependenciesFromCurrentContext(wholeClasspath = true)
}
}
val evaluationConfiguration = ScriptEvaluationConfiguration {
implicitReceivers(builder)
}
BasicJvmScriptingHost().eval(source, workspaceScriptConfiguration, evaluationConfiguration)
jdemeulenaere
08/16/2019, 8:15 AMfogone
08/17/2019, 4:48 PMimplicitReceivers()
and trying to import another script using @file:Import("..")
annotation. In evalWithConfigAndOtherScriptsResults()
-- it's part of kotlin.script.experimental.jvm.BasicJvmScriptEvaluator
there is next code:
val ctor = java.constructors.single() // <-- generated constructor which expects (imported script result, implicit receiver)
val instance = ctor.newInstance(*args.toArray()) // <--- args here reversed, so (implicit receiver, imported script result)
did somebody meet this problem?efemoney
08/20/2019, 9:46 AMkotlin-scripting-jvm-host
is missing a dependency on kotlin-scripting-compiler(-embeddable)
in the pom. Had to explicitly specify it.josephivie
08/22/2019, 5:33 AMkotlinc -cp kts.jar -script test.kts
, where test.kts
is my script file and kts.jar
is the kotlin-main-kts
JAR from Maven, but I get 'Unable to find script definitions' and a bunch of errors related to it not knowing what the dependency annotations are. I'm following the tutorial as exactly as I understand it - what's missing?josephivie
08/22/2019, 5:42 AM.kts
files will be with this script runner, why is it not default? The complexity of use is keeping scripting from becoming widely useful. I'd like the equivalent python script.py
, and I'd like it to be part of installing Kotlin. Until it's that simple, I can't rely on distributing .kts
files to others as a consistent, portable, easy way of giving other people scripts.
I know kscript
exists, but it only supports *nix.josephivie
08/23/2019, 1:05 AM@Repository
and such, possibly with Maven Central and JCenter just implied - future-compatible support with normal Kotlin scripts top priority
- Interactive mode - load the KT/KTS file and then get a REPL
- Line Argument - run the KT/KTS file, providing the expression you wish to be executed in that context.
- Open in IntelliJ - creates a project in a temp folder, including needed files using hard links. Full auto-complete. Does not use Gradle under the hood, but rather direct IML files.
- Fully platform independent, running in Java without any platform-specific features nor a separate installation of Kotlin (use embedded compiler instead)
- Perhaps platform-specific GUI integration - double click on script file to run, context-menu edit...
Is this something people would be interested in?
I think it wouldn't take me too long - I've experimented with similar things already. I already know how to create IntelliJ projects from XML, running Kotlin scripts, running the embedded Kotlin compiler, etc.
I'd primarily use it for build-scripts, personally. It would be nice to ditch Gradle and anything Gradle-like in favor of straight-up using libraries from Maven to compile your stuff. That would be some nice standard reuse there. I can imagine creating a build.kts
file and then opening it in interactive mode in the terminal of IntelliJ to run tasks like build()
, run()
, publish()
, etc. It would be so much faster to edit (Gradle's KTS editing isn't too speedy and resolving plugins can be tricky) and would make build files easier to follow, as they'd just be more normal Kotlin without extra bulky configuration systems and magic plugins. No build system, just... Kotlin. I'd have to make a couple of Maven libraries to make it more convenient to set up, but that's not too bad.josephivie
08/23/2019, 2:19 AMjosephivie
08/23/2019, 2:21 AMDALDEI
08/24/2019, 1:25 PMjosephivie
08/25/2019, 7:51 AM.kts
proper files working - for whatever reason, the embedded compiler wouldn't compile them but the standalone one would. Also couldn't figure out how to get them playing well with plain IntelliJ projects. I'd love to learn more about the topic if anyone has information I couldn't find.Egor
08/25/2019, 11:55 AMLeon K
08/26/2019, 2:01 PMILakeful
08/26/2019, 9:23 PMException in thread "..." java.lang.NoSuchMethodError: Line_1.access$getExample$p(LLine_1;)Ljava/lang/String;
darkmoon_uk
09/01/2019, 12:44 AMDALDEI
09/01/2019, 11:48 PMDALDEI
09/05/2019, 11:58 AMNikky
09/06/2019, 3:47 PMPaul Woitaschek
09/17/2019, 8:41 AMjdemeulenaere
09/22/2019, 12:07 PMbamboo
09/23/2019, 8:26 PMScriptDependenciesResolver
that reads the data from the given script resolver environment which can be configured via the -Xscript-resolver-environment
command line argument. The custom resolver is setup via the ScriptTemplateDefinition
annotation:
https://github.com/gradle/gradle/blob/6f683805c6b782b1eb91c01591aecabe6fe535fb/subprojects/kotlin-dsl/src/main/kotlin/org/gradle/kotlin/dsl/precompile/PrecompiledProjectScript.kt#L52-L54
My understanding is that it is NOT possible to mix the legacy ScriptTemplateDefinition
annotation with the new KotlinScript
one to get both, the dynamic implicit imports computed from the script resolver environment plus the implicit receivers from a custom compilationConfiguration
setup.
So the question is then, does the experimental API allow for the list of default imports for a given script to be computed based on command line arguments passed to the compiler?
@KotlinScript(
compilationConfiguration = DynamicDefaultImportsConfiguration::class
// other settings
)
open class ScriptWithDynamicDefaultImports
object DynamicDefaultImportsConfiguration : ScriptCompilationConfiguration({
refineConfiguration {
beforeCompiling {
it.compilationConfiguration.with {
defaultImports(
// How to read arguments passed to the compiler from here?
TODO()
)
}.asSuccess()
}
}
})