From 7d06d1cc7221b1d84b296898b9f24a1706922d3e Mon Sep 17 00:00:00 2001 From: rhunk <101876869+rhunk@users.noreply.github.com> Date: Wed, 21 Aug 2024 11:40:34 +0200 Subject: [PATCH] feat(scripting/interfaces): new thread function --- .../common/scripting/impl/JavaInterfaces.kt | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/common/src/main/kotlin/me/rhunk/snapenhance/common/scripting/impl/JavaInterfaces.kt b/common/src/main/kotlin/me/rhunk/snapenhance/common/scripting/impl/JavaInterfaces.kt index 4cfd75ad0..457d8f5d3 100644 --- a/common/src/main/kotlin/me/rhunk/snapenhance/common/scripting/impl/JavaInterfaces.kt +++ b/common/src/main/kotlin/me/rhunk/snapenhance/common/scripting/impl/JavaInterfaces.kt @@ -6,6 +6,7 @@ import me.rhunk.snapenhance.common.scripting.ktx.contextScope import me.rhunk.snapenhance.common.scripting.ktx.putFunction import me.rhunk.snapenhance.common.scripting.ktx.scriptableObject import java.lang.reflect.Proxy +import kotlin.concurrent.thread class JavaInterfaces : AbstractBinding("java-interfaces", BindingSide.COMMON) { override fun getObject() = scriptableObject { @@ -41,5 +42,20 @@ class JavaInterfaces : AbstractBinding("java-interfaces", BindingSide.COMMON) { } } } + + putFunction("thread") { arguments -> + val function = arguments?.get(0) as? org.mozilla.javascript.Function ?: return@putFunction null + + thread(start = false) { + contextScope { + function.call( + this, + this@scriptableObject, + this@scriptableObject, + emptyArray() + ) + } + } + } } } \ No newline at end of file