<p>Usually when writing a plugin I like to have keep the the loading/hooks code in a single file (ex. <code>plugin.c</code>) 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.</p>

<p>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.</p>

<p>The <a href="https://github.com/codebrainz/geany/commit/cafa5a6513979523090e9b16fbe4cc59e0312590">first change</a> 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.</p>

<p>The <a href="https://github.com/codebrainz/geany/commit/16c487aa0db51e41c39026636cec13f0a959c431">second change</a> (which is leading to the 3rd change), simply adds typedefs and better documentation for the existing callback functions.</p>

<p>The <a href="https://github.com/codebrainz/geany/commit/ac66af8e2ff450dfa2e02b2f42fe623813f83b1c">third change</a> 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 <code>_swapped</code> prefix, but some kind of different name is required to avoid breaking backwards compatibility.</p>

<p>Overall the changes are pretty trivial. I tested them using the code <a href="https://github.com/codebrainz/geany-test-object-friendly">in this repo</a>. To see how this improves the plugin code a little, see <a href="https://github.com/codebrainz/geany-test-object-friendly/commit/87454f0c2908b423491053ef9d1f5bbb2174facf" class="commit-link">codebrainz/geany-test-object-friendly@<tt>87454f0</tt></a> where I modified a normal plugin to use the changes in this PR.</p>

<p>The changes are completely backwards compatible.</p>

<p>Note: these changes are a result of my <a href="https://github.com/geany/geany/commit/437837d3a54367393c41d6c1e1f4d1af4481627e#commitcomment-19107275">brain dump in these comments</a>.</p>

<hr>

<h4>You can view, comment on, or merge this pull request online at:</h4>
<p>  <a href='https://github.com/geany/geany/pull/1244'>https://github.com/geany/geany/pull/1244</a></p>

<h4>Commit Summary</h4>
<ul>
  <li>Add helper macro to register module-scoped GObjects</li>
  <li>Add typedefs and more documentation for plugin funcs</li>
  <li>Add swapped plugin funcs, typedefs and documentation</li>
</ul>

<h4>File Changes</h4>
<ul>
  <li>
    <strong>M</strong>
    <a href="https://github.com/geany/geany/pull/1244/files#diff-0">src/plugindata.h</a>
    (185)
  </li>
  <li>
    <strong>M</strong>
    <a href="https://github.com/geany/geany/pull/1244/files#diff-1">src/plugins.c</a>
    (39)
  </li>
  <li>
    <strong>M</strong>
    <a href="https://github.com/geany/geany/pull/1244/files#diff-2">src/pluginutils.c</a>
    (11)
  </li>
</ul>

<h4>Patch Links:</h4>
<ul>
  <li><a href='https://github.com/geany/geany/pull/1244.patch'>https://github.com/geany/geany/pull/1244.patch</a></li>
  <li><a href='https://github.com/geany/geany/pull/1244.diff'>https://github.com/geany/geany/pull/1244.diff</a></li>
</ul>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br />You are receiving this because you are subscribed to this thread.<br />Reply to this email directly, <a href="https://github.com/geany/geany/pull/1244">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/ABDrJz11EdQZAF1WvVWt8hYVkVIOAhrYks5qsetxgaJpZM4KDeG5">mute the thread</a>.<img alt="" height="1" src="https://github.com/notifications/beacon/ABDrJwA9HurRuLr0F7WhBCaxpbBmVLtkks5qsetxgaJpZM4KDeG5.gif" width="1" /></p>
<div itemscope itemtype="http://schema.org/EmailMessage">
<div itemprop="action" itemscope itemtype="http://schema.org/ViewAction">
  <link itemprop="url" href="https://github.com/geany/geany/pull/1244"></link>
  <meta itemprop="name" content="View Pull Request"></meta>
</div>
<meta itemprop="description" content="View this Pull Request on GitHub"></meta>
</div>

<script type="application/json" data-scope="inboxmarkup">{"api_version":"1.0","publisher":{"api_key":"05dde50f1d1a384dd78767c55493e4bb","name":"GitHub"},"entity":{"external_key":"github/geany/geany","title":"geany/geany","subtitle":"GitHub repository","main_image_url":"https://cloud.githubusercontent.com/assets/143418/17495839/a5054eac-5d88-11e6-95fc-7290892c7bb5.png","avatar_image_url":"https://cloud.githubusercontent.com/assets/143418/15842166/7c72db34-2c0b-11e6-9aed-b52498112777.png","action":{"name":"Open in GitHub","url":"https://github.com/geany/geany"}},"updates":{"snippets":[{"icon":"DESCRIPTION","message":"Improvements to plugin mechanism for OO-style plugins (#1244)"}],"action":{"name":"View Pull Request","url":"https://github.com/geany/geany/pull/1244"}}}</script>