All Downloads are FREE. Search and download functionalities are using the official Maven repository.

jvmMain.org.luaj.vm2.internal.Actual.kt Maven / Gradle / Ivy

Go to download

LUAK - Kotlin port of LuaJ (fork of https://github.com/korlibs/korge-luak)

There is a newer version: 1.0.0-alpha3
Show newest version
@file:Suppress("PLATFORM_CLASS_MAPPED_TO_KOTLIN")

package org.luaj.vm2.internal

import org.luaj.vm2.io.*
import kotlin.reflect.*
import kotlin.system.*

internal actual object JSystem {
    actual val out: LuaWriter get() = System.out.toLua().toWriter()
    actual val err: LuaWriter get() = System.err.toLua().toWriter()
    actual val `in`: LuaBinInput get() = System.`in`.toLua()

    actual fun exit(code: Int): Unit = exitProcess(code)
    actual fun getProperty(key: String, def: String?): String? = System.getProperty(key, def)
    actual fun gc() = System.gc()
    actual fun totalMemory(): Long = Runtime.getRuntime().totalMemory()
    actual fun freeMemory(): Long = Runtime.getRuntime().freeMemory()
    actual fun InstantiateClassByName(name: String): Any? = try {
        Class.forName(name).newInstance()
    } catch (e: ClassNotFoundException) {
        null
    }
    actual fun StartNativeThread(runnable: () -> Unit, name: String): Unit = Thread(Runnable(runnable), name).start()

    actual fun Class_portableName(clazz: KClass<*>): String = clazz.java.name
    actual fun Class_isInstancePortable(clazz: KClass<*>, ins: Any): Boolean = clazz.java.isAssignableFrom(ins::class.java)
    actual fun Class_getResourceAsStreamPortable(clazz: KClass<*>, res: String): LuaBinInput? = clazz.java.getResourceAsStream(res)?.toLua()
    actual val supportStatic: Boolean = true
}

actual typealias IOException = java.io.IOException
actual typealias EOFException = java.io.EOFException

actual typealias InterruptedException = java.lang.InterruptedException

actual typealias WeakReference = java.lang.ref.WeakReference




© 2015 - 2024 Weber Informatics LLC | Privacy Policy