Lisp and bindings to GObject

Hello,
I am trying to make Common Lisp work with Gtk4 and I have a few questions. Using typelib introspection, I was able to reproduce all the basic examples of the Gtk4 intro, up to, and including, the use of the Builder.
The next step would be to do subclassing and use the templating facility, but it looks like this requires a good integration with GObject. I can bind to the GObject (GLib) library with typelib/introspection, and I am able to register a new type, but it is not clear to me how to create an instance of the new type (which is a subclass of a Gtk widget). The problem is that none of the constructors for GObject are available to language bindings, except g_object_newv, which is deprecated.
What is the expectation for language bindings to GObject?

  1. Do the class building and object instantiation “manually”, calling the constructors/destructors along the inheritance tree? That seems contrary to the philosophy of GObject, which is supposed to do all that for us.
  2. Write a C blob that can bind to the language and can access the GObject constructors? It looks like this is the approach of pygobject, Guile and Lua bindings, and probably many others. But Lisp has a foreign function interface that normally spares you the need to do that.
  3. Bind to the GObject constructors without going through introspection?
  4. Other?

As an extra question, what are the advantages of a tight integration with GObject (i.e. the possibility of having derived classes in the language that are registered to and mirrored in the GObject type system), besides the access to the XML templating facility?
Thanks!

Yes, you need to manually call those functions through FFI, or write a shim. For performance reasons I would recommended putting as much as you can in a shim and avoiding FFI. There are many, many things that need to be implemented manually (i.e. not through introspection) to get subclassing to work and to have a good experience with the target language.

Any non-final GObject type can be subclassed, not just widgets.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.