How can I create wrapper classes for generated c s...
# kotlin-native
u
How can I create wrapper classes for generated c structs? Whats the common pattern? I want to hide away the usage of pointers, c values, and such and leave that as internals. Trying to create a kotlin port of a c lib which I then want to call within a kotlin jvm project. Not sure if this is possible or proper way of doing so though as I have little experience.
Copy code
class Vector3D(var x: Float, var y: Float, var z: Float) {
    internal fun asNative() = nativeHeap.alloc<aiVector3D> {
        x = this@Vector3D.x
        y = this@Vector3D.y
        z = this@Vector3D.z
    }

    companion object {
        internal fun create(cPointer: CPointer<aiVector3D>): Vector3D {
            val aiVector = cPointer.pointed
            return Vector3D(aiVector.x, aiVector.y, aiVector.z)
        }
    }
}
Would this be a proper way?
c
Check out kotlinx-gtk for an example
Essentially you need to make the pointer an internal value only