summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xsrc/perl/get-signals.pl11
-rw-r--r--src/perl/perl-common.h3
-rw-r--r--src/perl/perl.c177
3 files changed, 94 insertions, 97 deletions
diff --git a/src/perl/get-signals.pl b/src/perl/get-signals.pl
index e3a574a9..716e25f2 100755
--- a/src/perl/get-signals.pl
+++ b/src/perl/get-signals.pl
@@ -18,11 +18,10 @@ while (<STDIN>) {
s/int[^,]*/int/g;
s/GSList of (\w+)s/gslist_\1/g;
- s/SERVER_REC[^,]*/Irssi::Server/g;
- s/IRC_SERVER_REC[^,]*/Irssi::Server/g;
- s/RECONNECT_REC[^,]*/Irssi::Reconnect/g;
- s/CHANNEL_REC[^,]*/Irssi::Channel/g;
- s/QUERY_REC[^,]*/Irssi::Query/g;
+ s/SERVER_REC[^,]*/iobject/g;
+ s/RECONNECT_REC[^,]*/iobject/g;
+ s/CHANNEL_REC[^,]*/iobject/g;
+ s/QUERY_REC[^,]*/iobject/g;
s/COMMAND_REC[^,]*/Irssi::Command/g;
s/NICK_REC[^,]*/Irssi::Nick/g;
s/BAN_REC[^,]*/Irssi::Ban/g;
@@ -34,7 +33,7 @@ while (<STDIN>) {
s/NOTIFYLIST_REC[^,]*/Irssi::Notifylist/g;
s/IGNORE_REC[^,]*/Irssi::Ignore/g;
s/WINDOW_REC[^,]*/Irssi::Window/g;
- s/WI_ITEM_REC[^,]*/Irssi::Windowitem/g;
+ s/WI_ITEM_REC[^,]*/iobject/g;
s/([\w:]+)(,|$)/"\1"\2/g;
print " { -1, \"$signal\", { $_, NULL } },\n";
diff --git a/src/perl/perl-common.h b/src/perl/perl-common.h
index c5eb9748..9684c7fd 100644
--- a/src/perl/perl-common.h
+++ b/src/perl/perl-common.h
@@ -4,6 +4,9 @@
#define new_pv(a) \
(newSVpv((a) == NULL ? "" : (a), (a) == NULL ? 0 : strlen(a)))
+#define new_bless(obj, stash) \
+ sv_bless(newRV_noinc(newSViv(GPOINTER_TO_INT(obj))), stash)
+
extern GHashTable *perl_stashes;
HV *irssi_get_stash_item(int type, int chat_type);
diff --git a/src/perl/perl.c b/src/perl/perl.c
index bf1ae551..6fb1d9db 100644
--- a/src/perl/perl.c
+++ b/src/perl/perl.c
@@ -33,6 +33,7 @@
#include "commands.h"
#include "misc.h"
#include "perl-common.h"
+#include "servers.h"
/* For compatibility with perl 5.004 and older */
#ifndef ERRSV
@@ -493,113 +494,107 @@ void perl_timeout_remove(int tag)
}
}
+static PERL_SIGNAL_ARGS_REC *perl_signal_find(int signal)
+{
+ const char *signame;
+ int n;
+
+ for (n = 0; perl_signal_args[n].signal != NULL; n++) {
+ if (signal == perl_signal_args[n].signal_id)
+ return &perl_signal_args[n];
+ }
+
+ /* try to find by name */
+ signame = module_find_id_str("signals", signal);
+ for (n = 0; perl_signal_args[n].signal != NULL; n++) {
+ if (strncmp(signame, perl_signal_args[n].signal,
+ strlen(perl_signal_args[n].signal)) == 0)
+ return &perl_signal_args[n];
+ }
+
+ return NULL;
+}
+
+
static int call_perl(const char *func, int signal, va_list va)
{
dSP;
PERL_SIGNAL_ARGS_REC *rec;
- int retcount, n, ret;
- void *arg;
+ int retcount, ret;
+
HV *stash;
+ void *arg;
+ int n;
- /* first check if we find exact match */
- rec = NULL;
- for (n = 0; perl_signal_args[n].signal != NULL; n++)
- {
- if (signal == perl_signal_args[n].signal_id)
- {
- rec = &perl_signal_args[n];
- break;
- }
- }
+ /* first check if we find exact match */
+ rec = perl_signal_find(signal);
- if (rec == NULL)
- {
- /* try to find by name */
- const char *signame;
+ ENTER;
+ SAVETMPS;
- signame = module_find_id_str("signals", signal);
- for (n = 0; perl_signal_args[n].signal != NULL; n++)
- {
- if (strncmp(signame, perl_signal_args[n].signal,
- strlen(perl_signal_args[n].signal)) == 0)
- {
- rec = &perl_signal_args[n];
- break;
- }
- }
- }
-
- ENTER;
- SAVETMPS;
-
- PUSHMARK(sp);
-
- if (rec != NULL)
- {
- /* put the arguments to perl stack */
- for (n = 0; n < 7; n++)
- {
- arg = va_arg(va, gpointer);
-
- if (rec->args[n] == NULL)
- break;
-
- if (strcmp(rec->args[n], "string") == 0)
- XPUSHs(sv_2mortal(newSVpv(arg == NULL ? "" : arg, arg == NULL ? 0 : strlen(arg))));
- else if (strcmp(rec->args[n], "int") == 0)
- XPUSHs(sv_2mortal(newSViv(GPOINTER_TO_INT(arg))));
- else if (strcmp(rec->args[n], "ulongptr") == 0)
- XPUSHs(sv_2mortal(newSViv(*(gulong *) arg)));
- else if (strncmp(rec->args[n], "gslist_", 7) == 0)
- {
- GSList *tmp;
-
- stash = gv_stashpv(rec->args[n]+7, 0);
- for (tmp = arg; tmp != NULL; tmp = tmp->next)
- XPUSHs(sv_2mortal(sv_bless(newRV_noinc(newSViv(GPOINTER_TO_INT(tmp->data))), stash)));
- }
- else
- {
- if (arg == NULL)
- XPUSHs(sv_2mortal(newSViv(0)));
- else {
- stash = gv_stashpv(rec->args[n], 0);
- XPUSHs(sv_2mortal(sv_bless(newRV_noinc(newSViv(GPOINTER_TO_INT(arg))), stash)));
+ PUSHMARK(sp);
+
+ if (rec != NULL) {
+ /* push the arguments to perl stack */
+ for (n = 0; n < 7 && rec->args[n] != NULL; n++) {
+ arg = va_arg(va, void *);
+
+ if (strcmp(rec->args[n], "string") == 0)
+ XPUSHs(sv_2mortal(new_pv(arg)));
+ else if (strcmp(rec->args[n], "int") == 0)
+ XPUSHs(sv_2mortal(newSViv(GPOINTER_TO_INT(arg))));
+ else if (strcmp(rec->args[n], "ulongptr") == 0)
+ XPUSHs(sv_2mortal(newSViv(*(unsigned long *) arg)));
+ else if (strncmp(rec->args[n], "gslist_", 7) == 0) {
+ /* linked list - push as AV */
+ GSList *tmp;
+ AV *av;
+
+ av = newAV();
+ stash = gv_stashpv(rec->args[n]+7, 0);
+ for (tmp = arg; tmp != NULL; tmp = tmp->next)
+ av_push(av, sv_2mortal(new_bless(tmp->data, stash)));
+ XPUSHs(newRV_noinc((SV*)av));
+ } else if (arg == NULL) {
+ /* don't bless NULL arguments */
+ XPUSHs(sv_2mortal(newSViv(0)));
+ } else if (strcmp(rec->args[n], "iobject") == 0) {
+ /* "irssi object" - any struct that has
+ "int type; int chat_type" as its first
+ variables (server, channel, ..) */
+ stash = irssi_get_stash((SERVER_REC *) arg);
+ XPUSHs(sv_2mortal(new_bless(arg, stash)));
+ } else {
+ /* blessed object */
+ stash = gv_stashpv(rec->args[n], 0);
+ XPUSHs(sv_2mortal(new_bless(arg, stash)));
+ }
}
- }
}
- }
- PUTBACK;
- retcount = perl_call_pv((char *) func, G_EVAL|G_SCALAR);
- SPAGAIN;
+ PUTBACK;
+ retcount = perl_call_pv((char *) func, G_EVAL|G_SCALAR);
+ SPAGAIN;
+
+ ret = 0;
+ if (SvTRUE(ERRSV)) {
+ STRLEN n_a;
- ret = 0;
- if (SvTRUE(ERRSV))
- {
- STRLEN n_a;
+ signal_emit("gui dialog", 2, "error", SvPV(ERRSV, n_a));
+ (void)POPs;
+ } else if (retcount > 0) {
+ SV *sv = POPs;
- signal_emit("gui dialog", 2, "error", SvPV(ERRSV, n_a));
- (void)POPs;
- }
- else
- {
- SV *sv;
-
- if (retcount > 0)
- {
- sv = POPs;
- if (SvIOK(sv) && SvIV(sv) == 1) ret = 1;
+ if (SvIOK(sv) && SvIV(sv) == 1) ret = 1;
+ while (--retcount > 0)
+ (void)POPi;
}
- for (n = 2; n <= retcount; n++)
- (void)POPi;
- }
- PUTBACK;
- FREETMPS;
- LEAVE;
+ PUTBACK;
+ FREETMPS;
+ LEAVE;
- return ret;
+ return ret;
}
static void sig_signal(void *signal, ...)