napperley
04/29/2021, 2:04 AMserebit
04/29/2021, 2:35 AMArray<String>.toCStringArray(autofreeScope: AutofreeScope)
. It returns a CPointer<CPointerVar<ByteVar>>
, which is exactly what you want. You just need to provide it a MemScope, which you can use memScoped
for.napperley
04/29/2021, 2:46 AM// ...
fun changeIcons(icons: Array<String>): Unit = memScoped {
val tmp = allocArray<CPointerVar<ByteVar>>(icons.size)
@Suppress("ReplaceRangeToWithUntil")
(0..(icons.size - 1)).forEach { pos -> tmp[pos] = icons[pos].cstr.ptr }
gtk_scale_button_set_icons(gtkScaleButtonPtr, tmp)
}
@serebit - Your solution looks much better than what I have come up with 😄 .napperley
04/29/2021, 2:49 AM// ...
fun changeIcons(icons: Array<String>): Unit = memScoped {
gtk_scale_button_set_icons(gtkScaleButtonPtr, icons.toCStringArray(this))
}