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?
Krystian
10/01/2022, 6:01 PM
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
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.
napperley
10/02/2022, 11:59 PM
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.