Skip to content

Calling a function from external library behaves differently #337

Answered by IsaacShelton
Apis035 asked this question in Q&A
Discussion options

You must be logged in to vote

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:

foreign 'raylib.dll'

record Color(r, g, b, a ubyte)

foreign InitWindow(int, int, *ubyte) void
foreign CloseWindow() void
foreign WindowShouldClose() int
foreign SetTargetFPS(int) void
foreign BeginDrawing() void
foreign EndDrawing() void
foreign ClearBackground(int) void
foreign DrawFPS(int, int) void

func ClearBackground(color Color) {
    ClearBackground(*cast *int &color)
}

func main {
    color Color = Color(50, 50, 50, 255)

    InitWindow(800, 400, 'raylib - Adept')
    SetTargetFPS(60)
    until WindowShouldClose() {
        BeginD…

Replies: 3 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@Apis035
Comment options

Answer selected by Apis035
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants