Skip to content

Commit 702ecd3

Browse files
committed
added docs for //ENTRY
1 parent 67cad59 commit 702ecd3

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,36 @@ FAQ
185185
---
186186

187187

188+
### Does it also work for regular kotlin class files `.kt`?
189+
190+
Yes, you can run kotlin classes through kscript. By default `kscript` will assume a top-level `main` method as entry-point.
191+
192+
However in case you're using a companion object to declare the entry point, you can indicate this via the `//ENTRY` directive:
193+
194+
```kotlin
195+
#!/usr/bin/env kscript
196+
197+
package test
198+
199+
//DEPS log4j:log4j:1.2.14
200+
//ENTRY Foo
201+
202+
class User(val age: Int)
203+
204+
fun findUserByName(name: String): User = null!!
205+
206+
class Foo{
207+
companion object {
208+
@JvmStatic fun main(args: Array<String>) {
209+
println("foo companion was called")
210+
}
211+
}
212+
}
213+
```
214+
The intial shebang could be left out by running the script directly with `kscript some.kt`
215+
216+
217+
188218
### How to adjust the memory settings for the JVM in my scriptlet?
189219

190220
`kscript` allows to provide a `//KOTLIN_OPTS` line followed by parameters passed on to `kotlin` similar to how dependencies are defined:

0 commit comments

Comments
 (0)