4

Please excuse me that I don't know if I should ask about all basic types in one post or separately.

Main questions:

  1. How do I pass an array of floats from Kotlin to JS?
  2. How about other "simple" types? Like a float, string?
  3. What about other types like set, map and even data classes?

I have this at the end of my Kotlin Main File

@SymbolName("callback")
external fun cb(<......>)

If the types in the cb() definition matches what I am passing from the main(), e.g. Int, Float, then cb() from the browser will get correct values.

If I am using Any, then all I'll get is an integer (which I guess should be a pointer to the memory).

I have tried to inspect heap but to no avail in how to retrieve the int, float, strings that I passed to cb() via Kotlin.

For Arrays, I noticed that there are JsArray in jsinterop package, but I cannot find good references on how to use it.

One thing I have noticed is that I can get an array of integers via Arenas:

    val arena = allocateArena()
    pushIntToArena(arena, 1)
    pushIntToArena(arena, 12)

Then I'll get the array via konan_dependencies.env.arenas.

But, how do I get an array of floats? Please advise.

P.S. I am using konan plugin in my build.gradle for compiling to Wasm32. I pass callback to Wasm by adding the function to window.konan.libraries in module.wasm.js:

    var konan = {
      libraries: [
        { "callback": function(msg) { console.trace(msg); } }
      ],
    }

Sunny Pun
  • 726
  • 5
  • 14

0 Answers0