Going over the documentation, I always see that *Class
structs contain either parent, vfuncs, or reserved space. Being C of course, there’s nothing limiting the fields to those types, and they could be simple types (int
s, double
, gchar*
, etc.) instead. For example, in C I can do this:
struct _LibraryObjectClass {
/*< private >*/
GObjectClass parent_class;
/*< public >*/
gchar *class_member;
/*< private >*/
gpointer reserved[4];
};
and assign class_member
in class_init
. Looking at the GObject introspection data, that information is clearly parsed and preserved in the .gir
:
<record name="ObjectClass"
c:type="LibraryObjectClass"
glib:is-gtype-struct-for="Object">
<source-position filename="../lib/mylib-0.h" line="52"/>
<field name="parent_class" readable="0" private="1">
<type name="GObject.ObjectClass" c:type="GObjectClass"/>
</field>
<field name="class_member">
<type name="utf8" c:type="gchar*"/>
</field>
<field name="reserved" readable="0" private="1">
<array zero-terminated="0" fixed-size="4">
<type name="gpointer" c:type="gpointer"/>
</array>
</field>
</record>
In C, I can create subclasses which set this field, and then access them in functions, but I cannot figure out how to do this from languages using GIR bindings.
For example, Vala docs mention instance, class, and static fields, but if I mark a field as class
, it does not set the LibraryObjectClass->class_member
field. I tried to do a similar thing in Python with PyGObject, but there doesn’t seem to be any magic to setup class fields (that I could find in the implementation.)
Is this actually something that’s supported? Have bindings simply never encountered or needed to implement it? Or is this just not something that’s supposed to be done. The docs simply never mention non-vfunc fields, either for or against.
You can find a full example here:
https://gitlab.gnome.org/QuLogic/gir-test