You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+12-12Lines changed: 12 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -185,9 +185,18 @@ FAQ
185
185
---
186
186
187
187
188
-
### Does it also work for regular kotlin class files `.kt`?
188
+
### Why is `kscript` not calling the main method in my `.kts` script?
189
189
190
-
Yes, you can run kotlin classes through kscript. By default `kscript` will assume a top-level `main` method as entry-point.
190
+
There is [no need](https://kotlinlang.org/docs/tutorials/command-line.html#using-the-command-line-to-run-scripts) for a `main` method in a Kotlin script. Kotlin `*.kts` scripts can be more simplistic compared to more common kotlin `*.kt` source files. The former work without a `main` method by directly running the provided code from top to bottom. E.g.
191
+
```
192
+
print("hello kotlin!")
193
+
```
194
+
is a valid Kotlin `kts` script. Plain and simple, no `main`, no `companion`, just a few bits of code.
195
+
196
+
197
+
### Ok, but does `kscript` also work for regular kotlin `.kt` source files with a `main` as entry point?
198
+
199
+
Yes, (since v1.6) you can run kotlin source files through `kscript`. By default it will assume a top-level `main` method as entry-point.
191
200
192
201
However in case you're using a companion object to declare the entry point, you can indicate this via the `//ENTRY` directive:
193
202
@@ -213,6 +222,7 @@ class Foo{
213
222
```
214
223
The intial shebang could be left out by running the script directly with `kscript some.kt`
215
224
225
+
By means of the `//ENTRY` directive, `kscript` can be used a application launcher for demos and examples. Even direcly from your github repo via its [URL input mode](#url-usage)
216
226
217
227
218
228
### How to adjust the memory settings for the JVM in my scriptlet?
@@ -226,16 +236,6 @@ println("Hello from Kotlin with 5g of heap memory running in server mode!")
226
236
```
227
237
228
238
229
-
### Scripts with a main method do not run with `kscript`?
230
-
231
-
There is [no need](https://kotlinlang.org/docs/tutorials/command-line.html#using-the-command-line-to-run-scripts) for a main method in a Kotlin script. Kotlin `*.kts` scripts can be more simplistic compared to regular kotlin `*.kt` source files and work without a main method by directly running the provided code. E.g.
232
-
```
233
-
print("hello kotlin!")
234
-
```
235
-
is a valid Kotlin `kts` script.
236
-
237
-
Regular class files are not supported [yet](https://github.com/holgerbrandl/kscript/issues/31#issuecomment-309976103) by `kscript`. This is because a `kt` Kotlin source file might contain multiple classes with a main method in each, so the entry point might not be always clearly defined. (see #31)
0 commit comments