digitalmars.D.learn - Noob ImportC questions
- John C. (68/68) Feb 26 Hello everyone. Recently I get interested in some GUI-related
- Kapendev (4/9) Feb 26 Both RAYWHITE and LIGHTGRAY are defines and ImportC was not able
- John C. (5/14) Feb 27 Yes, when I added new test simple value macro ("#define TESTM
- John C. (14/16) Feb 27 I tried to change
- Kapendev (4/7) Feb 27 Seems like it has a hard time understanding structs. I tried
- Kapendev (2/9) Feb 27 Ignore my define lol.
- John C. (14/21) Feb 27 I have found YouTube video about ImportC and Raylib, author
- John C. (3/4) Feb 27 Of course, I had to rewrite all "RAYWHITE" to "raywhite", etc.,
- Steven Schveighoffer (6/22) Feb 28 #define constants translated to enums are very limited in
- monkyyy (2/5) Feb 26 I think `import raylib` finds raylib.c
- John C. (4/5) Feb 26 Thank you, it were actually using raylib.c in both cases. When I
- John C. (3/6) Feb 27 I have tested some basic Raylib functionality from examples on
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` ```
Feb 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.
Feb 26
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: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?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.
Feb 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?
Feb 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.
Feb 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:Ignore my define lol.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.
Feb 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: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.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.
Feb 27
On Thursday, 27 February 2025 at 13:33:55 UTC, John C. wrote:all code I have tested worked perfectly.Of course, I had to rewrite all "RAYWHITE" to "raywhite", etc., but I'm happy to have working GUI library now!
Feb 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:#define constants translated to enums are very limited in importC. Numbers and strings work. These color defines do not work. In raylib-d the color defines are all translated by hand. https://dlang.org/spec/importc.html#defines -Stevewould 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?
Feb 28
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
Feb 26
On Wednesday, 26 February 2025 at 21:08:19 UTC, monkyyy wrote:I think `import raylib` finds raylib.cThank 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?)
Feb 26
On Wednesday, 26 February 2025 at 17:00:48 UTC, John C. wrote:2. 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.
Feb 27