Hello! Learning about cinterop-related types and s...
# multiplatform
v
Hello! Learning about cinterop-related types and still can't get them right. In the code below, how should I define
error
variable on the Kotlin side to call this C function?
Copy code
int analyze(char **error);
Related kotlin code:
Copy code
actual class Analysis {
    actual fun perform(): Int {
        
        val errorPointer = ???

        // type of `error` parameter is decompiled as `CValuesRef<CPointerVar<ByteVar>>?`
        val result = analyze(errorPointer)

        return result
    }
}
h
This is copied from my Objective C CoreData usage, but maybe it could help you too:
Copy code
fun <R> withErrorPointer(block: (CPointer<ObjCObjectVar<NSError?>>) -> R): Result<R> = memScoped {
    val errorPointer: ObjCObjectVar<NSError?> = alloc()
    val pointer = errorPointer.ptr

    val result = block(pointer)
    val error = pointer.pointed.value
    return if (error != null) {
        Result.failure(CoreDataError(error))
    } else {
        Result.success(result)
    }
}