electronstudio / jaylib

Java JNI bindings for Raylib
Other
113 stars 21 forks source link

Why `LoadImageColors` returns `Color` instead of `Color[]`? #52

Closed xzripper closed 2 months ago

xzripper commented 2 months ago

Raylib cheatsheet:

Color *LoadImageColors(Image image); // Load color data from image as a Color array (RGBA - 32bit)

Java:

public static native Raylib.Color LoadImageColors(@ByVal Raylib.Image var0);

And same issue with LoadMaterials, LoadRandomSequence, etc...

Why Jaylib returns single object instead of array?

electronstudio commented 2 months ago

Google "array to pointer decay".

The C function doesn't return an array - it returns a pointer. The pointer may point to an array, or it may point to a single struct. The compiler has no way to know from that function definition.

If we know that it has indeed returned an array, then we can access the other elements with https://electronstudio.github.io/jaylib/com/raylib/Raylib.Color.html#position(long)

electronstudio commented 2 months ago

https://github.com/electronstudio/jaylib?tab=readme-ov-file#arrays

xzripper commented 2 months ago

Thanks!