Craftd:Plugins: Difference between revisions

From wiki.vg
Jump to navigation Jump to search
imported>Meh.
(Created page with "== Plugins == Writing a plugin is pretty simple, you just have to create a loadable object with the 2 following functions: <syntaxhighlight lang="C"> extern bool CD_PluginIniti...")
imported>Kev009
(add plugin stub)
Line 25: Line 25:
It's adviced to use the hash in PRIVATE(self) instead of global static variables to keep the data, in this way other plugins
It's adviced to use the hash in PRIVATE(self) instead of global static variables to keep the data, in this way other plugins
can work with the data of your plugin if they want to.
can work with the data of your plugin if they want to.
=== Building Plugins ===
There are no requirements on specific build systems when writing plugins.
craftd uses autotools, and more specifically, [http://www.gnu.org/software/libtool/manual/ libtool] internally.  craftd uses lt_dlopenext() to load your plugins, so it will correctly load i.e. .so, .sl, .dylib, .dll as appropriate for the system you are running on. 
Note, however, that using libtool is advised to make using your plugin possible on many system types.
pkg-config files will be added in the future to ease cflag and include requirements for build/linkage.


[[Category:Craftd]]
[[Category:Craftd]]

Revision as of 01:50, 1 March 2011

Plugins

Writing a plugin is pretty simple, you just have to create a loadable object with the 2 following functions:

<syntaxhighlight lang="C"> extern bool CD_PluginInitialize (CDPlugin* self) {

   // Initialize data, register to events, register to timeouts, do whatever is need to initialize your plugin
   // return true if everything went as expected, return false to let the plugin manager know this plugin wasn't loaded correctly

}

extern bool CD_PluginFinalize (CDPlugin* self) {

   // Destroy data, unregister events and stuff
   // Same as for the initialize, return value states if the plugin unloaded correctly

} </syntaxhighlight>

It's adviced to use the hash in PRIVATE(self) instead of global static variables to keep the data, in this way other plugins can work with the data of your plugin if they want to.

Building Plugins

There are no requirements on specific build systems when writing plugins.

craftd uses autotools, and more specifically, libtool internally. craftd uses lt_dlopenext() to load your plugins, so it will correctly load i.e. .so, .sl, .dylib, .dll as appropriate for the system you are running on.

Note, however, that using libtool is advised to make using your plugin possible on many system types.

pkg-config files will be added in the future to ease cflag and include requirements for build/linkage.