diff --git a/src/perl/irssi-core.pl b/src/perl/irssi-core.pl index 9ab5953b..11aa0f6f 100644 --- a/src/perl/irssi-core.pl +++ b/src/perl/irssi-core.pl @@ -30,8 +30,10 @@ sub eval_data { } die $@ if $@; - eval {$package->handler;}; + my $ret; + eval { $ret = $package->handler; }; die $@ if $@; + return $ret; } sub eval_file { diff --git a/src/perl/perl-core.c b/src/perl/perl-core.c index accd5ef4..0c1e506b 100644 --- a/src/perl/perl-core.c +++ b/src/perl/perl-core.c @@ -216,6 +216,7 @@ static int perl_script_eval(PERL_SCRIPT_REC *script) dSP; char *error; int retcount; + SV *ret; ENTER; SAVETMPS; @@ -234,19 +235,19 @@ static int perl_script_eval(PERL_SCRIPT_REC *script) error = NULL; if (SvTRUE(ERRSV)) { - error = SvPV(ERRSV, PL_na); - } else if (retcount > 0) { - error = POPp; - } + error = SvPV(ERRSV, PL_na); - if (error != NULL) { - if (*error == '\0') - error = NULL; - else { - error = g_strdup(error); + if (error != NULL) { + error = g_strdup(error); signal_emit("script error", 2, script, error); - g_free(error); + g_free(error); } + } else if (retcount > 0) { + /* if script returns 0, it means the script wanted to die + immediately without any error message */ + ret = POPs; + if (ret != &PL_sv_undef && SvIOK(ret) && SvIV(ret) == 0) + error = ""; } PUTBACK;