summaryrefslogtreecommitdiff
path: root/src/perl/common
diff options
context:
space:
mode:
authorTimo Sirainen <cras@irssi.org>2002-01-22 18:25:39 +0000
committercras <cras@dbcabf3a-b0e7-0310-adc4-f8d773084564>2002-01-22 18:25:39 +0000
commitfbfc2b8ab68414f3d9c82f666391b99267211dcc (patch)
tree4bb0db2745e0230edf3051a857159fd246bc96ce /src/perl/common
parent2cd0cb5ef8d3efe6c7a9e86d256aae488e1f90f2 (diff)
downloadirssi-fbfc2b8ab68414f3d9c82f666391b99267211dcc.zip
Irssi::command_bind*() allows using hash.
git-svn-id: http://svn.irssi.org/repos/irssi/trunk@2336 dbcabf3a-b0e7-0310-adc4-f8d773084564
Diffstat (limited to 'src/perl/common')
-rw-r--r--src/perl/common/Core.xs58
1 files changed, 43 insertions, 15 deletions
diff --git a/src/perl/common/Core.xs b/src/perl/common/Core.xs
index 6cebd27c..4db742c0 100644
--- a/src/perl/common/Core.xs
+++ b/src/perl/common/Core.xs
@@ -1,6 +1,8 @@
#include "module.h"
#include "irssi-version.h"
+#define DEFAULT_COMMAND_CATEGORY "Perl scripts' commands"
+
void perl_signal_add_hash(int priority, SV *sv)
{
HV *hv;
@@ -16,6 +18,41 @@ void perl_signal_add_hash(int priority, SV *sv)
perl_signal_add_to(hv_iterkey(he, &len), HeVAL(he), priority);
}
+static void perl_command_bind_add_hash(int priority, SV *sv, char *category)
+{
+ HV *hv;
+ HE *he;
+ I32 len;
+
+ hv = hvref(sv);
+ hv_iterinit(hv);
+ while ((he = hv_iternext(hv)) != NULL)
+ perl_command_bind_to(hv_iterkey(he, &len), category, HeVAL(he), priority);
+}
+
+static void handle_command_bind(int priority, int items, SV *p0, SV *p1, SV *p2)
+{
+ char *category;
+ int hash;
+
+ hash = items > 0 && is_hvref(p0);
+ if (!hash) {
+ if (items < 2 || items > 3)
+ croak("Usage: Irssi::command_bind(signal, func, category)");
+ } else if (items > 2)
+ croak("Usage: Irssi::command_bind(signals_hash, category)");
+
+ if (!hash) {
+ category = items < 3 ? DEFAULT_COMMAND_CATEGORY :
+ (char *)SvPV(p2, PL_na);
+ perl_command_bind_to((char *)SvPV(p0, PL_na), category, p1, priority);
+ } else {
+ category = items < 2 ? DEFAULT_COMMAND_CATEGORY :
+ (char *)SvPV(p1, PL_na);
+ perl_command_bind_add_hash(priority, p0, category);
+ }
+}
+
MODULE = Irssi::Core PACKAGE = Irssi
PROTOTYPES: ENABLE
@@ -360,28 +397,19 @@ PPCODE:
}
void
-command_bind_first(cmd, func, category = "Perl scripts' commands")
- char *cmd
- char *category
- SV *func
+command_bind_first(...)
CODE:
- perl_command_bind_first(cmd, category, func);
+ handle_command_bind(0, items, ST(0), ST(1), ST(2));
void
-command_bind(cmd, func, category = "Perl scripts' commands")
- char *cmd
- char *category
- SV *func
+command_bind(...)
CODE:
- perl_command_bind(cmd, category, func);
+ handle_command_bind(1, items, ST(0), ST(1), ST(2));
void
-command_bind_last(cmd, func, category = "Perl scripts' commands")
- char *cmd
- char *category
- SV *func
+command_bind_last(...)
CODE:
- perl_command_bind_last(cmd, category, func);
+ handle_command_bind(2, items, ST(0), ST(1), ST(2));
void
command_runsub(cmd, data, server, item)