The Rest
Now that you know how to write native functions by hand this section is a piece of cake. All you have to do
to fullfill the requirements of a ferite module is write four functions. Yes it is that easy. These functions
are the ones that builder creates for you from module-init, module-deinit, module-register, and
module-unregister. Rather than talk too much, I will show you the code for a blank module:
void modulename_register()
{
System wide setup. Called when the module is loaded from disk.
}
void modulename_init( FeriteScript *script )
{
Per script setup. This is where you put the code to register
namespaces, classes, functions and variables and setup anything the script
needs.
}
void modulename_deinit( FeriteScript *script )
{
Anything you need to shutdown per script. Ferite will clean up
all structures you have registered so you do not need to clean those up
yourself [eg. the namespaces you have registered].
}
void modulename_unregister()
{
System wide shutdown. This gets called when the ferite engine is
being deinitialised.
}
|
If you have these four functions exported from you module, it will find them without problem. One thing to
note, the name of the module must be the same as the prefix for each of the functions
otherwise ferite will not be able to find them. For instance in foo.lib the init function
must be called foo_init.
The hardest part of writing a module is probably getting it to compile and be installed. But that will be left
as an exercise to the reader. [Hint: look at generate-module, a tool shipped with ferite
for installing modules written using builder - but can be modified to handle home made modules].
You may also want to read the next chapter as a cunning secret is told that can make writing native modules
easier.