diff --git a/bin/local_jrelease b/bin/local_jrelease new file mode 100755 index 0000000..8ce334a --- /dev/null +++ b/bin/local_jrelease @@ -0,0 +1,14 @@ +#!/bin/bash + +set -e + +root=./lyng/build/install/lyng-jvm/ + +./gradlew :lyng:installJvmDist +#strip $file +#upx $file +rm -rf ~/bin/jlyng-jvm || true +rm ~/bin/jlyng 2>/dev/null || true +mkdir -p ~/bin/jlyng-jvm +cp -R $root ~/bin/jlyng-jvm +ln -s ~/bin/jlyng-jvm/lyng-jvm/bin/lyng ~/bin/jlyng diff --git a/docs/samples/helloworld.lyng b/docs/samples/helloworld.lyng old mode 100644 new mode 100755 index da70ac9..f22731c --- a/docs/samples/helloworld.lyng +++ b/docs/samples/helloworld.lyng @@ -1,2 +1,3 @@ +#!/bin/env jlyng -println("Hello, world!"); +println("Hello, world2! "+ARGV); diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index ac2ac7b..67a191f 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,7 +1,7 @@ [versions] agp = "8.5.2" clikt = "5.0.3" -kotlin = "2.1.21" +kotlin = "2.2.0" android-minSdk = "24" android-compileSdk = "34" kotlinx-coroutines = "1.10.1" diff --git a/lyng/build.gradle.kts b/lyng/build.gradle.kts index 90e0bbe..841fc83 100644 --- a/lyng/build.gradle.kts +++ b/lyng/build.gradle.kts @@ -1,5 +1,5 @@ plugins { - kotlin("multiplatform") version "2.1.21" + kotlin("multiplatform") version "2.2.0" } group = "net.sergeych" diff --git a/lyng/src/commonMain/kotlin/Common.kt b/lyng/src/commonMain/kotlin/Common.kt index 76e3e31..f8e131d 100644 --- a/lyng/src/commonMain/kotlin/Common.kt +++ b/lyng/src/commonMain/kotlin/Common.kt @@ -1,11 +1,14 @@ package net.sergeych import com.github.ajalt.clikt.core.CliktCommand +import com.github.ajalt.clikt.core.Context +import com.github.ajalt.clikt.core.main import com.github.ajalt.clikt.parameters.arguments.argument import com.github.ajalt.clikt.parameters.arguments.multiple import com.github.ajalt.clikt.parameters.arguments.optional import com.github.ajalt.clikt.parameters.options.flag import com.github.ajalt.clikt.parameters.options.option +import kotlinx.coroutines.runBlocking import net.sergeych.lyng.* import okio.FileSystem import okio.Path.Companion.toPath @@ -41,7 +44,23 @@ val baseScope = Scope().apply { // } } -class Lyng(val launcher: (suspend () -> Unit) -> Unit) : CliktCommand() { +fun runMain(args: Array) { + if(args.isNotEmpty()) { + if( args.size >= 2 && args[0] == "--" ) { + // -- -file.lyng + executeFileWithArgs(args[1], args.drop(2)) + return + } else if( args[0][0] != '-') { + // file.lyng + executeFileWithArgs(args[0], args.drop(1)) + return + } + } + // normal processing + Lyng { runBlocking { it() } }.main(args) +} + +private class Lyng(val launcher: (suspend () -> Unit) -> Unit) : CliktCommand() { override val printHelpOnEmptyArgs = true @@ -55,7 +74,7 @@ class Lyng(val launcher: (suspend () -> Unit) -> Unit) : CliktCommand() { val args by argument(help = "arguments for script").multiple() - override fun help(context: com.github.ajalt.clikt.core.Context): String = + override fun help(context: Context): String = """ The Lyng script language interpreter, language version is $LyngVersion. @@ -106,6 +125,13 @@ class Lyng(val launcher: (suspend () -> Unit) -> Unit) : CliktCommand() { } } +fun executeFileWithArgs(fileName: String, args: List) { + runBlocking { + baseScope.addConst("ARGV", ObjList(args.map { ObjString(it) }.toMutableList())) + executeFile(fileName) + } +} + suspend fun executeFile(fileName: String) { var text = FileSystem.SYSTEM.source(fileName.toPath()).use { fileSource -> fileSource.buffer().use { bs -> diff --git a/lyng/src/jvmMain/kotlin/net/sergeych/lyng_cli/Main.kt b/lyng/src/jvmMain/kotlin/net/sergeych/lyng_cli/Main.kt index e639d54..543bfc7 100644 --- a/lyng/src/jvmMain/kotlin/net/sergeych/lyng_cli/Main.kt +++ b/lyng/src/jvmMain/kotlin/net/sergeych/lyng_cli/Main.kt @@ -1,9 +1,7 @@ package net.sergeych.lyng_cli -import com.github.ajalt.clikt.core.main -import kotlinx.coroutines.runBlocking -import net.sergeych.Lyng +import net.sergeych.runMain fun main(args: Array) { - Lyng({ runBlocking { it() } }).main(args) + runMain(args) } \ No newline at end of file diff --git a/lyng/src/linuxX64Main/kotlin/Main.kt b/lyng/src/linuxX64Main/kotlin/Main.kt index 81d9243..f654831 100644 --- a/lyng/src/linuxX64Main/kotlin/Main.kt +++ b/lyng/src/linuxX64Main/kotlin/Main.kt @@ -1,7 +1,5 @@ -import com.github.ajalt.clikt.core.main -import kotlinx.coroutines.runBlocking -import net.sergeych.Lyng +import net.sergeych.runMain fun main(args: Array) { - Lyng( { runBlocking { it() } }).main(args) + runMain(args) } \ No newline at end of file