Skip to content

Commit 10dd4a4

Browse files
committed
enhanced docs about//ENTRY directive
1 parent 702ecd3 commit 10dd4a4

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

README.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,18 @@ FAQ
185185
---
186186

187187

188-
### Does it also work for regular kotlin class files `.kt`?
188+
### Why is `kscript` not calling the main method in my `.kts` script?
189189

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.
191200

192201
However in case you're using a companion object to declare the entry point, you can indicate this via the `//ENTRY` directive:
193202

@@ -213,6 +222,7 @@ class Foo{
213222
```
214223
The intial shebang could be left out by running the script directly with `kscript some.kt`
215224

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)
216226

217227

218228
### 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!")
226236
```
227237

228238

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)
238-
239239
Support
240240
-------
241241

0 commit comments

Comments
 (0)