ImportC rocks!

Steven Schveighoffer schveiguy at gmail.com
Mon Mar 14 13:30:44 UTC 2022


On 3/14/22 6:47 AM, Andrea Fontana wrote:
> On Saturday, 12 March 2022 at 09:55:03 UTC, Ki Rill wrote:
>> I tried using Raylib with importC, and I thought I should share my 
>> recent experience using it... Works like a charm! Worked from the 
>> first (second really) try!
>>
>> What I did step by step (in case someone needs directions):
>>
>> raylib.c:
>> ```
>> #include "raylib.h"
>> ```
>>
>> main.d:
>> ```
>> void main() {
>>     import raylib;
>>
>>     InitWindow(640, 640, "ImportC raylib test");
>>     // game loop
>>     CloseWindow();
>> }
>> ```
>>
>> Compiling:
>> ```
>> gcc -E raylib.c > raylib.i
>> dmd main.d raylib.c -L=-lraylib
>> ./main
>> ```
> 
> 
> The big problem is that #define are missing. So a lot of const must be 
> redefined or made explicit like:
> 
> ray.h:
> ```
> #include "raylib.h"
> Color RAYLIB_BLACK = BLACK;
>   ```
> 
> But  it's not so comfortable to use.
> 
> I would like to mix different languages, just like kotlin+java on 
> android development or like calypso did.
> 

Yes, C does not allow manifest constants of anything other than integers 
via enum. Raylib has eschewed most (all?) #defines of integers, 
preferring enums, but e.g. a `Color` struct cannot be an enum.

The pain of having to not only redeclare manifest constants but *also* 
give them a different name is pretty high.

-Steve


More information about the Digitalmars-d mailing list