<@U3SK5B492> , one think that i didn't understand ...
# kotlin-native
j
@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
josemeyer: usually, to create C structure you need to initialize each field individually, see using of SDL in Tetris example
s
You can create
CValue
by initializing each field individually using the following expression:
Copy code
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:
Copy code
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
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.