[Github-comments] [geany/geany] Improvements to plugin mechanism for OO-style plugins (#1244)

Matthew Brush notifications at xxxxx
Thu Sep 22 02:44:01 UTC 2016


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](https://github.com/codebrainz/geany/commit/cafa5a6513979523090e9b16fbe4cc59e0312590) 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](https://github.com/codebrainz/geany/commit/16c487aa0db51e41c39026636cec13f0a959c431) (which is leading to the 3rd change), simply adds typedefs and better documentation for the existing callback functions.

The [third change](https://github.com/codebrainz/geany/commit/ac66af8e2ff450dfa2e02b2f42fe623813f83b1c) 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](https://github.com/codebrainz/geany-test-object-friendly). To see how this improves the plugin code a little, see https://github.com/codebrainz/geany-test-object-friendly/commit/87454f0c2908b423491053ef9d1f5bbb2174facf 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/commit/437837d3a54367393c41d6c1e1f4d1af4481627e#commitcomment-19107275).
You can view, comment on, or merge this pull request online at:

  https://github.com/geany/geany/pull/1244

-- Commit Summary --

  * Add helper macro to register module-scoped GObjects
  * Add typedefs and more documentation for plugin funcs
  * Add swapped plugin funcs, typedefs and documentation

-- File Changes --

    M src/plugindata.h (185)
    M src/plugins.c (39)
    M src/pluginutils.c (11)

-- Patch Links --

https://github.com/geany/geany/pull/1244.patch
https://github.com/geany/geany/pull/1244.diff

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/geany/geany/pull/1244
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.geany.org/pipermail/github-comments/attachments/20160921/b3614d60/attachment.html>


More information about the Github-comments mailing list