comparison plugins/PERL-HOWTO @ 3551:cd938f18f3f8

[gaim-migrate @ 3626] In the interest of continued progress, I pulled what's usable out of my development tree and am committing it. Here, we have gotten rid of the plugins dialog and perl menu under Tools and put them both in preferences. Perl scripts now work like plugins--you have to load them explicitly (it will probe $prefix/lib/gaim and $HOME/.gaim for them) and you can unload them (although right now, this is entirely unreliable) Oh, and I broke all your perl scripts. Sorry about that. Don't try fixing them yet, though--I'm gonna make unloading single scripts more reliable tommorow. I should also finish Phase Two tommorow as well. committer: Tailor Script <tailor@pidgin.im>
author Sean Egan <seanegan@gmail.com>
date Thu, 26 Sep 2002 07:37:52 +0000
parents b48065e52337
children e120097bbd72
comparison
equal deleted inserted replaced
3550:e9b2003ee562 3551:cd938f18f3f8
1 This is really the wrong place for a HOWTO on writing perl scripts for gaim, 1 So, you wanna write a perl script.
2 but there didn't seem to be a much better place.
3 2
4 If you've ever written a perl script for X-Chat then you've basically written 3 Perl scripts in Gaim can be very useful. Although they can't directly manipulate
5 one for gaim as well. perl.c in gaim's source is basically an exact copy of 4 Gaim data like a plugin, or provide any sort of UI, they're portable, easy to develop
6 X-Chat's perl.c file, with small modifications to suit Gaim rather than IRC. 5 rapidly and extremely powerful when manipulating incoming and outgoing messages.
7 6
8 Basically the reason for including perl is based on the experience with the 7 This document assumes you know perl--Gaim perl scripts work exactly like normal perl
9 plugins. X-Chat's docs on Perl Scripting sums it up nicely: 8 scripts, with a few extra commands you can use.
10 it's not quite as simple to stick a module together in C and make it
11 stable compared to the development time of perl code
12 9
13 Plugins are more powerful as they can directly access gaim's functions and 10 The first thing Gaim will do with your plugin (provided it's in $prefix/lib/gaim or
14 variables; as such they should be used for things like modifying the UI or 11 $HOME/.gaim/) is look for and call a function called "description". description()
15 when something takes quite a bit of trickery not offered by perl. But for 12 gives Gaim the information it will use in the plugins dialog--script name, version,
16 the most part things should be written in Perl. It's more stable than 13 your name--all sorts of good things. Let's look at an example:
17 plugins.
18 14
19 There's a really quick simple perl script in this directory, gaim.pl, that 15 sub description {
20 should show most of the functions. Most things should be self-explanatory. 16 my($a, $b, $c, $d, $e, $f) = @_;
17 ("Example", "1.0", "An example Gaim perl script that does nothing
18 particularly useful:\n\t-Show a dialog on load\n\t-Set user idle for
19 6,000 seconds\n\t-Greets people signing on with \"Hello\"\n\t-Informs
20 you when script has been loaded for one minute.",
21 "Eric Warmenhoven &lt;eric\@warmenhoven.org>", "http://gaim.sf.net",
22 "/dev/null");
23 }
21 24
22 There's one thing you need to be aware of in perl scripts for gaim. Gaim 25 This pushes what's needed to the perl stack. What is all that stuff?
23 supports multiple connections, and perl deals with them by using a unique 26 $a - Name
24 identifier for each of them (that's a fancy way of saying that perl scripts 27 $b - Version
25 use the memory address of the connection). 28 $c - Description
29 $d - Authors
30 $e - Webpage
31 $f - Icon (this is the path to an icon Gaim will use for your script)
26 32
27 Everything available in normal perl scripts should be available in gaim's 33 It should be noted that this information will be formatted according to Pango's
28 perl interface, so I'm not going to bother describing that. The important 34 markup language--a language akin to HTML. This is neat in that it lets you bold
29 things are the functions provided by gaim's internal GAIM module, which is 35 and italicize your description and stuff, but it's important you take care to
30 what most of this document is about. So, onto the functions. 36 properly escape stuff (notice the &lt; in $d).
37
38 Now, for the Gaim-specific perl functions (if you know x-chat scripts, you'll
39 feel right at home):
31 40
32 GAIM::register(name, version, shutdownroutine, unused) 41 GAIM::register(name, version, shutdownroutine, unused)
33 Just like X-Chat. This is the first function your script should call. 42 Just like X-Chat. This is the first function your script should call.
34 shutdownroutine is a function that will be called when the script 43 shutdownroutine is a function that will be called when the script
35 gets unloaded (like when gaim gets closed). This function returns 44 gets unloaded (like when gaim gets closed). This function returns