migrated to kotlin 2.2.0
better support for shebangs in CLI lyng added jlyng local release
This commit is contained in:
parent
612c0fb7b9
commit
ce4ed5c819
14
bin/local_jrelease
Executable file
14
bin/local_jrelease
Executable file
@ -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
|
3
docs/samples/helloworld.lyng
Normal file → Executable file
3
docs/samples/helloworld.lyng
Normal file → Executable file
@ -1,2 +1,3 @@
|
|||||||
|
#!/bin/env jlyng
|
||||||
|
|
||||||
println("Hello, world!");
|
println("Hello, world2! "+ARGV);
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
[versions]
|
[versions]
|
||||||
agp = "8.5.2"
|
agp = "8.5.2"
|
||||||
clikt = "5.0.3"
|
clikt = "5.0.3"
|
||||||
kotlin = "2.1.21"
|
kotlin = "2.2.0"
|
||||||
android-minSdk = "24"
|
android-minSdk = "24"
|
||||||
android-compileSdk = "34"
|
android-compileSdk = "34"
|
||||||
kotlinx-coroutines = "1.10.1"
|
kotlinx-coroutines = "1.10.1"
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
plugins {
|
plugins {
|
||||||
kotlin("multiplatform") version "2.1.21"
|
kotlin("multiplatform") version "2.2.0"
|
||||||
}
|
}
|
||||||
|
|
||||||
group = "net.sergeych"
|
group = "net.sergeych"
|
||||||
|
@ -1,11 +1,14 @@
|
|||||||
package net.sergeych
|
package net.sergeych
|
||||||
|
|
||||||
import com.github.ajalt.clikt.core.CliktCommand
|
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.argument
|
||||||
import com.github.ajalt.clikt.parameters.arguments.multiple
|
import com.github.ajalt.clikt.parameters.arguments.multiple
|
||||||
import com.github.ajalt.clikt.parameters.arguments.optional
|
import com.github.ajalt.clikt.parameters.arguments.optional
|
||||||
import com.github.ajalt.clikt.parameters.options.flag
|
import com.github.ajalt.clikt.parameters.options.flag
|
||||||
import com.github.ajalt.clikt.parameters.options.option
|
import com.github.ajalt.clikt.parameters.options.option
|
||||||
|
import kotlinx.coroutines.runBlocking
|
||||||
import net.sergeych.lyng.*
|
import net.sergeych.lyng.*
|
||||||
import okio.FileSystem
|
import okio.FileSystem
|
||||||
import okio.Path.Companion.toPath
|
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<String>) {
|
||||||
|
if(args.isNotEmpty()) {
|
||||||
|
if( args.size >= 2 && args[0] == "--" ) {
|
||||||
|
// -- -file.lyng <args>
|
||||||
|
executeFileWithArgs(args[1], args.drop(2))
|
||||||
|
return
|
||||||
|
} else if( args[0][0] != '-') {
|
||||||
|
// file.lyng <args>
|
||||||
|
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
|
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()
|
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.
|
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<String>) {
|
||||||
|
runBlocking {
|
||||||
|
baseScope.addConst("ARGV", ObjList(args.map { ObjString(it) }.toMutableList()))
|
||||||
|
executeFile(fileName)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
suspend fun executeFile(fileName: String) {
|
suspend fun executeFile(fileName: String) {
|
||||||
var text = FileSystem.SYSTEM.source(fileName.toPath()).use { fileSource ->
|
var text = FileSystem.SYSTEM.source(fileName.toPath()).use { fileSource ->
|
||||||
fileSource.buffer().use { bs ->
|
fileSource.buffer().use { bs ->
|
||||||
|
@ -1,9 +1,7 @@
|
|||||||
package net.sergeych.lyng_cli
|
package net.sergeych.lyng_cli
|
||||||
|
|
||||||
import com.github.ajalt.clikt.core.main
|
import net.sergeych.runMain
|
||||||
import kotlinx.coroutines.runBlocking
|
|
||||||
import net.sergeych.Lyng
|
|
||||||
|
|
||||||
fun main(args: Array<String>) {
|
fun main(args: Array<String>) {
|
||||||
Lyng({ runBlocking { it() } }).main(args)
|
runMain(args)
|
||||||
}
|
}
|
@ -1,7 +1,5 @@
|
|||||||
import com.github.ajalt.clikt.core.main
|
import net.sergeych.runMain
|
||||||
import kotlinx.coroutines.runBlocking
|
|
||||||
import net.sergeych.Lyng
|
|
||||||
|
|
||||||
fun main(args: Array<String>) {
|
fun main(args: Array<String>) {
|
||||||
Lyng( { runBlocking { it() } }).main(args)
|
runMain(args)
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user