]> sipb.mit.edu Git - ikiwiki.git/blob - doc/todo/support_for_plugins_written_in_other_languages.mdwn
web commit by http://edward.myopenid.com/: fix code block rendering
[ikiwiki.git] / doc / todo / support_for_plugins_written_in_other_languages.mdwn
1 ikiwiki should support writing plugins in other languages
2
3 > [[done]] !!
4
5 While it should be possible to call ikiwiki from C, doing the callbacks in C is
6 probably hard. And accessing perl at all from C is ugly. It also doesn't
7 make it very easy to write plugins in an interpreted language, since that
8 would mean linking perl and eg, python in one binary. (Been there, done
9 that, never again.)
10
11 Instead, I'm considering using XML RPC to let ikiwiki communicate with a
12 child process that it can spawn. The child could then be any program,
13 written in any language. It could talk XML RPC via stdio. (This assumes
14 that most languages allow easily serialising XML::RPC calls and responses
15 to a file descriptor. Some XML RPC implementations may be hardcoded to use
16 http..) For ease of implementation, each rpc request sent via stio should
17 end with a newline, and begin with "<?xml ..>".
18
19 Here's how it would basically look, not showing the actual XML RPC used to
20 pass values.
21
22         -> call import
23         <- call hook type => preprocess, id => foo, call => plugin_preprocess
24         -> result 1
25         <- result 1
26
27         -> call plugin_preprocess page => bar
28         <- call getconfig url
29         -> result "http://example.com", ...
30         <- call debug "foo"
31         -> result 1
32         <- result done "my return value"
33
34 From ikiwiki's POV:
35
36 * ikiwiki always initiates each conversation with a command
37 * After sending a command, ikiwiki reads commands, dispatches them, and 
38   returns the results, in a loop, until it gets a result for the command it
39   called.
40
41 From the plugin's POV:
42
43 * It's probably sitting in an XML::RPC loop.
44 * Get a command from ikiwiki.
45 * Dispatch the command to the appropriate function.
46 * The function can use XML::RPC to communicate with ikiwiki to get things
47   like config values; and to call ikiwiki functions.
48 * Send the function's return value back to ikiwiki.
49
50 Simple enough, really. ikiwiki would need to add accessor functions for
51 all important variables, such as "getconfig" and "setconfig". It would
52 probably be easiest for ikiwiki to dispatch a command by just evaling
53 IkiWiki::$command.
54
55 Plugin programs could be dropped into /usr/share/ikiwiki/plugins/, and
56 load_plugin() would just open2 the plugin program and call import.