Jared Woolston
03/23/2020, 9:24 PMnvk.kt
which contains:
@file:JsModule("nvk")
@file:JsNonModule
package nvk
external class VulkanWindow
And in the JS source set, I am trying to define an actual
for an expected
as seen here:
actual class VkWindow {
val window: VulkanWindow
actual constructor(width: Int, height: Int, title: String) {
window = VulkanWindow::class.js.createInstance()
window.asDynamic()["width"] = width
window.asDynamic()["height"] = height
window.asDynamic()["title"] = title
}
}
Where createInstance()
is defined following the discussion at https://discuss.kotlinlang.org/t/is-there-a-way-to-use-the-new-operator-with-arguments-on-a-dynamic-variable-in-kotlin-javascript/6126/4 as:
fun <T : Any> JsClass<T>.createInstance(vararg args: dynamic): T {
@Suppress("UNUSED_VARIABLE")
val ctor = this
@Suppress("UNUSED_VARIABLE")
val argsArray = (listOf(null) + args).toTypedArray()
//language=JavaScript 1.6
return js("new (Function.prototype.bind.apply(ctor, argsArray))").unsafeCast<T>()
}
This all compiles fine but when I try and run it via jsNodeRun
I get the following error:
return js("new (Function.prototype.bind.apply(ctor, argsArray))").unsafeCast<T>()
^
Error: Argument 1 must be of type 'Object'To be honest, I don't have a particular preference on how I instantiate objects from this module, though I would like to be able to eventually do it with arguments. Any guidance would be greatly appreciated.
turansky
03/23/2020, 10:42 PMJared Woolston
03/23/2020, 10:43 PMDominaezzz
03/23/2020, 10:44 PMJared Woolston
03/23/2020, 10:44 PMJared Woolston
03/23/2020, 10:44 PM