diff options
author | Timo Sirainen <cras@irssi.org> | 2001-12-06 20:46:31 +0000 |
---|---|---|
committer | cras <cras@dbcabf3a-b0e7-0310-adc4-f8d773084564> | 2001-12-06 20:46:31 +0000 |
commit | e558f1252a0df15a2ee62ed7e283ea42578f177c (patch) | |
tree | bc6fb120402d19c2f4d665dce4a1a6c959c56d10 /src/perl | |
parent | 31dcd8258f8f52c065e4297f7abecc5dd0a7d0a2 (diff) | |
download | irssi-e558f1252a0df15a2ee62ed7e283ea42578f177c.zip |
Irssi::signal_add() accepts now a hash, so you can do eg. signal_add('sig1'
=> 'func1', 'sig2' => 'func2');
git-svn-id: http://svn.irssi.org/repos/irssi/trunk@2200 dbcabf3a-b0e7-0310-adc4-f8d773084564
Diffstat (limited to 'src/perl')
-rw-r--r-- | src/perl/common/Core.xs | 40 |
1 files changed, 34 insertions, 6 deletions
diff --git a/src/perl/common/Core.xs b/src/perl/common/Core.xs index 4edde30c..3a3e6768 100644 --- a/src/perl/common/Core.xs +++ b/src/perl/common/Core.xs @@ -1,6 +1,21 @@ #include "module.h" #include "irssi-version.h" +void perl_signal_add_hash(int priority, SV *sv) +{ + HV *hv; + HE *he; + I32 len; + + if (!is_hvref(sv)) + croak("Usage: Irssi::signal_add(hash)"); + + hv = hvref(sv); + hv_iterinit(hv); + while ((he = hv_iternext(hv)) != NULL) + perl_signal_add_to(hv_iterkey(he, &len), HeVAL(he), priority); +} + MODULE = Irssi::Core PACKAGE = Irssi PROTOTYPES: ENABLE @@ -25,25 +40,38 @@ CODE: signal_emit(signal, items-1, p[0], p[1], p[2], p[3], p[4], p[5]); void -signal_add(signal, func) - char *signal - SV *func +signal_add(...) CODE: - perl_signal_add(signal, func); + if (items != 1 && items != 2) + croak("Usage: Irssi::signal_add(signal, func)"); + if (items == 2) + perl_signal_add((char *)SvPV(ST(0),PL_na), ST(1)); + else + perl_signal_add_hash(1, ST(0)); void signal_add_first(signal, func) char *signal SV *func CODE: - perl_signal_add_first(signal, func); + if (items != 1 && items != 2) + croak("Usage: Irssi::signal_add(signal, func)"); + if (items == 2) + perl_signal_add_first((char *)SvPV(ST(0),PL_na), ST(1)); + else + perl_signal_add_hash(0, ST(0)); void signal_add_last(signal, func) char *signal SV *func CODE: - perl_signal_add_last(signal, func); + if (items != 1 && items != 2) + croak("Usage: Irssi::signal_add(signal, func)"); + if (items == 2) + perl_signal_add_last((char *)SvPV(ST(0),PL_na), ST(1)); + else + perl_signal_add_hash(2, ST(0)); void signal_remove(signal, func) |