Allow implementing GTypeInterfaces
We need to allow implementing an existing GTypeInterface
on a newly-defined class. For example, implement GtkTreeModelIface
.
impl SomeInterface for Foo
should be enough for the user to say that they want to implement an interface.
We need to:
-
Generate a
GInterfaceInfo
struct, with pointers to our interface initialization functions. -
Generate the interface initialization function, which fills in the vtable.
-
For each implemented method, fill it into the vtable.
An unresolved question is, how can we ensure that the user in fact implemented all the methods in the interface? We don't have a list of them in the procedural macro; we would have to extract that info from the GIR file. For now, it's probably acceptable to initialize the vtable to all-zeros and let program crash if it runs into an unimplemented method.
- Vala reference for interfaces - note that this mostly concerns defining new interfaces; their implementation is simply this:
interface Speaker : Object { // here Object is an interface prerequisite
public abstract void speak ();
}
/* Fox: implements Speaker, implements speak () */
class Fox : Object, Speaker {
public void speak () {
stdout.printf (" Fox says Ow-wow-wow-wow\n");
}
}