Jump to page: 1 2
Thread overview
Noob ImportC questions
Feb 26
John C.
Feb 26
Kapendev
Feb 27
John C.
Feb 27
John C.
Feb 27
Kapendev
Feb 27
Kapendev
Feb 27
John C.
Feb 27
John C.
Feb 26
monkyyy
Feb 27
John C.
Feb 27
John C.
February 26

Hello everyone. Recently I get interested in some GUI-related stuff and I want to use Raylib in my project. I know about raylib-d, dray, etc. bindings, but I would like to see what can ImportC do for me in this situation.
I have following project hierarchy:

project/
  src/
    main.d
    raylib.c
  lib/
    raylib/
      include/
        raylib.h
      libraylib.a

main.d contents:

import raylib;

void main() {
    InitWindow(800, 600, "Hello, Raylib!");
    SetTargetFPS(60);
    while (!WindowShouldClose()) {
        BeginDrawing();
            ClearBackground(Color(245, 245, 245, 255));
            DrawText("Hello, Raylib!", 400, 300, 28, Color(200, 200, 200, 255));
        EndDrawing();
    }
    CloseWindow();
}

raylib.c contents:

#include "../lib/raylib/include/raylib.h"

Raylib header file and library files were downloaded from Raylib GitHub releases page.
Here some questions about it and object file layout arised (it's important to mention that I'm newbie in D and programming at all):

  1. Why both "ldmd2 main.d raylib.c -L../lib/raylib/libraylib.a" and "ldmd2 main.d -L../lib/raylib/libraylib.a" produce working executable? main.d code in second example does not have access to header inclusions, or this data is already available in library file?
  2. Why main.d version with "Color(...)" replaced by "RAYWHITE" or "LIGHTGREY" (defined in header) will not compile with "undefined identifier" error?

Modified main.d:

import raylib;

void main() {
    InitWindow(800, 600, "Hello, Raylib!");
    SetTargetFPS(60);
    while (!WindowShouldClose()) {
        BeginDrawing();
            ClearBackground(RAYWHITE);
            DrawText("Hello, Raylib!", 400, 300, 28, LIGHTGRAY);
        EndDrawing();
    }
    CloseWindow();
}

Error (with both commands above, same result):

main.d(8): Error: undefined identifier `RAYWHITE`
main.d(9): Error: undefined identifier `LIGHTGRAY`
February 26

On Wednesday, 26 February 2025 at 17:00:48 UTC, John C. wrote:

>

Error (with both commands above, same result):

main.d(8): Error: undefined identifier `RAYWHITE`
main.d(9): Error: undefined identifier `LIGHTGRAY`

Both RAYWHITE and LIGHTGRAY are defines and ImportC was not able to parse them, so they don't exist.
No idea about the first question.

February 26

On Wednesday, 26 February 2025 at 17:00:48 UTC, John C. wrote:

>

Why both "ldmd2 main.d raylib.c -L../lib/raylib/libraylib.a" and "ldmd2 main.d -L../lib/raylib/libraylib.a" produce working executable?

I think import raylib finds raylib.c

February 27

On Wednesday, 26 February 2025 at 21:08:19 UTC, monkyyy wrote:

>

I think import raylib finds raylib.c

Thank you, it were actually using raylib.c in both cases. When I renamed this file, import was made impossible (I think it should have happened?)

February 27

On Wednesday, 26 February 2025 at 18:53:40 UTC, Kapendev wrote:

>

On Wednesday, 26 February 2025 at 17:00:48 UTC, John C. wrote:

>

Error (with both commands above, same result):

main.d(8): Error: undefined identifier `RAYWHITE`
main.d(9): Error: undefined identifier `LIGHTGRAY`

Both RAYWHITE and LIGHTGRAY are defines and ImportC was not able to parse them, so they don't exist.
No idea about the first question.

Yes, when I added new test simple value macro ("#define TESTM 123"), main.d was able to use it. So, this problem is connected to ImportC parsing capabilities? If it is, would removing some "hard to parse" constructs in header file help this situation?

February 27

On Thursday, 27 February 2025 at 08:10:04 UTC, John C. wrote:

>

would removing some "hard to parse" constructs in header file help this situation?

I tried to change

#define LIGHTGRAY       CLITERAL(Color){ 200, 200, 200, 255 }    // Light Gray

To more simpler definition which does not contain other previously defined macros (such as CLITERAL above)

#define LIGHTGRAY       (Color){ 200, 200, 200, 255 }            // Light Gray

But this change was not helpful, same error occured. Does this mean that ImportC cannot parse object literals?

February 27

On Wednesday, 26 February 2025 at 17:00:48 UTC, John C. wrote:

>
  1. Why main.d version with "Color(...)" replaced by "RAYWHITE" or "LIGHTGREY" (defined in header) will not compile with "undefined identifier" error?

I have tested some basic Raylib functionality from examples on their website and seems that only colors are not available.

February 27

On Thursday, 27 February 2025 at 08:16:33 UTC, John C. wrote:

>

On Thursday, 27 February 2025 at 08:10:04 UTC, John C. wrote:
But this change was not helpful, same error occured. Does this mean that ImportC cannot parse object literals?

Seems like it has a hard time understanding structs. I tried something like #define MY_COLOR struct Color {...}, but got the same error.

February 27

On Thursday, 27 February 2025 at 12:48:19 UTC, Kapendev wrote:

>

On Thursday, 27 February 2025 at 08:16:33 UTC, John C. wrote:

>

On Thursday, 27 February 2025 at 08:10:04 UTC, John C. wrote:
But this change was not helpful, same error occured. Does this mean that ImportC cannot parse object literals?

Seems like it has a hard time understanding structs. I tried something like #define MY_COLOR struct Color {...}, but got the same error.

Ignore my define lol.

February 27

On Thursday, 27 February 2025 at 12:48:19 UTC, Kapendev wrote:

>

On Thursday, 27 February 2025 at 08:16:33 UTC, John C. wrote:

>

On Thursday, 27 February 2025 at 08:10:04 UTC, John C. wrote:
But this change was not helpful, same error occured. Does this mean that ImportC cannot parse object literals?

Seems like it has a hard time understanding structs. I tried something like #define MY_COLOR struct Color {...}, but got the same error.

I have found YouTube video about ImportC and Raylib, author writes many constants to make ImportC parse colors successfully.
His raylib.c looked like following:

#include "../lib/raylib/include/raylib.h"

const Color lightgray = LIGHTGRAY;
const Color gray = GRAY;
const Color darkgray = DARKGRAY;
const Color yellow = YELLOW;
...

After applying this modification to raylib.c, all code I have tested worked perfectly.

« First   ‹ Prev
1 2