Is there a known issue with cinterop having proble...
# kotlin-native
k
Is there a known issue with cinterop having problems converting macros with custom types? I'm trying to create a binding for C game framework library Raylib and it seems that custom defined colors of type struct Color holding unsigned char are not being converted over to Kotlin?
In the .header file, Colors are defined as:
Copy code
// Color, 4 components, R8G8B8A8 (32bit)
typedef struct Color {
    unsigned char r;        // Color red value
    unsigned char g;        // Color green value
    unsigned char b;        // Color blue value
    unsigned char a;        // Color alpha value
} Color;
And a macro is created as: #define LIGHTGRAY CLITERAL(Color){ 200, 200, 200, 255 } // Light Gray CLITERAL is yet another macro:
Copy code
// NOTE: MSVC C++ compiler does not support compound literals (C99 feature)
// Plain structures in C++ (without constructors) can be initialized with { }
#if defined(__cplusplus)
    #define CLITERAL(type)      type
#else
    #define CLITERAL(type)      (type)
#endif
a
Yeah, it doesn't resolve macros at the moment. You have to define a custom function in your .def file https://kotlinlang.org/docs/native-c-interop.html#add-custom-declarations
k
Yep, using this fixed the issue. Thank you
n
Kotlin doesn't support Macros, therefore custom definitions (via defined C functions) have to be provided, C constants (faked via Macros) are the main exception since they are automatically covered by the cinterop tool.
Adding Macros support to Kotlin would make the language too complicated, tooling support for Kotlin would become very poor, Kotlin code would be unreadable, backwards compatibility would head out the window, and build times would go through the roof.