Hi all,
I wanted to fully refactor Tsoding’s Eepers game as I believe it can be greatly improved upon.
One of the first things that I wanted to do, is to decouple the bindings to the Raylib library (written in C) from the main source code of the game. The reasoning behind this is that I want the Ada code to be fully Ada, and the C code to be hidden away. For that reason, I wanted to create a thick binding that would fully hide the C binding from the user.
I started my journey already, which you can see in my thick-binding branch. I have already done the porting (more or less) for the raymath module.
The experience was not great:
- creating the Ada function specs
- the C and Ada data-types
- the
To_C
(more on that later) andTo_Ada
functions - putting the C functions as internal function of the Ada functions
- creating the (very simple and repetitive!) bodies of the Ada functions…
I think this can be done better… Here is the thing, I know Ada allows for very simple function definitions to be one liners, see:
function Is_Origin (P : in Point) return Boolean is
(P.X = 0.0 and P.Y = 0.0);
And I thought that maybe I can simplify all this boilerplate to something easier in the spec file, like:
function My_Ada_Func(Left, Right : Vector2) return Vector2 is
((To_C(Left) + To_C(Right)); -- "+" operator is a C import
However, I cannot seem to be able to do it… Why?
Well, the “+” C-function needs to be visible, but I do not want that, I want it as a private function so that the consumer of the library cannot use it. However, I do want the My_Ada_Func
to be visible, and I cannot seem to be able to mix these two things together. And a very similar story takes place with the “custom” To_C
function. I do not want it to be visible, but it is needed by the Ada function…
Do you have any ideas or recommendations? Can the idea I am proposing here be done? Basically, what I want boils down to:
- Have potentially only the
.ads
file with simple function definitions (one liners like the one above) - Have all the C stuff hidden away and unable to be used by the library consumers
- Have it all work together
The Ada standard can be as new as needed.
Thank you for your help,
Fer
P.S.: you can take a look at the horrible code I have already changed in the link provided above.