From f0c34e27bb914a08c0b5e29482b1d9c625d9a464 Mon Sep 17 00:00:00 2001 From: rhunk <101876869+rhunk@users.noreply.github.com> Date: Thu, 21 Sep 2023 19:26:20 +0200 Subject: [PATCH] fix(scripting): dyn method call --- .../kotlin/me/rhunk/snapenhance/scripting/JSModule.kt | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/core/src/main/kotlin/me/rhunk/snapenhance/scripting/JSModule.kt b/core/src/main/kotlin/me/rhunk/snapenhance/scripting/JSModule.kt index 4145f958..b535bde1 100644 --- a/core/src/main/kotlin/me/rhunk/snapenhance/scripting/JSModule.kt +++ b/core/src/main/kotlin/me/rhunk/snapenhance/scripting/JSModule.kt @@ -68,10 +68,13 @@ class JSModule( constructor.newInstance(*args ?: emptyArray()) } - clazz.declaredMethods.forEach { method -> - method.isAccessible = true + clazz.declaredMethods.filter { Modifier.isStatic(it.modifiers) }.forEach { method -> putFunction(method.name) { args -> - args?.also { method.invoke(null, *it) } ?: method.invoke(null) + clazz.declaredMethods.find { + it.name == method.name && it.parameterTypes.zip(args ?: emptyArray()).all { (type, arg) -> + type.isAssignableFrom(arg.javaClass) + } + }?.invoke(null, *args ?: emptyArray()) } }