-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
No Simple Example Exists #21
Comments
If you want a really simple example, you can look at https://github.com/Kotlin/kotlin-script-examples/blob/master/jvm/main-kts/MainKts.md, but those are using the built-in script definition ( I don't think it's possible to give a simpler example than "basic" because of the need to define a separate jar for the script definition (class that the kts file "extends"). Re "simple example", did you mean https://github.com/Kotlin/kotlin-script-examples/tree/master/jvm/simple-main-kts? What steps are you doing? |
https://github.com/Kotlin/kotlin-script-examples/tree/master/jvm/basic/jvm-simple-script is what I was trying to follow, but I did not want to clone the repo, I just wanted a standalone environment to play with... This is what I tried, but could not get it to work. Main.kt
default.kts
When I run it I get
|
I reproduced your problem in: https://github.com/TWiStErRob/repros/tree/main/kotlin/basic-script-hello-world I recommend you don't hide the error message by doing this: if (it.severity > ScriptDiagnostic.Severity.DEBUG) {
val ex = it.exception
println(" : ${it.message}" + if (ex == null) "" else "\n${ex.stackTraceToString()}")
} it gives way more info:
at this point you can see the following:
Since there's a problem with the configuration, I made a wild guess, and found the solution:
|
WOW... thanks so much... your sleuthing is beyond my Kotlin skills... Anyway, it looks like
So, mostly I just constructed this code by copy/paste from various sources, not really understanding what the code was doing. The original code has too many inter-dependencies on other things. However, the end result is basically what I asked for in the first place: two simple files. By comparison, I did something similar in Java, but using the runtime compiler, then loading the class file, and invoking it with reflection. The code is easier to read and understand, but it did take a lot of trial and error to get it right. Years ago, I did something similar with Groovy, and it was a lot easier to load Groovy at runtime, and call it. I also did something similar with Scala, but sort of cheated and just invoked Scala as scripts from the runtime by calling the Java Process API. I like the idea of loading Kotlin source at runtime and executing it, but I hope it become much simpler. |
All these examples are too complicated, brittle, and fragile. Can someone please give the most simple working example possible with only two files
When I try to run the simple example I get
: wrong number of arguments: 0 expected: 1: java.lang.IllegalArgumentException: wrong number of arguments: 0 expected: 1
The text was updated successfully, but these errors were encountered: