mirror of
https://github.com/weechat/weechat.git
synced 2026-06-27 21:36:37 +02:00
Added keyboard handler to plugin API
This commit is contained in:
@@ -54,7 +54,7 @@ lua_State *lua_current_interpreter = NULL;
|
||||
int
|
||||
weechat_lua_exec (t_weechat_plugin *plugin,
|
||||
t_plugin_script *script,
|
||||
char *function, char *server, char *arguments)
|
||||
char *function, char *arg1, char *arg2, char *arg3)
|
||||
{
|
||||
|
||||
lua_current_interpreter = script->interpreter;
|
||||
@@ -62,10 +62,19 @@ weechat_lua_exec (t_weechat_plugin *plugin,
|
||||
lua_getglobal (lua_current_interpreter, function);
|
||||
lua_current_script = script;
|
||||
|
||||
lua_pushstring (lua_current_interpreter, server == NULL ? "" : server);
|
||||
lua_pushstring (lua_current_interpreter, arguments == NULL ? "" : arguments);
|
||||
if (arg1)
|
||||
{
|
||||
lua_pushstring (lua_current_interpreter, (arg1) ? arg1 : "");
|
||||
if (arg2)
|
||||
{
|
||||
lua_pushstring (lua_current_interpreter, (arg2) ? arg2 : "");
|
||||
if (arg3)
|
||||
lua_pushstring (lua_current_interpreter, (arg3) ? arg3 : "");
|
||||
}
|
||||
}
|
||||
|
||||
if ( lua_pcall(lua_current_interpreter, 2, 1, 0) != 0)
|
||||
if (lua_pcall (lua_current_interpreter,
|
||||
(arg1) ? ((arg2) ? ((arg3) ? 3 : 2) : 1) : 0, 1, 0) != 0)
|
||||
{
|
||||
plugin->print_server (plugin,
|
||||
"Lua error: unable to run function \"%s\"",
|
||||
@@ -80,19 +89,52 @@ weechat_lua_exec (t_weechat_plugin *plugin,
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_lua_handler: general message and command handler for Lua
|
||||
* weechat_lua_cmd_msg_handler: general command/message handler for Lua
|
||||
*/
|
||||
|
||||
int
|
||||
weechat_lua_handler (t_weechat_plugin *plugin,
|
||||
char *server, char *command, char *arguments,
|
||||
char *handler_args, void *handler_pointer)
|
||||
weechat_lua_cmd_msg_handler (t_weechat_plugin *plugin,
|
||||
int argc, char **argv,
|
||||
char *handler_args, void *handler_pointer)
|
||||
{
|
||||
if (argc >= 3)
|
||||
return weechat_lua_exec (plugin, (t_plugin_script *)handler_pointer,
|
||||
handler_args, argv[0], argv[2], NULL);
|
||||
else
|
||||
return PLUGIN_RC_KO;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_lua_timer_handler: general timer handler for Lua
|
||||
*/
|
||||
|
||||
int
|
||||
weechat_lua_timer_handler (t_weechat_plugin *plugin,
|
||||
int argc, char **argv,
|
||||
char *handler_args, void *handler_pointer)
|
||||
{
|
||||
/* make gcc happy */
|
||||
(void) command;
|
||||
(void) argc;
|
||||
(void) argv;
|
||||
|
||||
return weechat_lua_exec (plugin, (t_plugin_script *)handler_pointer,
|
||||
handler_args, server, arguments);
|
||||
handler_args, NULL, NULL, NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_lua_keyboard_handler: general keyboard handler for Lua
|
||||
*/
|
||||
|
||||
int
|
||||
weechat_lua_keyboard_handler (t_weechat_plugin *plugin,
|
||||
int argc, char **argv,
|
||||
char *handler_args, void *handler_pointer)
|
||||
{
|
||||
if (argc >= 2)
|
||||
return weechat_lua_exec (plugin, (t_plugin_script *)handler_pointer,
|
||||
handler_args, argv[0], argv[1], argv[2]);
|
||||
else
|
||||
return PLUGIN_RC_KO;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -104,6 +146,7 @@ weechat_lua_register (lua_State *L)
|
||||
{
|
||||
const char *name, *version, *shutdown_func, *description;
|
||||
int n;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) L;
|
||||
|
||||
@@ -179,6 +222,7 @@ weechat_lua_print (lua_State *L)
|
||||
{
|
||||
const char *message, *channel_name, *server_name;
|
||||
int n;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) L;
|
||||
|
||||
@@ -199,24 +243,24 @@ weechat_lua_print (lua_State *L)
|
||||
|
||||
switch (n)
|
||||
{
|
||||
case 1:
|
||||
message = lua_tostring (lua_current_interpreter, -1);
|
||||
break;
|
||||
case 2:
|
||||
channel_name = lua_tostring (lua_current_interpreter, -2);
|
||||
message = lua_tostring (lua_current_interpreter, -1);
|
||||
break;
|
||||
case 3:
|
||||
server_name = lua_tostring (lua_current_interpreter, -3);
|
||||
channel_name = lua_tostring (lua_current_interpreter, -2);
|
||||
message = lua_tostring (lua_current_interpreter, -1);
|
||||
break;
|
||||
default:
|
||||
lua_plugin->print_server (lua_plugin,
|
||||
"Lua error: wrong parameters for "
|
||||
"\"print\" function");
|
||||
lua_pushnumber (lua_current_interpreter, 0);
|
||||
return 1;
|
||||
case 1:
|
||||
message = lua_tostring (lua_current_interpreter, -1);
|
||||
break;
|
||||
case 2:
|
||||
channel_name = lua_tostring (lua_current_interpreter, -2);
|
||||
message = lua_tostring (lua_current_interpreter, -1);
|
||||
break;
|
||||
case 3:
|
||||
server_name = lua_tostring (lua_current_interpreter, -3);
|
||||
channel_name = lua_tostring (lua_current_interpreter, -2);
|
||||
message = lua_tostring (lua_current_interpreter, -1);
|
||||
break;
|
||||
default:
|
||||
lua_plugin->print_server (lua_plugin,
|
||||
"Lua error: wrong parameters for "
|
||||
"\"print\" function");
|
||||
lua_pushnumber (lua_current_interpreter, 0);
|
||||
return 1;
|
||||
}
|
||||
|
||||
lua_plugin->print (lua_plugin,
|
||||
@@ -237,6 +281,7 @@ weechat_lua_print_infobar (lua_State *L)
|
||||
{
|
||||
const char *message;
|
||||
int delay, n;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) L;
|
||||
|
||||
@@ -280,6 +325,7 @@ static int
|
||||
weechat_lua_remove_infobar (lua_State *L)
|
||||
{
|
||||
int n, how_many;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) L;
|
||||
|
||||
@@ -314,6 +360,7 @@ weechat_lua_log (lua_State *L)
|
||||
{
|
||||
const char *message, *channel_name, *server_name;
|
||||
int n;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) L;
|
||||
|
||||
@@ -334,24 +381,24 @@ weechat_lua_log (lua_State *L)
|
||||
|
||||
switch (n)
|
||||
{
|
||||
case 1:
|
||||
message = lua_tostring (lua_current_interpreter, -1);
|
||||
break;
|
||||
case 2:
|
||||
channel_name = lua_tostring (lua_current_interpreter, -2);
|
||||
message = lua_tostring (lua_current_interpreter, -1);
|
||||
break;
|
||||
case 3:
|
||||
server_name = lua_tostring (lua_current_interpreter, -3);
|
||||
channel_name = lua_tostring (lua_current_interpreter, -2);
|
||||
message = lua_tostring (lua_current_interpreter, -1);
|
||||
break;
|
||||
default:
|
||||
lua_plugin->print_server (lua_plugin,
|
||||
"Lua error: wrong parameters for "
|
||||
"\"log\" function");
|
||||
lua_pushnumber (lua_current_interpreter, 0);
|
||||
return 1;
|
||||
case 1:
|
||||
message = lua_tostring (lua_current_interpreter, -1);
|
||||
break;
|
||||
case 2:
|
||||
channel_name = lua_tostring (lua_current_interpreter, -2);
|
||||
message = lua_tostring (lua_current_interpreter, -1);
|
||||
break;
|
||||
case 3:
|
||||
server_name = lua_tostring (lua_current_interpreter, -3);
|
||||
channel_name = lua_tostring (lua_current_interpreter, -2);
|
||||
message = lua_tostring (lua_current_interpreter, -1);
|
||||
break;
|
||||
default:
|
||||
lua_plugin->print_server (lua_plugin,
|
||||
"Lua error: wrong parameters for "
|
||||
"\"log\" function");
|
||||
lua_pushnumber (lua_current_interpreter, 0);
|
||||
return 1;
|
||||
}
|
||||
|
||||
lua_plugin->log (lua_plugin,
|
||||
@@ -372,6 +419,7 @@ weechat_lua_command (lua_State *L)
|
||||
{
|
||||
const char *command, *channel_name, *server_name;
|
||||
int n;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) L;
|
||||
|
||||
@@ -392,24 +440,24 @@ weechat_lua_command (lua_State *L)
|
||||
|
||||
switch (n)
|
||||
{
|
||||
case 1:
|
||||
command = lua_tostring (lua_current_interpreter, -1);
|
||||
break;
|
||||
case 2:
|
||||
channel_name = lua_tostring (lua_current_interpreter, -2);
|
||||
command = lua_tostring (lua_current_interpreter, -1);
|
||||
break;
|
||||
case 3:
|
||||
server_name = lua_tostring (lua_current_interpreter, -3);
|
||||
channel_name = lua_tostring (lua_current_interpreter, -2);
|
||||
command = lua_tostring (lua_current_interpreter, -1);
|
||||
break;
|
||||
default:
|
||||
lua_plugin->print_server (lua_plugin,
|
||||
"Lua error: wrong parameters for "
|
||||
"\"command\" function");
|
||||
lua_pushnumber (lua_current_interpreter, 0);
|
||||
return 1;
|
||||
case 1:
|
||||
command = lua_tostring (lua_current_interpreter, -1);
|
||||
break;
|
||||
case 2:
|
||||
channel_name = lua_tostring (lua_current_interpreter, -2);
|
||||
command = lua_tostring (lua_current_interpreter, -1);
|
||||
break;
|
||||
case 3:
|
||||
server_name = lua_tostring (lua_current_interpreter, -3);
|
||||
channel_name = lua_tostring (lua_current_interpreter, -2);
|
||||
command = lua_tostring (lua_current_interpreter, -1);
|
||||
break;
|
||||
default:
|
||||
lua_plugin->print_server (lua_plugin,
|
||||
"Lua error: wrong parameters for "
|
||||
"\"command\" function");
|
||||
lua_pushnumber (lua_current_interpreter, 0);
|
||||
return 1;
|
||||
}
|
||||
|
||||
lua_plugin->exec_command (lua_plugin,
|
||||
@@ -430,6 +478,7 @@ weechat_lua_add_message_handler (lua_State *L)
|
||||
{
|
||||
const char *irc_command, *function;
|
||||
int n;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) L;
|
||||
|
||||
@@ -460,7 +509,8 @@ weechat_lua_add_message_handler (lua_State *L)
|
||||
function = lua_tostring (lua_current_interpreter, -1);
|
||||
|
||||
if (!lua_plugin->msg_handler_add (lua_plugin, (char *) irc_command,
|
||||
weechat_lua_handler, (char *) function,
|
||||
weechat_lua_cmd_msg_handler,
|
||||
(char *) function,
|
||||
(void *)lua_current_script))
|
||||
{
|
||||
lua_pushnumber (lua_current_interpreter, 0);
|
||||
@@ -481,6 +531,7 @@ weechat_lua_add_command_handler (lua_State *L)
|
||||
const char *command, *function, *description, *arguments, *arguments_description;
|
||||
const char *completion_template;
|
||||
int n;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) L;
|
||||
|
||||
@@ -504,24 +555,24 @@ weechat_lua_add_command_handler (lua_State *L)
|
||||
|
||||
switch (n)
|
||||
{
|
||||
case 2:
|
||||
command = lua_tostring (lua_current_interpreter, -2);
|
||||
function = lua_tostring (lua_current_interpreter, -1);
|
||||
break;
|
||||
case 6:
|
||||
command = lua_tostring (lua_current_interpreter, -6);
|
||||
function = lua_tostring (lua_current_interpreter, -5);
|
||||
description = lua_tostring (lua_current_interpreter, -4);
|
||||
arguments = lua_tostring (lua_current_interpreter, -3);
|
||||
arguments_description = lua_tostring (lua_current_interpreter, -2);
|
||||
completion_template = lua_tostring (lua_current_interpreter, -1);
|
||||
break;
|
||||
default:
|
||||
lua_plugin->print_server (lua_plugin,
|
||||
"Lua error: wrong parameters for "
|
||||
"\"add_command_handler\" function");
|
||||
lua_pushnumber (lua_current_interpreter, 0);
|
||||
return 1;
|
||||
case 2:
|
||||
command = lua_tostring (lua_current_interpreter, -2);
|
||||
function = lua_tostring (lua_current_interpreter, -1);
|
||||
break;
|
||||
case 6:
|
||||
command = lua_tostring (lua_current_interpreter, -6);
|
||||
function = lua_tostring (lua_current_interpreter, -5);
|
||||
description = lua_tostring (lua_current_interpreter, -4);
|
||||
arguments = lua_tostring (lua_current_interpreter, -3);
|
||||
arguments_description = lua_tostring (lua_current_interpreter, -2);
|
||||
completion_template = lua_tostring (lua_current_interpreter, -1);
|
||||
break;
|
||||
default:
|
||||
lua_plugin->print_server (lua_plugin,
|
||||
"Lua error: wrong parameters for "
|
||||
"\"add_command_handler\" function");
|
||||
lua_pushnumber (lua_current_interpreter, 0);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!lua_plugin->cmd_handler_add (lua_plugin,
|
||||
@@ -530,7 +581,7 @@ weechat_lua_add_command_handler (lua_State *L)
|
||||
(char *) arguments,
|
||||
(char *) arguments_description,
|
||||
(char *) completion_template,
|
||||
weechat_lua_handler,
|
||||
weechat_lua_cmd_msg_handler,
|
||||
(char *) function,
|
||||
(void *)lua_current_script))
|
||||
{
|
||||
@@ -552,6 +603,7 @@ weechat_lua_add_timer_handler (lua_State *L)
|
||||
int interval;
|
||||
const char *function;
|
||||
int n;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) L;
|
||||
|
||||
@@ -582,7 +634,8 @@ weechat_lua_add_timer_handler (lua_State *L)
|
||||
function = lua_tostring (lua_current_interpreter, -1);
|
||||
|
||||
if (!lua_plugin->timer_handler_add (lua_plugin, interval,
|
||||
weechat_lua_handler, (char *) function,
|
||||
weechat_lua_timer_handler,
|
||||
(char *) function,
|
||||
(void *)lua_current_script))
|
||||
{
|
||||
lua_pushnumber (lua_current_interpreter, 0);
|
||||
@@ -594,7 +647,57 @@ weechat_lua_add_timer_handler (lua_State *L)
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_lua_remove_handler: remove a handler
|
||||
* weechat_lua_add_keyboard_handler: add a keyboard handler
|
||||
*/
|
||||
|
||||
static int
|
||||
weechat_lua_add_keyboard_handler (lua_State *L)
|
||||
{
|
||||
const char *function;
|
||||
int n;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) L;
|
||||
|
||||
if (!lua_current_script)
|
||||
{
|
||||
lua_plugin->print_server (lua_plugin,
|
||||
"Lua error: unable to add keyboard handler, "
|
||||
"script not initialized");
|
||||
lua_pushnumber (lua_current_interpreter, 0);
|
||||
return 1;
|
||||
}
|
||||
|
||||
function = NULL;
|
||||
|
||||
n = lua_gettop (lua_current_interpreter);
|
||||
|
||||
if (n != 1)
|
||||
{
|
||||
lua_plugin->print_server (lua_plugin,
|
||||
"Lua error: wrong parameters for "
|
||||
"\"add_keyboard_handler\" function");
|
||||
lua_pushnumber (lua_current_interpreter, 0);
|
||||
return 1;
|
||||
}
|
||||
|
||||
function = lua_tostring (lua_current_interpreter, -1);
|
||||
|
||||
if (!lua_plugin->keyboard_handler_add (lua_plugin,
|
||||
weechat_lua_keyboard_handler,
|
||||
(char *) function,
|
||||
(void *)lua_current_script))
|
||||
{
|
||||
lua_pushnumber (lua_current_interpreter, 0);
|
||||
return 1;
|
||||
}
|
||||
|
||||
lua_pushnumber (lua_current_interpreter, 1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_lua_remove_handler: remove a command/message handler
|
||||
*/
|
||||
|
||||
static int
|
||||
@@ -602,6 +705,7 @@ weechat_lua_remove_handler (lua_State *L)
|
||||
{
|
||||
const char *command, *function;
|
||||
int n;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) L;
|
||||
|
||||
@@ -647,6 +751,7 @@ weechat_lua_remove_timer_handler (lua_State *L)
|
||||
{
|
||||
const char *function;
|
||||
int n;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) L;
|
||||
|
||||
@@ -681,6 +786,50 @@ weechat_lua_remove_timer_handler (lua_State *L)
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_lua_remove_keyboard_handler: remove a keyboard handler
|
||||
*/
|
||||
|
||||
static int
|
||||
weechat_lua_remove_keyboard_handler (lua_State *L)
|
||||
{
|
||||
const char *function;
|
||||
int n;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) L;
|
||||
|
||||
if (!lua_current_script)
|
||||
{
|
||||
lua_plugin->print_server (lua_plugin,
|
||||
"Lua error: unable to remove keyboard handler, "
|
||||
"script not initialized");
|
||||
lua_pushnumber (lua_current_interpreter, 0);
|
||||
return 1;
|
||||
}
|
||||
|
||||
function = NULL;
|
||||
|
||||
n = lua_gettop (lua_current_interpreter);
|
||||
|
||||
if (n != 1)
|
||||
{
|
||||
lua_plugin->print_server (lua_plugin,
|
||||
"Lua error: wrong parameters for "
|
||||
"\"remove_keyboard_handler\" function");
|
||||
lua_pushnumber (lua_current_interpreter, 0);
|
||||
return 1;
|
||||
}
|
||||
|
||||
function = lua_tostring (lua_current_interpreter, -1);
|
||||
|
||||
weechat_script_remove_keyboard_handler (lua_plugin, lua_current_script,
|
||||
(char *) function);
|
||||
|
||||
lua_pushnumber (lua_current_interpreter, 1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_lua_get_info: get various infos
|
||||
*/
|
||||
@@ -691,6 +840,7 @@ weechat_lua_get_info (lua_State *L)
|
||||
const char *arg, *server_name;
|
||||
char *info;
|
||||
int n;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) L;
|
||||
|
||||
@@ -710,19 +860,19 @@ weechat_lua_get_info (lua_State *L)
|
||||
|
||||
switch (n)
|
||||
{
|
||||
case 1:
|
||||
arg = lua_tostring (lua_current_interpreter, -1);
|
||||
break;
|
||||
case 2:
|
||||
arg = lua_tostring (lua_current_interpreter, -2);
|
||||
server_name = lua_tostring (lua_current_interpreter, -1);
|
||||
break;
|
||||
default:
|
||||
lua_plugin->print_server (lua_plugin,
|
||||
"Lua error: wrong parameters for "
|
||||
"\"get_info\" function");
|
||||
lua_pushnumber (lua_current_interpreter, 0);
|
||||
return 1;
|
||||
case 1:
|
||||
arg = lua_tostring (lua_current_interpreter, -1);
|
||||
break;
|
||||
case 2:
|
||||
arg = lua_tostring (lua_current_interpreter, -2);
|
||||
server_name = lua_tostring (lua_current_interpreter, -1);
|
||||
break;
|
||||
default:
|
||||
lua_plugin->print_server (lua_plugin,
|
||||
"Lua error: wrong parameters for "
|
||||
"\"get_info\" function");
|
||||
lua_pushnumber (lua_current_interpreter, 0);
|
||||
return 1;
|
||||
}
|
||||
|
||||
info = lua_plugin->get_info (lua_plugin, (char *) arg, (char *) server_name);
|
||||
@@ -746,6 +896,7 @@ weechat_lua_get_dcc_info (lua_State *L)
|
||||
char timebuffer2[64];
|
||||
struct in_addr in;
|
||||
int i;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) L;
|
||||
|
||||
@@ -767,7 +918,7 @@ weechat_lua_get_dcc_info (lua_State *L)
|
||||
|
||||
lua_newtable (lua_current_interpreter);
|
||||
|
||||
for(i=0, ptr_dcc = dcc_info; ptr_dcc; ptr_dcc = ptr_dcc->next_dcc, i++)
|
||||
for (i = 0, ptr_dcc = dcc_info; ptr_dcc; ptr_dcc = ptr_dcc->next_dcc, i++)
|
||||
{
|
||||
strftime(timebuffer1, sizeof(timebuffer1), "%F %T",
|
||||
localtime(&ptr_dcc->start_time));
|
||||
@@ -860,6 +1011,7 @@ weechat_lua_get_config (lua_State *L)
|
||||
const char *option;
|
||||
char *return_value;
|
||||
int n;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) L;
|
||||
|
||||
@@ -905,6 +1057,7 @@ weechat_lua_set_config (lua_State *L)
|
||||
{
|
||||
const char *option, *value;
|
||||
int n;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) L;
|
||||
|
||||
@@ -952,6 +1105,7 @@ weechat_lua_get_plugin_config (lua_State *L)
|
||||
const char *option;
|
||||
char *return_value;
|
||||
int n;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) L;
|
||||
|
||||
@@ -999,6 +1153,7 @@ weechat_lua_set_plugin_config (lua_State *L)
|
||||
{
|
||||
const char *option, *value;
|
||||
int n;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) L;
|
||||
|
||||
@@ -1047,6 +1202,7 @@ weechat_lua_get_server_info (lua_State *L)
|
||||
{
|
||||
t_plugin_server_info *server_info, *ptr_server;
|
||||
char timebuffer[64];
|
||||
|
||||
/* make gcc happy */
|
||||
(void) L;
|
||||
|
||||
@@ -1067,7 +1223,7 @@ weechat_lua_get_server_info (lua_State *L)
|
||||
|
||||
lua_newtable (lua_current_interpreter);
|
||||
|
||||
for(ptr_server = server_info; ptr_server; ptr_server = ptr_server->next_server)
|
||||
for (ptr_server = server_info; ptr_server; ptr_server = ptr_server->next_server)
|
||||
{
|
||||
strftime(timebuffer, sizeof(timebuffer), "%F %T",
|
||||
localtime(&ptr_server->away_time));
|
||||
@@ -1201,6 +1357,7 @@ weechat_lua_get_channel_info (lua_State *L)
|
||||
t_plugin_channel_info *channel_info, *ptr_channel;
|
||||
const char *server;
|
||||
int n;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) L;
|
||||
|
||||
@@ -1237,7 +1394,7 @@ weechat_lua_get_channel_info (lua_State *L)
|
||||
|
||||
lua_newtable (lua_current_interpreter);
|
||||
|
||||
for(ptr_channel = channel_info; ptr_channel; ptr_channel = ptr_channel->next_channel)
|
||||
for (ptr_channel = channel_info; ptr_channel; ptr_channel = ptr_channel->next_channel)
|
||||
{
|
||||
lua_pushstring (lua_current_interpreter, ptr_channel->name);
|
||||
lua_newtable (lua_current_interpreter);
|
||||
@@ -1284,6 +1441,7 @@ weechat_lua_get_nick_info (lua_State *L)
|
||||
t_plugin_nick_info *nick_info, *ptr_nick;
|
||||
const char *server, *channel;
|
||||
int n;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) L;
|
||||
|
||||
@@ -1349,6 +1507,7 @@ weechat_lua_constant_plugin_rc_ok (lua_State *L)
|
||||
{
|
||||
/* make gcc happy */
|
||||
(void) L;
|
||||
|
||||
lua_pushnumber (lua_current_interpreter, PLUGIN_RC_OK);
|
||||
return 1;
|
||||
}
|
||||
@@ -1358,6 +1517,7 @@ weechat_lua_constant_plugin_rc_ko (lua_State *L)
|
||||
{
|
||||
/* make gcc happy */
|
||||
(void) L;
|
||||
|
||||
lua_pushnumber (lua_current_interpreter, PLUGIN_RC_KO);
|
||||
return 1;
|
||||
}
|
||||
@@ -1367,6 +1527,7 @@ weechat_lua_constant_plugin_rc_ok_ignore_weechat (lua_State *L)
|
||||
{
|
||||
/* make gcc happy */
|
||||
(void) L;
|
||||
|
||||
lua_pushnumber (lua_current_interpreter, PLUGIN_RC_OK_IGNORE_WEECHAT);
|
||||
return 1;
|
||||
}
|
||||
@@ -1376,6 +1537,7 @@ weechat_lua_constant_plugin_rc_ok_ignore_plugins (lua_State *L)
|
||||
{
|
||||
/* make gcc happy */
|
||||
(void) L;
|
||||
|
||||
lua_pushnumber (lua_current_interpreter, PLUGIN_RC_OK_IGNORE_PLUGINS);
|
||||
return 1;
|
||||
}
|
||||
@@ -1385,6 +1547,7 @@ weechat_lua_constant_plugin_rc_ok_ignore_all (lua_State *L)
|
||||
{
|
||||
/* make gcc happy */
|
||||
(void) L;
|
||||
|
||||
lua_pushnumber (lua_current_interpreter, PLUGIN_RC_OK_IGNORE_ALL);
|
||||
return 1;
|
||||
}
|
||||
@@ -1404,8 +1567,10 @@ const struct luaL_reg weechat_lua_funcs[] = {
|
||||
{ "add_message_handler", weechat_lua_add_message_handler},
|
||||
{ "add_command_handler", weechat_lua_add_command_handler},
|
||||
{ "add_timer_handler", weechat_lua_add_timer_handler},
|
||||
{ "add_keyboard_handler", weechat_lua_add_keyboard_handler},
|
||||
{ "remove_handler", weechat_lua_remove_handler},
|
||||
{ "remove_timer_handler", weechat_lua_remove_timer_handler},
|
||||
{ "remove_keyboard_handler", weechat_lua_remove_keyboard_handler},
|
||||
{ "get_info", weechat_lua_get_info},
|
||||
{ "get_dcc_info", weechat_lua_get_dcc_info},
|
||||
{ "get_config", weechat_lua_get_config},
|
||||
@@ -1536,7 +1701,7 @@ weechat_lua_unload (t_weechat_plugin *plugin, t_plugin_script *script)
|
||||
script->name);
|
||||
|
||||
if (script->shutdown_func[0])
|
||||
weechat_lua_exec (plugin, script, script->shutdown_func, "", "");
|
||||
weechat_lua_exec (plugin, script, script->shutdown_func, "", "", "");
|
||||
|
||||
lua_close (script->interpreter);
|
||||
|
||||
@@ -1590,8 +1755,8 @@ weechat_lua_unload_all (t_weechat_plugin *plugin)
|
||||
|
||||
int
|
||||
weechat_lua_cmd (t_weechat_plugin *plugin,
|
||||
char *server, char *command, char *arguments,
|
||||
char *handler_args, void *handler_pointer)
|
||||
int cmd_argc, char **cmd_argv,
|
||||
char *handler_args, void *handler_pointer)
|
||||
{
|
||||
int argc, handler_found;
|
||||
char **argv, *path_script;
|
||||
@@ -1599,13 +1764,14 @@ weechat_lua_cmd (t_weechat_plugin *plugin,
|
||||
t_plugin_handler *ptr_handler;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) server;
|
||||
(void) command;
|
||||
(void) handler_args;
|
||||
(void) handler_pointer;
|
||||
|
||||
if (arguments)
|
||||
argv = plugin->explode_string (plugin, arguments, " ", 0, &argc);
|
||||
if (cmd_argc < 3)
|
||||
return PLUGIN_RC_KO;
|
||||
|
||||
if (cmd_argv[2])
|
||||
argv = plugin->explode_string (plugin, cmd_argv[2], " ", 0, &argc);
|
||||
else
|
||||
{
|
||||
argv = NULL;
|
||||
@@ -1687,6 +1853,24 @@ weechat_lua_cmd (t_weechat_plugin *plugin,
|
||||
ptr_handler->handler_args);
|
||||
}
|
||||
}
|
||||
if (!handler_found)
|
||||
plugin->print_server (plugin, " (none)");
|
||||
|
||||
/* list Lua keyboard handlers */
|
||||
plugin->print_server (plugin, "");
|
||||
plugin->print_server (plugin, "Lua keyboard handlers:");
|
||||
handler_found = 0;
|
||||
for (ptr_handler = plugin->handlers;
|
||||
ptr_handler; ptr_handler = ptr_handler->next_handler)
|
||||
{
|
||||
if ((ptr_handler->type == HANDLER_KEYBOARD)
|
||||
&& (ptr_handler->handler_args))
|
||||
{
|
||||
handler_found = 1;
|
||||
plugin->print_server (plugin, " Lua(%s)",
|
||||
ptr_handler->handler_args);
|
||||
}
|
||||
}
|
||||
if (!handler_found)
|
||||
plugin->print_server (plugin, " (none)");
|
||||
break;
|
||||
@@ -1730,7 +1914,7 @@ weechat_lua_cmd (t_weechat_plugin *plugin,
|
||||
if (argv)
|
||||
plugin->free_exploded_string (plugin, argv);
|
||||
|
||||
return 1;
|
||||
return PLUGIN_RC_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -103,11 +103,11 @@ char *weechat_perl_code =
|
||||
int
|
||||
weechat_perl_exec (t_weechat_plugin *plugin,
|
||||
t_plugin_script *script,
|
||||
char *function, char *server, char *arguments)
|
||||
char *function, char *arg1, char *arg2, char *arg3)
|
||||
{
|
||||
char empty_server[1] = { '\0' };
|
||||
char empty_arg[1] = { '\0' };
|
||||
char *func;
|
||||
char *argv[3];
|
||||
char *argv[4];
|
||||
unsigned int count;
|
||||
int return_code;
|
||||
SV *sv;
|
||||
@@ -116,11 +116,11 @@ weechat_perl_exec (t_weechat_plugin *plugin,
|
||||
dSP;
|
||||
|
||||
#ifndef MULTIPLICITY
|
||||
int size = strlen(script->interpreter) + strlen(function) + 3;
|
||||
int size = strlen (script->interpreter) + strlen(function) + 3;
|
||||
func = (char *) malloc ( size * sizeof(char));
|
||||
if (func == NULL)
|
||||
if (!func)
|
||||
return PLUGIN_RC_KO;
|
||||
snprintf(func, size, "%s::%s", (char *) script->interpreter, function);
|
||||
snprintf (func, size, "%s::%s", (char *) script->interpreter, function);
|
||||
#else
|
||||
func = function;
|
||||
PERL_SET_CONTEXT (script->interpreter);
|
||||
@@ -129,12 +129,25 @@ weechat_perl_exec (t_weechat_plugin *plugin,
|
||||
ENTER;
|
||||
SAVETMPS;
|
||||
PUSHMARK(sp);
|
||||
if (!server)
|
||||
argv[0] = empty_server;
|
||||
if (arg1)
|
||||
{
|
||||
argv[0] = (arg1) ? arg1 : empty_arg;
|
||||
if (arg2)
|
||||
{
|
||||
argv[1] = (arg2) ? arg2 : empty_arg;
|
||||
if (arg3)
|
||||
{
|
||||
argv[2] = (arg3) ? arg3 : empty_arg;
|
||||
argv[3] = NULL;
|
||||
}
|
||||
else
|
||||
argv[2] = NULL;
|
||||
}
|
||||
else
|
||||
argv[1] = NULL;
|
||||
}
|
||||
else
|
||||
argv[0] = server;
|
||||
argv[1] = arguments;
|
||||
argv[2] = NULL;
|
||||
argv[0] = NULL;
|
||||
|
||||
perl_current_script = script;
|
||||
|
||||
@@ -166,26 +179,59 @@ weechat_perl_exec (t_weechat_plugin *plugin,
|
||||
LEAVE;
|
||||
|
||||
#ifndef MULTIPLICITY
|
||||
free(func);
|
||||
free (func);
|
||||
#endif
|
||||
|
||||
return return_code;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_perl_handler: general message and command handler for Perl
|
||||
* weechat_perl_cmd_msg_handler: general command/message handler for Perl
|
||||
*/
|
||||
|
||||
int
|
||||
weechat_perl_handler (t_weechat_plugin *plugin,
|
||||
char *server, char *command, char *arguments,
|
||||
char *handler_args, void *handler_pointer)
|
||||
weechat_perl_cmd_msg_handler (t_weechat_plugin *plugin,
|
||||
int argc, char **argv,
|
||||
char *handler_args, void *handler_pointer)
|
||||
{
|
||||
if (argc >= 3)
|
||||
return weechat_perl_exec (plugin, (t_plugin_script *)handler_pointer,
|
||||
handler_args, argv[0], argv[2], NULL);
|
||||
else
|
||||
return PLUGIN_RC_KO;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_perl_timer_handler: general timer handler for Perl
|
||||
*/
|
||||
|
||||
int
|
||||
weechat_perl_timer_handler (t_weechat_plugin *plugin,
|
||||
int argc, char **argv,
|
||||
char *handler_args, void *handler_pointer)
|
||||
{
|
||||
/* make gcc happy */
|
||||
(void) command;
|
||||
(void) argc;
|
||||
(void) argv;
|
||||
|
||||
return weechat_perl_exec (plugin, (t_plugin_script *)handler_pointer,
|
||||
handler_args, server, arguments);
|
||||
handler_args, NULL, NULL, NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_perl_keyboard_handler: general keyboard handler for Perl
|
||||
*/
|
||||
|
||||
int
|
||||
weechat_perl_keyboard_handler (t_weechat_plugin *plugin,
|
||||
int argc, char **argv,
|
||||
char *handler_args, void *handler_pointer)
|
||||
{
|
||||
if (argc >= 3)
|
||||
return weechat_perl_exec (plugin, (t_plugin_script *)handler_pointer,
|
||||
handler_args, argv[0], argv[1], argv[2]);
|
||||
else
|
||||
return PLUGIN_RC_KO;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -456,7 +502,7 @@ static XS (XS_weechat_command)
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat::add_message_handler: add handler for messages (privmsg, ...)
|
||||
* weechat::add_message_handler: add a handler for messages (privmsg, ...)
|
||||
*/
|
||||
|
||||
static XS (XS_weechat_add_message_handler)
|
||||
@@ -488,7 +534,7 @@ static XS (XS_weechat_add_message_handler)
|
||||
function = SvPV (ST (1), integer);
|
||||
|
||||
if (perl_plugin->msg_handler_add (perl_plugin, irc_command,
|
||||
weechat_perl_handler, function,
|
||||
weechat_perl_cmd_msg_handler, function,
|
||||
(void *)perl_current_script))
|
||||
XSRETURN_YES;
|
||||
|
||||
@@ -496,7 +542,7 @@ static XS (XS_weechat_add_message_handler)
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat::add_command_handler: add command handler (define/redefine commands)
|
||||
* weechat::add_command_handler: add a command handler (define/redefine commands)
|
||||
*/
|
||||
|
||||
static XS (XS_weechat_add_command_handler)
|
||||
@@ -538,7 +584,7 @@ static XS (XS_weechat_add_command_handler)
|
||||
arguments,
|
||||
arguments_description,
|
||||
completion_template,
|
||||
weechat_perl_handler,
|
||||
weechat_perl_cmd_msg_handler,
|
||||
function,
|
||||
(void *)perl_current_script))
|
||||
XSRETURN_YES;
|
||||
@@ -547,7 +593,7 @@ static XS (XS_weechat_add_command_handler)
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat::add_timer_handler: add timer handler
|
||||
* weechat::add_timer_handler: add a timer handler
|
||||
*/
|
||||
|
||||
static XS (XS_weechat_add_timer_handler)
|
||||
@@ -579,16 +625,54 @@ static XS (XS_weechat_add_timer_handler)
|
||||
interval = SvIV (ST (0));
|
||||
function = SvPV (ST (1), integer);
|
||||
|
||||
perl_plugin->print_server (perl_plugin,
|
||||
"Perl add timer: interval = %d", interval);
|
||||
if (perl_plugin->timer_handler_add (perl_plugin, interval,
|
||||
weechat_perl_handler, function,
|
||||
weechat_perl_timer_handler, function,
|
||||
(void *)perl_current_script))
|
||||
XSRETURN_YES;
|
||||
|
||||
XSRETURN_NO;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat::add_keyboard_handler: add a keyboard handler
|
||||
*/
|
||||
|
||||
static XS (XS_weechat_add_keyboard_handler)
|
||||
{
|
||||
char *function;
|
||||
unsigned int integer;
|
||||
dXSARGS;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) cv;
|
||||
|
||||
if (!perl_current_script)
|
||||
{
|
||||
perl_plugin->print_server (perl_plugin,
|
||||
"Perl error: unable to add keyboard handler, "
|
||||
"script not initialized");
|
||||
XSRETURN_NO;
|
||||
}
|
||||
|
||||
if (items < 1)
|
||||
{
|
||||
perl_plugin->print_server (perl_plugin,
|
||||
"Perl error: wrong parameters for "
|
||||
"\"add_keyboard_handler\" function");
|
||||
XSRETURN_NO;
|
||||
}
|
||||
|
||||
function = SvPV (ST (0), integer);
|
||||
|
||||
if (perl_plugin->keyboard_handler_add (perl_plugin,
|
||||
weechat_perl_keyboard_handler,
|
||||
function,
|
||||
(void *)perl_current_script))
|
||||
XSRETURN_YES;
|
||||
|
||||
XSRETURN_NO;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat::remove_handler: remove a message/command handler
|
||||
*/
|
||||
@@ -664,6 +748,43 @@ static XS (XS_weechat_remove_timer_handler)
|
||||
XSRETURN_YES;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat::remove_keyboard_handler: remove a keyboard handler
|
||||
*/
|
||||
|
||||
static XS (XS_weechat_remove_keyboard_handler)
|
||||
{
|
||||
char *function;
|
||||
unsigned int integer;
|
||||
dXSARGS;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) cv;
|
||||
|
||||
if (!perl_current_script)
|
||||
{
|
||||
perl_plugin->print_server (perl_plugin,
|
||||
"Perl error: unable to remove keyboard handler, "
|
||||
"script not initialized");
|
||||
XSRETURN_NO;
|
||||
}
|
||||
|
||||
if (items < 1)
|
||||
{
|
||||
perl_plugin->print_server (perl_plugin,
|
||||
"Perl error: wrong parameters for "
|
||||
"\"remove_keyboard_handler\" function");
|
||||
XSRETURN_NO;
|
||||
}
|
||||
|
||||
function = SvPV (ST (0), integer);
|
||||
|
||||
weechat_script_remove_keyboard_handler (perl_plugin, perl_current_script,
|
||||
function);
|
||||
|
||||
XSRETURN_YES;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat::get_info: get various infos
|
||||
*/
|
||||
@@ -1170,6 +1291,43 @@ static XS (XS_weechat_get_nick_info)
|
||||
XSRETURN (1);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat::color_input: add color in input buffer
|
||||
*/
|
||||
|
||||
static XS (XS_weechat_input_color)
|
||||
{
|
||||
int color, start, length;
|
||||
dXSARGS;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) cv;
|
||||
|
||||
if (!perl_current_script)
|
||||
{
|
||||
perl_plugin->print_server (perl_plugin,
|
||||
"Perl error: unable to colorize input, "
|
||||
"script not initialized");
|
||||
XSRETURN_NO;
|
||||
}
|
||||
|
||||
if (items < 3)
|
||||
{
|
||||
perl_plugin->print_server (perl_plugin,
|
||||
"Perl error: wrong parameters for "
|
||||
"\"color_input\" function");
|
||||
XSRETURN_NO;
|
||||
}
|
||||
|
||||
color = SvIV (ST (0));
|
||||
start = SvIV (ST (1));
|
||||
length = SvIV (ST (2));
|
||||
|
||||
perl_plugin->input_color (perl_plugin, color, start, length);
|
||||
|
||||
XSRETURN_YES;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_perl_xs_init: initialize subroutines
|
||||
*/
|
||||
@@ -1191,8 +1349,10 @@ weechat_perl_xs_init (pTHX)
|
||||
newXS ("weechat::add_message_handler", XS_weechat_add_message_handler, "weechat");
|
||||
newXS ("weechat::add_command_handler", XS_weechat_add_command_handler, "weechat");
|
||||
newXS ("weechat::add_timer_handler", XS_weechat_add_timer_handler, "weechat");
|
||||
newXS ("weechat::add_keyboard_handler", XS_weechat_add_keyboard_handler, "weechat");
|
||||
newXS ("weechat::remove_handler", XS_weechat_remove_handler, "weechat");
|
||||
newXS ("weechat::remove_timer_handler", XS_weechat_remove_timer_handler, "weechat");
|
||||
newXS ("weechat::remove_keyboard_handler", XS_weechat_remove_keyboard_handler, "weechat");
|
||||
newXS ("weechat::get_info", XS_weechat_get_info, "weechat");
|
||||
newXS ("weechat::get_dcc_info", XS_weechat_get_dcc_info, "weechat");
|
||||
newXS ("weechat::get_config", XS_weechat_get_config, "weechat");
|
||||
@@ -1202,6 +1362,7 @@ weechat_perl_xs_init (pTHX)
|
||||
newXS ("weechat::get_server_info", XS_weechat_get_server_info, "weechat");
|
||||
newXS ("weechat::get_channel_info", XS_weechat_get_channel_info, "weechat");
|
||||
newXS ("weechat::get_nick_info", XS_weechat_get_nick_info, "weechat");
|
||||
newXS ("weechat::input_color", XS_weechat_input_color, "weechat");
|
||||
|
||||
/* interface constants */
|
||||
stash = gv_stashpv ("weechat", TRUE);
|
||||
@@ -1237,7 +1398,7 @@ weechat_perl_load (t_weechat_plugin *plugin, char *filename)
|
||||
snprintf(pkgname, sizeof(pkgname), "%s%d", PKG_NAME_PREFIX, packnum);
|
||||
packnum++;
|
||||
tempscript.interpreter = "WeechatPerlScriptLoader";
|
||||
eval = weechat_perl_exec (plugin, &tempscript, "weechat_perl_load_eval_file", filename, pkgname);
|
||||
eval = weechat_perl_exec (plugin, &tempscript, "weechat_perl_load_eval_file", filename, pkgname, "");
|
||||
#else
|
||||
perl_current_interpreter = perl_alloc();
|
||||
|
||||
@@ -1256,7 +1417,7 @@ weechat_perl_load (t_weechat_plugin *plugin, char *filename)
|
||||
perl_parse (perl_current_interpreter, weechat_perl_xs_init, 3, perl_args, NULL);
|
||||
|
||||
eval_pv (weechat_perl_code, TRUE);
|
||||
eval = weechat_perl_exec (plugin, &tempscript, "weechat_perl_load_eval_file", filename, "");
|
||||
eval = weechat_perl_exec (plugin, &tempscript, "weechat_perl_load_eval_file", filename, "", "");
|
||||
|
||||
free (perl_current_script_filename);
|
||||
|
||||
@@ -1338,7 +1499,7 @@ weechat_perl_unload (t_weechat_plugin *plugin, t_plugin_script *script)
|
||||
#endif
|
||||
|
||||
if (script->shutdown_func[0])
|
||||
weechat_perl_exec (plugin, script, script->shutdown_func, "", "");
|
||||
weechat_perl_exec (plugin, script, script->shutdown_func, "", "", "");
|
||||
|
||||
#ifndef MULTIPLICITY
|
||||
if (script->interpreter)
|
||||
@@ -1398,7 +1559,7 @@ weechat_perl_unload_all (t_weechat_plugin *plugin)
|
||||
|
||||
int
|
||||
weechat_perl_cmd (t_weechat_plugin *plugin,
|
||||
char *server, char *command, char *arguments,
|
||||
int cmd_argc, char **cmd_argv,
|
||||
char *handler_args, void *handler_pointer)
|
||||
{
|
||||
int argc, handler_found;
|
||||
@@ -1406,14 +1567,15 @@ weechat_perl_cmd (t_weechat_plugin *plugin,
|
||||
t_plugin_script *ptr_script;
|
||||
t_plugin_handler *ptr_handler;
|
||||
|
||||
if (cmd_argc < 3)
|
||||
return PLUGIN_RC_KO;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) server;
|
||||
(void) command;
|
||||
(void) handler_args;
|
||||
(void) handler_pointer;
|
||||
|
||||
if (arguments)
|
||||
argv = plugin->explode_string (plugin, arguments, " ", 0, &argc);
|
||||
if (cmd_argv[2])
|
||||
argv = plugin->explode_string (plugin, cmd_argv[2], " ", 0, &argc);
|
||||
else
|
||||
{
|
||||
argv = NULL;
|
||||
@@ -1497,6 +1659,22 @@ weechat_perl_cmd (t_weechat_plugin *plugin,
|
||||
}
|
||||
if (!handler_found)
|
||||
plugin->print_server (plugin, " (none)");
|
||||
|
||||
/* list Perl keyboard handlers */
|
||||
plugin->print_server (plugin, "");
|
||||
plugin->print_server (plugin, "Perl keyboard handlers:");
|
||||
handler_found = 0;
|
||||
for (ptr_handler = plugin->handlers;
|
||||
ptr_handler; ptr_handler = ptr_handler->next_handler)
|
||||
{
|
||||
if ((ptr_handler->type == HANDLER_KEYBOARD)
|
||||
&& (ptr_handler->handler_args))
|
||||
{
|
||||
handler_found = 1;
|
||||
plugin->print_server (plugin, " Perl(%s)",
|
||||
ptr_handler->handler_args);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
if (plugin->ascii_strcasecmp (plugin, argv[0], "autoload") == 0)
|
||||
@@ -1538,7 +1716,7 @@ weechat_perl_cmd (t_weechat_plugin *plugin,
|
||||
if (argv)
|
||||
plugin->free_exploded_string (plugin, argv);
|
||||
|
||||
return 1;
|
||||
return PLUGIN_RC_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -50,7 +50,7 @@ PyThreadState *python_mainThreadState = NULL;
|
||||
int
|
||||
weechat_python_exec (t_weechat_plugin *plugin,
|
||||
t_plugin_script *script,
|
||||
char *function, char *server, char *arguments)
|
||||
char *function, char *arg1, char *arg2, char *arg3)
|
||||
{
|
||||
PyObject *evMain;
|
||||
PyObject *evDict;
|
||||
@@ -75,8 +75,21 @@ weechat_python_exec (t_weechat_plugin *plugin,
|
||||
ret = -1;
|
||||
|
||||
python_current_script = script;
|
||||
|
||||
rc = PyObject_CallFunction(evFunc, "ss", server == NULL ? "" : server, arguments == NULL ? "" : arguments);
|
||||
|
||||
if (arg1)
|
||||
{
|
||||
if (arg2)
|
||||
{
|
||||
if (arg3)
|
||||
rc = PyObject_CallFunction (evFunc, "sss", arg1, arg2, arg3);
|
||||
else
|
||||
rc = PyObject_CallFunction (evFunc, "ss", arg1, arg2);
|
||||
}
|
||||
else
|
||||
rc = PyObject_CallFunction (evFunc, "s", arg1);
|
||||
}
|
||||
else
|
||||
rc = PyObject_CallFunction (evFunc, "");
|
||||
|
||||
if (rc)
|
||||
{
|
||||
@@ -94,19 +107,52 @@ weechat_python_exec (t_weechat_plugin *plugin,
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_python_handler: general message and command handler for Python
|
||||
* weechat_python_cmd_msg_handler: general command/message handler for Python
|
||||
*/
|
||||
|
||||
int
|
||||
weechat_python_handler (t_weechat_plugin *plugin,
|
||||
char *server, char *command, char *arguments,
|
||||
char *handler_args, void *handler_pointer)
|
||||
weechat_python_cmd_msg_handler (t_weechat_plugin *plugin,
|
||||
int argc, char **argv,
|
||||
char *handler_args, void *handler_pointer)
|
||||
{
|
||||
if (argc >= 3)
|
||||
return weechat_python_exec (plugin, (t_plugin_script *)handler_pointer,
|
||||
handler_args, argv[0], argv[2], NULL);
|
||||
else
|
||||
return PLUGIN_RC_KO;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_python_timer_handler: general timer handler for Python
|
||||
*/
|
||||
|
||||
int
|
||||
weechat_python_timer_handler (t_weechat_plugin *plugin,
|
||||
int argc, char **argv,
|
||||
char *handler_args, void *handler_pointer)
|
||||
{
|
||||
/* make gcc happy */
|
||||
(void) command;
|
||||
(void) argc;
|
||||
(void) argv;
|
||||
|
||||
return weechat_python_exec (plugin, (t_plugin_script *)handler_pointer,
|
||||
handler_args, server, arguments);
|
||||
handler_args, NULL, NULL, NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_python_keyboard_handler: general keyboard handler for Python
|
||||
*/
|
||||
|
||||
int
|
||||
weechat_python_keyboard_handler (t_weechat_plugin *plugin,
|
||||
int argc, char **argv,
|
||||
char *handler_args, void *handler_pointer)
|
||||
{
|
||||
if (argc >= 3)
|
||||
return weechat_python_exec (plugin, (t_plugin_script *)handler_pointer,
|
||||
handler_args, argv[0], argv[1], argv[2]);
|
||||
else
|
||||
return PLUGIN_RC_KO;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -392,7 +438,8 @@ weechat_python_add_message_handler (PyObject *self, PyObject *args)
|
||||
}
|
||||
|
||||
if (python_plugin->msg_handler_add (python_plugin, irc_command,
|
||||
weechat_python_handler, function,
|
||||
weechat_python_cmd_msg_handler,
|
||||
function,
|
||||
(void *)python_current_script))
|
||||
return Py_BuildValue ("i", 1);
|
||||
|
||||
@@ -443,7 +490,7 @@ weechat_python_add_command_handler (PyObject *self, PyObject *args)
|
||||
arguments,
|
||||
arguments_description,
|
||||
completion_template,
|
||||
weechat_python_handler,
|
||||
weechat_python_cmd_msg_handler,
|
||||
function,
|
||||
(void *)python_current_script))
|
||||
return Py_BuildValue ("i", 1);
|
||||
@@ -484,13 +531,53 @@ weechat_python_add_timer_handler (PyObject *self, PyObject *args)
|
||||
}
|
||||
|
||||
if (python_plugin->timer_handler_add (python_plugin, interval,
|
||||
weechat_python_handler, function,
|
||||
weechat_python_timer_handler,
|
||||
function,
|
||||
(void *)python_current_script))
|
||||
return Py_BuildValue ("i", 1);
|
||||
|
||||
return Py_BuildValue ("i", 0);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_python_add_keyboard_handler: add a keyboard handler
|
||||
*/
|
||||
|
||||
static PyObject *
|
||||
weechat_python_add_keyboard_handler (PyObject *self, PyObject *args)
|
||||
{
|
||||
char *function;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) self;
|
||||
|
||||
if (!python_current_script)
|
||||
{
|
||||
python_plugin->print_server (python_plugin,
|
||||
"Python error: unable to add keyboard handler, "
|
||||
"script not initialized");
|
||||
return Py_BuildValue ("i", 0);
|
||||
}
|
||||
|
||||
function = NULL;
|
||||
|
||||
if (!PyArg_ParseTuple (args, "s", &function))
|
||||
{
|
||||
python_plugin->print_server (python_plugin,
|
||||
"Python error: wrong parameters for "
|
||||
"\"add_keyboard_handler\" function");
|
||||
return Py_BuildValue ("i", 0);
|
||||
}
|
||||
|
||||
if (python_plugin->keyboard_handler_add (python_plugin,
|
||||
weechat_python_keyboard_handler,
|
||||
function,
|
||||
(void *)python_current_script))
|
||||
return Py_BuildValue ("i", 1);
|
||||
|
||||
return Py_BuildValue ("i", 0);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_python_remove_handler: remove a handler
|
||||
*/
|
||||
@@ -564,6 +651,42 @@ weechat_python_remove_timer_handler (PyObject *self, PyObject *args)
|
||||
return Py_BuildValue ("i", 1);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_python_remove_keyboard_handler: remove a keyboard handler
|
||||
*/
|
||||
|
||||
static PyObject *
|
||||
weechat_python_remove_keyboard_handler (PyObject *self, PyObject *args)
|
||||
{
|
||||
char *function;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) self;
|
||||
|
||||
if (!python_current_script)
|
||||
{
|
||||
python_plugin->print_server (python_plugin,
|
||||
"Python error: unable to remove keyboard handler, "
|
||||
"script not initialized");
|
||||
return Py_BuildValue ("i", 0);
|
||||
}
|
||||
|
||||
function = NULL;
|
||||
|
||||
if (!PyArg_ParseTuple (args, "s", &function))
|
||||
{
|
||||
python_plugin->print_server (python_plugin,
|
||||
"Python error: wrong parameters for "
|
||||
"\"remove_keyboard_handler\" function");
|
||||
return Py_BuildValue ("i", 0);
|
||||
}
|
||||
|
||||
weechat_script_remove_keyboard_handler (python_plugin, python_current_script,
|
||||
function);
|
||||
|
||||
return Py_BuildValue ("i", 1);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_python_get_info: get various infos
|
||||
*/
|
||||
@@ -1132,8 +1255,10 @@ PyMethodDef weechat_python_funcs[] = {
|
||||
{ "add_message_handler", weechat_python_add_message_handler, METH_VARARGS, "" },
|
||||
{ "add_command_handler", weechat_python_add_command_handler, METH_VARARGS, "" },
|
||||
{ "add_timer_handler", weechat_python_add_timer_handler, METH_VARARGS, "" },
|
||||
{ "add_keyboard_handler", weechat_python_add_keyboard_handler, METH_VARARGS, "" },
|
||||
{ "remove_handler", weechat_python_remove_handler, METH_VARARGS, "" },
|
||||
{ "remove_timer_handler", weechat_python_remove_timer_handler, METH_VARARGS, "" },
|
||||
{ "remove_keyboard_handler", weechat_python_remove_keyboard_handler, METH_VARARGS, "" },
|
||||
{ "get_info", weechat_python_get_info, METH_VARARGS, "" },
|
||||
{ "get_dcc_info", weechat_python_get_dcc_info, METH_VARARGS, "" },
|
||||
{ "get_config", weechat_python_get_config, METH_VARARGS, "" },
|
||||
@@ -1307,7 +1432,7 @@ weechat_python_unload (t_weechat_plugin *plugin, t_plugin_script *script)
|
||||
script->name);
|
||||
|
||||
if (script->shutdown_func[0])
|
||||
weechat_python_exec (plugin, script, script->shutdown_func, "", "");
|
||||
weechat_python_exec (plugin, script, script->shutdown_func, "", "", "");
|
||||
|
||||
PyThreadState_Swap (script->interpreter);
|
||||
Py_EndInterpreter (script->interpreter);
|
||||
@@ -1362,7 +1487,7 @@ weechat_python_unload_all (t_weechat_plugin *plugin)
|
||||
|
||||
int
|
||||
weechat_python_cmd (t_weechat_plugin *plugin,
|
||||
char *server, char *command, char *arguments,
|
||||
int cmd_argc, char **cmd_argv,
|
||||
char *handler_args, void *handler_pointer)
|
||||
{
|
||||
int argc, handler_found;
|
||||
@@ -1371,13 +1496,14 @@ weechat_python_cmd (t_weechat_plugin *plugin,
|
||||
t_plugin_handler *ptr_handler;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) server;
|
||||
(void) command;
|
||||
(void) handler_args;
|
||||
(void) handler_pointer;
|
||||
|
||||
if (arguments)
|
||||
argv = plugin->explode_string (plugin, arguments, " ", 0, &argc);
|
||||
if (cmd_argc < 3)
|
||||
return PLUGIN_RC_KO;
|
||||
|
||||
if (cmd_argv[2])
|
||||
argv = plugin->explode_string (plugin, cmd_argv[2], " ", 0, &argc);
|
||||
else
|
||||
{
|
||||
argv = NULL;
|
||||
@@ -1459,6 +1585,24 @@ weechat_python_cmd (t_weechat_plugin *plugin,
|
||||
ptr_handler->handler_args);
|
||||
}
|
||||
}
|
||||
if (!handler_found)
|
||||
plugin->print_server (plugin, " (none)");
|
||||
|
||||
/* list Python keyboard handlers */
|
||||
plugin->print_server (plugin, "");
|
||||
plugin->print_server (plugin, "Python keyboard handlers:");
|
||||
handler_found = 0;
|
||||
for (ptr_handler = plugin->handlers;
|
||||
ptr_handler; ptr_handler = ptr_handler->next_handler)
|
||||
{
|
||||
if ((ptr_handler->type == HANDLER_KEYBOARD)
|
||||
&& (ptr_handler->handler_args))
|
||||
{
|
||||
handler_found = 1;
|
||||
plugin->print_server (plugin, " Python(%s)",
|
||||
ptr_handler->handler_args);
|
||||
}
|
||||
}
|
||||
if (!handler_found)
|
||||
plugin->print_server (plugin, " (none)");
|
||||
break;
|
||||
@@ -1502,7 +1646,7 @@ weechat_python_cmd (t_weechat_plugin *plugin,
|
||||
if (argv)
|
||||
plugin->free_exploded_string (plugin, argv);
|
||||
|
||||
return 1;
|
||||
return PLUGIN_RC_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -104,7 +104,7 @@ rb_protect_funcall(VALUE recv, ID mid, int *state, int argc, ...)
|
||||
int
|
||||
weechat_ruby_exec (t_weechat_plugin *plugin,
|
||||
t_plugin_script *script,
|
||||
char *function, char *server, char *arguments)
|
||||
char *function, char *arg1, char *arg2, char *arg3)
|
||||
{
|
||||
VALUE ruby_retcode, err;
|
||||
int ruby_error;
|
||||
@@ -112,11 +112,32 @@ weechat_ruby_exec (t_weechat_plugin *plugin,
|
||||
(void) plugin;
|
||||
|
||||
ruby_current_script = script;
|
||||
|
||||
ruby_retcode = rb_protect_funcall ((VALUE) script->interpreter, rb_intern(function),
|
||||
&ruby_error, 2,
|
||||
rb_str_new2((server == NULL) ? "" : server),
|
||||
rb_str_new2((arguments == NULL) ? "" : arguments));
|
||||
|
||||
if (arg1)
|
||||
{
|
||||
if (arg2)
|
||||
{
|
||||
if (arg3)
|
||||
ruby_retcode = rb_protect_funcall ((VALUE) script->interpreter, rb_intern(function),
|
||||
&ruby_error, 3,
|
||||
rb_str_new2(arg1),
|
||||
rb_str_new2(arg2),
|
||||
rb_str_new2(arg3));
|
||||
else
|
||||
ruby_retcode = rb_protect_funcall ((VALUE) script->interpreter, rb_intern(function),
|
||||
&ruby_error, 2,
|
||||
rb_str_new2(arg1),
|
||||
rb_str_new2(arg2));
|
||||
}
|
||||
else
|
||||
ruby_retcode = rb_protect_funcall ((VALUE) script->interpreter, rb_intern(function),
|
||||
&ruby_error, 1,
|
||||
rb_str_new2(arg1));
|
||||
}
|
||||
else
|
||||
ruby_retcode = rb_protect_funcall ((VALUE) script->interpreter, rb_intern(function),
|
||||
&ruby_error, 0);
|
||||
|
||||
if (ruby_error)
|
||||
{
|
||||
ruby_plugin->print_server (ruby_plugin,
|
||||
@@ -137,19 +158,52 @@ weechat_ruby_exec (t_weechat_plugin *plugin,
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_ruby_handler: general message and command handler for Ruby
|
||||
* weechat_ruby_cmd_msg_handler: general command/message handler for Ruby
|
||||
*/
|
||||
|
||||
int
|
||||
weechat_ruby_handler (t_weechat_plugin *plugin,
|
||||
char *server, char *command, char *arguments,
|
||||
char *handler_args, void *handler_pointer)
|
||||
weechat_ruby_cmd_msg_handler (t_weechat_plugin *plugin,
|
||||
int argc, char **argv,
|
||||
char *handler_args, void *handler_pointer)
|
||||
{
|
||||
if (argc >= 3)
|
||||
return weechat_ruby_exec (plugin, (t_plugin_script *)handler_pointer,
|
||||
handler_args, argv[0], argv[2], NULL);
|
||||
else
|
||||
return PLUGIN_RC_KO;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_ruby_timer_handler: general timer handler for Ruby
|
||||
*/
|
||||
|
||||
int
|
||||
weechat_ruby_timer_handler (t_weechat_plugin *plugin,
|
||||
int argc, char **argv,
|
||||
char *handler_args, void *handler_pointer)
|
||||
{
|
||||
/* make gcc happy */
|
||||
(void) command;
|
||||
(void) argc;
|
||||
(void) argv;
|
||||
|
||||
return weechat_ruby_exec (plugin, (t_plugin_script *)handler_pointer,
|
||||
handler_args, server, arguments);
|
||||
handler_args, NULL, NULL, NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_ruby_keyboard_handler: general keyboard handler for Ruby
|
||||
*/
|
||||
|
||||
int
|
||||
weechat_ruby_keyboard_handler (t_weechat_plugin *plugin,
|
||||
int argc, char **argv,
|
||||
char *handler_args, void *handler_pointer)
|
||||
{
|
||||
if (argc >= 2)
|
||||
return weechat_ruby_exec (plugin, (t_plugin_script *)handler_pointer,
|
||||
handler_args, argv[0], argv[1], argv[2]);
|
||||
else
|
||||
return PLUGIN_RC_KO;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -482,7 +536,7 @@ weechat_ruby_command (int argc, VALUE *argv, VALUE class)
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_ruby_add_message_handler: add handler for messages
|
||||
* weechat_ruby_add_message_handler: add a handler for messages (privmsg, ...)
|
||||
*/
|
||||
|
||||
static VALUE
|
||||
@@ -519,7 +573,8 @@ weechat_ruby_add_message_handler (VALUE class, VALUE message, VALUE function)
|
||||
c_function = STR2CSTR (function);
|
||||
|
||||
if (ruby_plugin->msg_handler_add (ruby_plugin, c_message,
|
||||
weechat_ruby_handler, c_function,
|
||||
weechat_ruby_cmd_msg_handler,
|
||||
c_function,
|
||||
(void *)ruby_current_script))
|
||||
return INT2FIX (1);
|
||||
|
||||
@@ -527,7 +582,7 @@ weechat_ruby_add_message_handler (VALUE class, VALUE message, VALUE function)
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_ruby_add_command_handler: define/redefines commands
|
||||
* weechat_ruby_add_command_handler: add a command handler (define/redefine commands)
|
||||
*/
|
||||
|
||||
static VALUE
|
||||
@@ -608,7 +663,7 @@ weechat_ruby_add_command_handler (int argc, VALUE *argv, VALUE class)
|
||||
c_arguments,
|
||||
c_arguments_description,
|
||||
c_completion_template,
|
||||
weechat_ruby_handler,
|
||||
weechat_ruby_cmd_msg_handler,
|
||||
c_function,
|
||||
(void *)ruby_current_script))
|
||||
return INT2FIX (1);
|
||||
@@ -655,13 +710,57 @@ weechat_ruby_add_timer_handler (VALUE class, VALUE interval, VALUE function)
|
||||
c_function = STR2CSTR (function);
|
||||
|
||||
if (ruby_plugin->timer_handler_add (ruby_plugin, c_interval,
|
||||
weechat_ruby_handler, c_function,
|
||||
weechat_ruby_timer_handler,
|
||||
c_function,
|
||||
(void *)ruby_current_script))
|
||||
return INT2FIX (1);
|
||||
|
||||
return INT2FIX (0);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_ruby_add_keyboard_handler: add a keyboard handler
|
||||
*/
|
||||
|
||||
static VALUE
|
||||
weechat_ruby_add_keyboard_handler (VALUE class, VALUE function)
|
||||
{
|
||||
char *c_function;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) class;
|
||||
|
||||
if (!ruby_current_script)
|
||||
{
|
||||
ruby_plugin->print_server (ruby_plugin,
|
||||
"Ruby error: unable to add keyboard handler, "
|
||||
"script not initialized");
|
||||
return INT2FIX (0);
|
||||
}
|
||||
|
||||
c_function = NULL;
|
||||
|
||||
if (NIL_P (function))
|
||||
{
|
||||
ruby_plugin->print_server (ruby_plugin,
|
||||
"Ruby error: wrong parameters for "
|
||||
"\"add_keyboard_handler\" function");
|
||||
return INT2FIX (0);
|
||||
}
|
||||
|
||||
Check_Type (function, T_STRING);
|
||||
|
||||
c_function = STR2CSTR (function);
|
||||
|
||||
if (ruby_plugin->keyboard_handler_add (ruby_plugin,
|
||||
weechat_ruby_keyboard_handler,
|
||||
c_function,
|
||||
(void *)ruby_current_script))
|
||||
return INT2FIX (1);
|
||||
|
||||
return INT2FIX (0);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_ruby_remove_handler: remove a handler
|
||||
*/
|
||||
@@ -745,6 +844,46 @@ weechat_ruby_remove_timer_handler (VALUE class, VALUE function)
|
||||
return INT2FIX (1);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_ruby_remove_keyboard_handler: remove a keyboard handler
|
||||
*/
|
||||
|
||||
static VALUE
|
||||
weechat_ruby_remove_keyboard_handler (VALUE class, VALUE function)
|
||||
{
|
||||
char *c_function;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) class;
|
||||
|
||||
if (!ruby_current_script)
|
||||
{
|
||||
ruby_plugin->print_server (ruby_plugin,
|
||||
"Ruby error: unable to remove keyboard handler, "
|
||||
"script not initialized");
|
||||
return INT2FIX (0);
|
||||
}
|
||||
|
||||
c_function = NULL;
|
||||
|
||||
if (NIL_P (function))
|
||||
{
|
||||
ruby_plugin->print_server (ruby_plugin,
|
||||
"Ruby error: wrong parameters for "
|
||||
"\"remove_keyboard_handler\" function");
|
||||
return INT2FIX (0);
|
||||
}
|
||||
|
||||
Check_Type (function, T_STRING);
|
||||
|
||||
c_function = STR2CSTR (function);
|
||||
|
||||
weechat_script_remove_keyboard_handler (ruby_plugin, ruby_current_script,
|
||||
c_function);
|
||||
|
||||
return INT2FIX (1);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_ruby_get_info: get various infos
|
||||
*/
|
||||
@@ -1485,7 +1624,7 @@ weechat_ruby_unload (t_weechat_plugin *plugin, t_plugin_script *script)
|
||||
script->name);
|
||||
|
||||
if (script->shutdown_func[0])
|
||||
weechat_ruby_exec (plugin, script, script->shutdown_func, "", "");
|
||||
weechat_ruby_exec (plugin, script, script->shutdown_func, "", "", "");
|
||||
|
||||
if (script->interpreter)
|
||||
rb_gc_unregister_address (script->interpreter);
|
||||
@@ -1541,7 +1680,7 @@ weechat_ruby_unload_all (t_weechat_plugin *plugin)
|
||||
|
||||
int
|
||||
weechat_ruby_cmd (t_weechat_plugin *plugin,
|
||||
char *server, char *command, char *arguments,
|
||||
int cmd_argc, char **cmd_argv,
|
||||
char *handler_args, void *handler_pointer)
|
||||
{
|
||||
int argc, handler_found;
|
||||
@@ -1550,13 +1689,14 @@ weechat_ruby_cmd (t_weechat_plugin *plugin,
|
||||
t_plugin_handler *ptr_handler;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) server;
|
||||
(void) command;
|
||||
(void) handler_args;
|
||||
(void) handler_pointer;
|
||||
|
||||
if (arguments)
|
||||
argv = plugin->explode_string (plugin, arguments, " ", 0, &argc);
|
||||
if (cmd_argc < 3)
|
||||
return PLUGIN_RC_KO;
|
||||
|
||||
if (cmd_argv[2])
|
||||
argv = plugin->explode_string (plugin, cmd_argv[2], " ", 0, &argc);
|
||||
else
|
||||
{
|
||||
argv = NULL;
|
||||
@@ -1638,6 +1778,24 @@ weechat_ruby_cmd (t_weechat_plugin *plugin,
|
||||
ptr_handler->handler_args);
|
||||
}
|
||||
}
|
||||
if (!handler_found)
|
||||
plugin->print_server (plugin, " (none)");
|
||||
|
||||
/* list Ruby keyboard handlers */
|
||||
plugin->print_server (plugin, "");
|
||||
plugin->print_server (plugin, "Ruby keyboard handlers:");
|
||||
handler_found = 0;
|
||||
for (ptr_handler = plugin->handlers;
|
||||
ptr_handler; ptr_handler = ptr_handler->next_handler)
|
||||
{
|
||||
if ((ptr_handler->type == HANDLER_KEYBOARD)
|
||||
&& (ptr_handler->handler_args))
|
||||
{
|
||||
handler_found = 1;
|
||||
plugin->print_server (plugin, " Ruby(%s)",
|
||||
ptr_handler->handler_args);
|
||||
}
|
||||
}
|
||||
if (!handler_found)
|
||||
plugin->print_server (plugin, " (none)");
|
||||
break;
|
||||
@@ -1681,7 +1839,7 @@ weechat_ruby_cmd (t_weechat_plugin *plugin,
|
||||
if (argv)
|
||||
plugin->free_exploded_string (plugin, argv);
|
||||
|
||||
return 1;
|
||||
return PLUGIN_RC_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1758,8 +1916,10 @@ weechat_plugin_init (t_weechat_plugin *plugin)
|
||||
rb_define_module_function (mWeechat, "add_message_handler", weechat_ruby_add_message_handler, 2);
|
||||
rb_define_module_function (mWeechat, "add_command_handler", weechat_ruby_add_command_handler, -1);
|
||||
rb_define_module_function (mWeechat, "add_timer_handler", weechat_ruby_add_timer_handler, 2);
|
||||
rb_define_module_function (mWeechat, "add_keyboard_handler", weechat_ruby_add_keyboard_handler, 1);
|
||||
rb_define_module_function (mWeechat, "remove_handler", weechat_ruby_remove_handler, 2);
|
||||
rb_define_module_function (mWeechat, "remove_timer_handler", weechat_ruby_remove_timer_handler, 1);
|
||||
rb_define_module_function (mWeechat, "remove_keyboard_handler", weechat_ruby_remove_keyboard_handler, 1);
|
||||
rb_define_module_function (mWeechat, "get_info", weechat_ruby_get_info, -1);
|
||||
rb_define_module_function (mWeechat, "get_dcc_info", weechat_ruby_get_dcc_info, 0);
|
||||
rb_define_module_function (mWeechat, "get_config", weechat_ruby_get_config, 1);
|
||||
|
||||
@@ -317,7 +317,36 @@ weechat_script_remove_timer_handler (t_weechat_plugin *plugin,
|
||||
ptr_handler = plugin->handlers;
|
||||
while (ptr_handler)
|
||||
{
|
||||
if (((t_plugin_script *)ptr_handler->handler_pointer == script)
|
||||
if ((ptr_handler->type == HANDLER_TIMER)
|
||||
&& ((t_plugin_script *)ptr_handler->handler_pointer == script)
|
||||
&& (plugin->ascii_strcasecmp (plugin, ptr_handler->handler_args, function) == 0))
|
||||
{
|
||||
next_handler = ptr_handler->next_handler;
|
||||
plugin->handler_remove (plugin, ptr_handler);
|
||||
ptr_handler = next_handler;
|
||||
}
|
||||
else
|
||||
ptr_handler = ptr_handler->next_handler;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_script_remove_keyboard_handler: remove a keyboard handler for a script
|
||||
*/
|
||||
|
||||
void
|
||||
weechat_script_remove_keyboard_handler (t_weechat_plugin *plugin,
|
||||
t_plugin_script *script,
|
||||
char *function)
|
||||
{
|
||||
t_plugin_handler *ptr_handler, *next_handler;
|
||||
|
||||
/* search and remove keyboard handlers */
|
||||
ptr_handler = plugin->handlers;
|
||||
while (ptr_handler)
|
||||
{
|
||||
if ((ptr_handler->type == HANDLER_KEYBOARD)
|
||||
&& ((t_plugin_script *)ptr_handler->handler_pointer == script)
|
||||
&& (plugin->ascii_strcasecmp (plugin, ptr_handler->handler_args, function) == 0))
|
||||
{
|
||||
next_handler = ptr_handler->next_handler;
|
||||
|
||||
@@ -56,6 +56,9 @@ extern void weechat_script_remove_handler (t_weechat_plugin *,
|
||||
extern void weechat_script_remove_timer_handler (t_weechat_plugin *,
|
||||
t_plugin_script *,
|
||||
char *);
|
||||
extern void weechat_script_remove_keyboard_handler (t_weechat_plugin *,
|
||||
t_plugin_script *,
|
||||
char *);
|
||||
extern char *weechat_script_get_plugin_config (t_weechat_plugin *,
|
||||
t_plugin_script *,
|
||||
char *);
|
||||
|
||||
Reference in New Issue
Block a user