Calling a function from external library behaves differently #337
-
I'm trying to use raylib in Adept as a dynamic link library. Below I attached a snippet of Adept code and equivalent C code for comparison. Both does the following:
However, on Adept, Question: How to fix this? Is the data type incorrect? Test files: https://apis.s-ul.eu/j3HQICre Adept code: foreign 'raylib.dll'
record Color(r, g, b, a ubyte)
foreign InitWindow(int, int, *ubyte) void
foreign CloseWindow() void
foreign WindowShouldClose() bool
foreign SetTargetFPS(int) void
foreign BeginDrawing() void
foreign EndDrawing() void
foreign ClearBackground(Color) void
foreign DrawFPS(int, int) void
func main {
color Color = Color(50, 50, 50, 255)
InitWindow(800, 400, 'raylib - Adept')
SetTargetFPS(60)
until WindowShouldClose() {
BeginDrawing()
ClearBackground(color)
DrawFPS(16, 16)
EndDrawing()
}
CloseWindow()
} C code: #define RLAPI __declspec(dllimport)
typedef struct {unsigned char r, g, b, a;} Color;
RLAPI void InitWindow(int, int, char*);
RLAPI void CloseWindow();
RLAPI int WindowShouldClose();
RLAPI void SetTargetFPS(int);
RLAPI void BeginDrawing();
RLAPI void EndDrawing();
RLAPI void ClearBackground(Color);
RLAPI void DrawFPS(int, int);
int main() {
Color color = {50, 50, 50, 255};
InitWindow(800, 400, "raylib - C");
SetTargetFPS(60);
while (!WindowShouldClose()) {
BeginDrawing();
ClearBackground(color);
DrawFPS(16, 16);
EndDrawing();
}
CloseWindow();
} Result:
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
That's weird, it should work the same. I will see if I can reproduce it |
Beta Was this translation helpful? Give feedback.
-
It works as expected with |
Beta Was this translation helpful? Give feedback.
-
It turns out that the LLVM C calling convention doesn't properly work when passing some struct types by value. In the meantime, the following works:
|
Beta Was this translation helpful? Give feedback.
It turns out that the LLVM C calling convention doesn't properly work when passing some struct types by value.
In the meantime, the following works: