Jeff Lockhart
09/22/2022, 9:03 PM[]
only available for CPointer<ByteVar>
? The docs seem to imply it should be possible for any CPointer<T>
, but I only see the extension available for CPointer<ByteVar>
(the docs show CPointer<BytePtr>
in the example code). Do I have to reinterpret<ByteVar>()
in order to iterate an array of a different pointer type?Landry Norris
09/22/2022, 11:47 PMLandry Norris
09/22/2022, 11:49 PMJeff Lockhart
09/23/2022, 7:33 PMinline operator fun <reified T : CStructVar> CPointer<T>?.plus(index: Int): CPointer<T>? =
interpretCPointer(this.rawValue + index * sizeOf<T>())
inline operator fun <reified T : CStructVar> CPointer<T>.get(index: Int): T =
(this + index)!!.pointed
inline fun <reified T : CStructVar, R> CPointer<T>.toList(
size: Int,
transform: (CPointer<T>) -> R
): List<R> {
val array = this
return buildList(size) {
repeat(size) { i ->
add(transform(array[i].ptr))
}
}
}