Usually when writing a plugin I like to have keep the the loading/hooks code in a single file (ex. plugin.c
) and then having some kind of "context" object code in a separate file, often implemented in OO-style (ex. constructor, destructor, functions taking instance as first param, etc). The new plugin API has been designed specifically to make this possible.
To further improve the new plugin API, this PR adds changes that reduce the boilerplate needed to write an OO-style plugin (often GObject-based, but not necessarily) properly.
The first change is to add a macro to make it simpler to register a GObject type of which an instance is bound to the module loading/unloading lifetime.
The second change (which is leading to the 3rd change), simply adds typedefs and better documentation for the existing callback functions.
The third change is to add a second set of callback functions which get passed the instance data as the first parameter, in usual OO fashion. Typedefs are added to those from the 2nd change to allow casting functions to the right type. I'm not super fond of the _swapped
prefix, but some kind of different name is required to avoid breaking backwards compatibility.
Overall the changes are pretty trivial. I tested them using the code in this repo. To see how this improves the plugin code a little, see codebrainz/geany-test-object-friendly@87454f0 where I modified a normal plugin to use the changes in this PR.
The changes are completely backwards compatible.
Note: these changes are a result of my brain dump in these comments.
https://github.com/geany/geany/pull/1244
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or mute the thread.