when I read a typelib, I can call any callable described in a GICallableInfo with its method g_callable_info_invoke. In order to do that, GICallableInfo gives enough information and what to pass and what to receive, and then g_callable_info_invoke does the job.
That’s as far as I went! Then there is girffi within libgirepository and then there is libffi.
I’d like a simple example showing how to use all of this together (reading the python bindings is just too much work to answer this question), and understand the benefits of using it instead of the invoke method directly.
I’ve read somewhere it’s faster because I can cache the call. But if I have to build the arguments each time I want to use an ffi_cif, what’s the benefit?
So examples and explanations would be most welcome.
they all have a set of methods, inherited from GICallableInfo to know and set the list of arguments and the return value.
moreover, the method g_callable_info_invoke, is as the name suggests (and certainly not the doc which is full of TODO), used to make the call itself. This method has 10 arguments! That’s a lot!
in a language bindings, the user would call the target function (like a method in a Gtk object for example)
This function would be matched by your language bindings to the corresponding GICallableInfo object (or one of its children).
Then your language bindings will marshall the arguments from your language into the corresponding arguments as required by the GICallableInfo parameters (marshall = transform them from the representation in your language into their representation in C),
then your language bindings will call the g_callable_info_invoke for the GICallableInfo method,
get the results of the target function, unmarshall the result (=return of the function) back to a type that your language can understand
I keep answering to myself once again.
In fact, everything can be called with an invoker. But the code is quite heavy to write.
I wrote an example with tons of comments in it to show how to create a window and associate a callback with a closure, only using introspection.
It’s make with Gtk4 by the way.
The code is in this repository: GitHub - yimyom/understanding_gtk_and_gobject: Code I wrote to understand and experiment with Gtk and GObject and the file is called with_invoker.c.