jniMain.com.dokar.quickjs.alias.dslAlias.jni.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of quickjs-kt Show documentation
Show all versions of quickjs-kt Show documentation
A QuickJS binding for idiomatic Kotlin, with Async/DSL/ES Modules support.
The newest version!
package com.dokar.quickjs.alias
import com.dokar.quickjs.ExperimentalQuickJsApi
import com.dokar.quickjs.QuickJs
import com.dokar.quickjs.QuickJsException
import com.dokar.quickjs.binding.JsObjectHandle
import com.dokar.quickjs.binding.define
import com.dokar.quickjs.evaluate
import kotlin.reflect.KType
/**
* Alias for inline version of [QuickJs.define].
*/
@ExperimentalQuickJsApi
inline fun QuickJs.def(
name: String,
instance: Any,
parent: JsObjectHandle = JsObjectHandle.globalThis,
) {
define(name = name, instance = instance, parent = parent)
}
/**
* Alias for [QuickJs.define].
*/
@ExperimentalQuickJsApi
fun QuickJs.def(
name: String,
type: Class,
instance: Any,
parent: JsObjectHandle = JsObjectHandle.globalThis,
) {
define(name = name, type = type, instance = instance, parent = parent)
}
/**
* Alias for [QuickJs.evaluate].
*/
@ExperimentalQuickJsApi
@Throws(QuickJsException::class)
suspend fun QuickJs.eval(
bytecode: ByteArray,
type: KType
): T {
return evaluate(bytecode = bytecode, type = type)
}
/**
* Alias for [QuickJs.evaluate].
*/
@ExperimentalQuickJsApi
@Throws(QuickJsException::class)
suspend fun QuickJs.eval(
code: String,
type: KType,
filename: String = "main.js",
asModule: Boolean = false
): T {
return evaluate(code = code, type = type, filename = filename, asModule = asModule)
}