https://kotlinlang.org logo
Title
j

josemeyer

05/08/2017, 12:09 PM
@olonho , one think that i didn't understand taking a look at the documentation was how can i pass a CValue as a struct parameter to a C function. One example is that i've tried to use a function from SDL2 which expects a struct parameter SDL_color, so i need to create this on kotlin with some values like {255, 255, 255} and then use it when call the function. Can you help me with that please?
o

olonho

05/08/2017, 2:20 PM
josemeyer: usually, to create C structure you need to initialize each field individually, see using of SDL in Tetris example
s

svyatoslav.scherbina

05/08/2017, 2:37 PM
You can create
CValue
by initializing each field individually using the following expression:
cValue<SDL_Color> {
    r = 255
    g = 255
    b = 255
    a = 0
}
If the type is known (e.g. when this expression is used as function argument), then type argument can be omitted:
cValue {
    r = 255
    ...
}
(This approach is not documented yet, and the previous one with
readValue
, described at https://github.com/JetBrains/kotlin-native/blob/master/INTEROP.md#passing-and-receiving-structs-by-value is less convenient)
j

josemeyer

05/08/2017, 6:17 PM
Thanks @svyatoslav.scherbina and @olonho, i think my problems were more related to how to initialize a CValue with the respective fields and with this example it's clear to me now. Thanks again and congrats to this awesome work that you have done.