infinity-0.1.1: Plugins/PLUGINS
== introduction ==
writing plugins for infinity is remarkably simple.
here's a ~30 second tutorial to writing a plugin
that takes a string as an argument, and simply
reverses it.
1. create a file in Plugins/ under the name
ReversePlugin.hs.
2. Put this in the file:
-- snip
module ReversePlugin where
import API -- imports Infinity's API
plugin :: InfinityPlugin
plugin = InfinityPlugin {
name = "ReverseString",
commands = ["rev"],
description = "reverses a string",
action = rev
}
rev :: InfAction
rev _ _ s = (return . reverse) s
-- end snip
3. start infinity
4. done. infinity automatically compiles
and loads the plugin on startup! no
static compilation! (this has the
benefit that you don't need to
recompile upon adding new plugins
or modifying old ones, simply
restart infinity)
== notes ==
while writing plugins is quite simple, there
are a few things you should note:
1. the name of the file and the name
of the module as declared in the first
line of the file *must* be the same;
you cannot have a plugin with a module
name of "DestroyEarth" in the file
Plugins/NuclearBomb.hs.
2. plugins can register multiple commands,
these are passed to the action upon
invocation as the first parameter
3. the action in the plugin needs to have
a type of:
String -> String -> String -> IO String
the first argument is the nick of who
invoked the command, the second is the
name of the command that was invoked,
while the third is the actual
string that the user passed to
the command
4. if you need to return multiple lines of
output, simply turn your return your string
enclosed in unlines, i.e.:
return $ unlines ["Hello","World"]
infinity will correctly break this
into multiple lines and output it.
that is all. happy hacking...