Jump to: navigation, search


Plugins for Craftd are placed in subdirectories under the ./plugins directory. It is standard to have main.c, in which the following statements are needed to do much of value:

#include <craftd/Server.h>
#include <craftd/Plugin.h>

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

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

CD_PluginFinalize (CDPlugin* self)
    // Destroy data, unregister events and stuff

    // Same as for the initialize, return value states if the plugin unloaded correctly

It's advised 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.