Kotlin Native 相当于 System.exit(-1)

Kotlin Native equivalent of System.exit(-1)

在下面的 Kotlin/JVM 程序中 System.exit(-1) 停止执行程序并返回错误退出代码:

fun main(args: Array<String>) {
    if (args.size < 2) {
        println("too few args!")
        System.exit(-1)
    }
    println("Hello, ${args[1]} from ${args[0]}")
}

Kotlin/Native 无法访问任何 Java 类,包括 System。那么 Kotlin/Native 程序停止执行带有错误代码的程序的等效函数是什么?

使用exitProcess:

import kotlin.system.exitProcess
...
exitProcess(exitCode)

Declaration and documentation 在 Kotlin 源代码中。