Also another problem I am noticing now: The HashMa...
# kotlin-native
p
Also another problem I am noticing now: The HashMap type has no definition in the header file. Do I have to call those functions blindly or why are they not exported?
a
They are not exported by default. One can wrap it manually, so only needed parts of stdlib will become available from C.
p
How would I accomplish that?
a
I mean you can provide functions, that take or return HashMaps, and they will be exposed along with the type itself. Mb like
fun emptyHashFromC():HashMap<Int, String> = HashMap<Int, String>()
. This will make possible to create instances of
<libname>_kref_kotlin_collections_HashMap
. What exactly are you trying to achieve here?
p
I have a function that returns a HashMap, but I only get this definition in my header file: typedef struct {   nimmstawindows_KNativePtr pinned; } nimmstawindows_kref_kotlin_collections_HashMap; If a function of mine now returns a HashMap, how would I know which functions are available on that object without checking the Kotlin code?
For example: How would I retrieve the first String in that HashMap?
a
I am not sure what can be assumed as the first String, but something like
Copy code
fun getFirst(map:HashMap<String, String>):String {
    return map.maxBy { it.key.toString() }!!.value
}
p
Hmm maybe I didn't make myself clear: I am trying to call a function on the returned HashMap from C code. But I don't have the header of that class available. If I call this from Kotlin it should be easy, because IDEA knows the Kotlin classes. But how do I tell my C IDE what functions are available on the object? Can I export the Kotlin stdlib definitions as well?
a
AFAIK, no, you cannot export stdlib as-is, you can only wrap important parts of it manually. From C side it is possible to use only functions, described in the header.
p
I see, thanks for your help
a
Thanks for such detailed explanation of the use-case 🙂 I hope this aspect can be improved with time.