changeset 806:67bdecdecbb7

[gaim-migrate @ 816] yay, i think perl is finally working well committer: Tailor Script <tailor@pidgin.im>
author Eric Warmenhoven <eric@warmenhoven.org>
date Thu, 31 Aug 2000 01:40:58 +0000
parents 2f0655e185b8
children 632d781c29da
files plugins/PERL-HOWTO plugins/gaim.pl src/gaim.h src/perl.c src/plugins.c
diffstat 5 files changed, 45 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/PERL-HOWTO	Thu Aug 31 01:07:39 2000 +0000
+++ b/plugins/PERL-HOWTO	Thu Aug 31 01:40:58 2000 +0000
@@ -16,6 +16,9 @@
 the most part things should be written in Perl. It's more stable than
 plugins.
 
+There's a really quick simple perl script in this directory, gaim.pl, that
+should show most of the functions. Most things should be self-explanatory.
+
 Everything available in normal perl scripts should be available in gaim's
 perl interface, so I'm not going to bother describing that. The important
 things are the functions provided by gaim's internal AIM module, which is
@@ -107,8 +110,9 @@
 	short-circut gaim (that is, your script will be called in order it was added,
 	despite what other scripts do, and afterwards, execution will continue as
 	normal). Names of buddies and chat rooms will be in quotes, and all other
-	values (like text messages) will not be.
+	values (like text messages) will not be. (Watch the debug window to get a
+	better feel for this, or better yet, look at the bottom of plugins.c.)
 
 AIM::add_timeout_handler(integer, function)
 	This calls function after integer number of seconds. It only calls function
-	once, so if you want to keep calling function, keep reading the handler.
+	once, so if you want to keep calling function, keep readding the handler.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/plugins/gaim.pl	Thu Aug 31 01:40:58 2000 +0000
@@ -0,0 +1,31 @@
+AIM::register("gaim test", "0.0.1", "goodbye", "");
+
+$ver = AIM::get_info(0);
+$nam = AIM::get_info(1);
+$pro = AIM::get_info(2);
+
+AIM::print("Perl Says", "Gaim $ver, $nam using $pro");
+
+# i should probably do something with these to actually test them, huh
+@bud = AIM::buddy_list();
+@onl = AIM::online_list();
+@den = AIM::deny_list();
+
+AIM::command("idle", "60000") if ($pro ne "Offline");
+
+AIM::add_event_handler("event_buddy_signon", "say_hello");
+AIM::add_timeout_handler(600, "notify");
+
+sub echo_reply {
+	$args = @_;
+	$args =~ s/\"//g;
+	AIM::print_to_conv($args, "Hello");
+}
+
+sub notify {
+	AIM::print("10 minutes", "gaim test has been loaded for 10 minutes");
+}
+
+sub goodbye {
+	AIM::print("You Bastard!", "You killed Kenny!");
+}
--- a/src/gaim.h	Thu Aug 31 01:07:39 2000 +0000
+++ b/src/gaim.h	Thu Aug 31 01:40:58 2000 +0000
@@ -401,7 +401,7 @@
 #define TYPE_SIGNOFF   4
 #define TYPE_KEEPALIVE 5
 
-#define REVISION "gaim:$Revision: 810 $"
+#define REVISION "gaim:$Revision: 816 $"
 #define FLAPON "FLAPON\r\n\r\n"
 
 #define ROAST "Tic/Toc"
@@ -738,7 +738,7 @@
 extern void perl_autoload();
 extern int perl_load_file(char *);
 extern void perl_end();
-extern int perl_event(enum gaim_event, char *);
+extern int perl_event(char *, char *);
 extern void load_perl_script(GtkWidget *, gpointer);
 extern void unload_perl_scripts(GtkWidget *, gpointer);
 extern void list_perl_scripts(GtkWidget *, gpointer);
--- a/src/perl.c	Thu Aug 31 01:07:39 2000 +0000
+++ b/src/perl.c	Thu Aug 31 01:40:58 2000 +0000
@@ -485,14 +485,14 @@
 	serv_chat_send(c->id, what);
 }
 
-int perl_event(enum gaim_event event, char *args)
+int perl_event(char *event, char *args)
 {
 	GList *handler;
 	struct _perl_event_handlers *data;
 
 	for (handler = perl_event_handlers; handler != NULL; handler = handler->next) {
 		data = handler->data;
-		if (!strcmp(event_name(event), data->event_type))
+		if (!strcmp(event, data->event_type))
 			execute_perl(data->handler_name, args);
 	}
 
@@ -510,6 +510,8 @@
 	handler->event_type = g_strdup(SvPV(ST(0), junk));
 	handler->handler_name = g_strdup(SvPV(ST(1), junk));
 	perl_event_handlers = g_list_append(perl_event_handlers, handler);
+	sprintf(debug_buff, "registered perl event handler for %s\n", handler->event_type);
+	debug_print(debug_buff);
 	XSRETURN_EMPTY;
 }
 
@@ -532,7 +534,7 @@
 	items = 0;
 
 	handler = g_new0(struct _perl_timeout_handlers, 1);
-	timeout = atol(SvPV(ST(0), junk));
+	timeout = 1000 * atol(SvPV(ST(0), junk));
 	handler->handler_name = g_strdup(SvPV(ST(1), junk));
 	perl_timeout_handlers = g_list_append(perl_timeout_handlers, handler);
 	handler->iotag = gtk_timeout_add(timeout, (GtkFunction)perl_timeout, handler);
--- a/src/plugins.c	Thu Aug 31 01:07:39 2000 +0000
+++ b/src/plugins.c	Thu Aug 31 01:40:58 2000 +0000
@@ -780,6 +780,6 @@
 	tmp = event_name(event);
 	sprintf(debug_buff, "%s: %s\n", tmp, buf);
 	debug_print(debug_buff);
-	perl_event(event, buf);
+	perl_event(tmp, buf);
 #endif
 }