forked from PsychoticNinja/irssi
Irssi::command_bind*() allows using hash.
git-svn-id: http://svn.irssi.org/repos/irssi/trunk@2336 dbcabf3a-b0e7-0310-adc4-f8d773084564
This commit is contained in:
parent
2cd0cb5ef8
commit
fbfc2b8ab6
@ -1,6 +1,8 @@
|
|||||||
#include "module.h"
|
#include "module.h"
|
||||||
#include "irssi-version.h"
|
#include "irssi-version.h"
|
||||||
|
|
||||||
|
#define DEFAULT_COMMAND_CATEGORY "Perl scripts' commands"
|
||||||
|
|
||||||
void perl_signal_add_hash(int priority, SV *sv)
|
void perl_signal_add_hash(int priority, SV *sv)
|
||||||
{
|
{
|
||||||
HV *hv;
|
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);
|
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
|
MODULE = Irssi::Core PACKAGE = Irssi
|
||||||
PROTOTYPES: ENABLE
|
PROTOTYPES: ENABLE
|
||||||
|
|
||||||
@ -360,28 +397,19 @@ PPCODE:
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
command_bind_first(cmd, func, category = "Perl scripts' commands")
|
command_bind_first(...)
|
||||||
char *cmd
|
|
||||||
char *category
|
|
||||||
SV *func
|
|
||||||
CODE:
|
CODE:
|
||||||
perl_command_bind_first(cmd, category, func);
|
handle_command_bind(0, items, ST(0), ST(1), ST(2));
|
||||||
|
|
||||||
void
|
void
|
||||||
command_bind(cmd, func, category = "Perl scripts' commands")
|
command_bind(...)
|
||||||
char *cmd
|
|
||||||
char *category
|
|
||||||
SV *func
|
|
||||||
CODE:
|
CODE:
|
||||||
perl_command_bind(cmd, category, func);
|
handle_command_bind(1, items, ST(0), ST(1), ST(2));
|
||||||
|
|
||||||
void
|
void
|
||||||
command_bind_last(cmd, func, category = "Perl scripts' commands")
|
command_bind_last(...)
|
||||||
char *cmd
|
|
||||||
char *category
|
|
||||||
SV *func
|
|
||||||
CODE:
|
CODE:
|
||||||
perl_command_bind_last(cmd, category, func);
|
handle_command_bind(2, items, ST(0), ST(1), ST(2));
|
||||||
|
|
||||||
void
|
void
|
||||||
command_runsub(cmd, data, server, item)
|
command_runsub(cmd, data, server, item)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user