adding functions : get_buffer_info, get_window_info, get_buffer_data and print_server in scripts API
This commit is contained in:
parent
8ee907af02
commit
22b80dec65
@ -241,24 +241,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,
|
||||
@ -270,6 +270,49 @@ weechat_lua_print (lua_State *L)
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_lua_print_server: print message into a buffer server
|
||||
*/
|
||||
|
||||
static int
|
||||
weechat_lua_print_server (lua_State *L)
|
||||
{
|
||||
const char *message;
|
||||
int n;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) L;
|
||||
|
||||
if (!lua_current_script)
|
||||
{
|
||||
lua_plugin->print_server (lua_plugin,
|
||||
"Lua error: unable to print message, "
|
||||
"script not initialized");
|
||||
lua_pushnumber (lua_current_interpreter, 0);
|
||||
return 1;
|
||||
}
|
||||
|
||||
message = NULL;
|
||||
|
||||
n = lua_gettop (lua_current_interpreter);
|
||||
|
||||
if (n == 1)
|
||||
message = lua_tostring (lua_current_interpreter, -1);
|
||||
else
|
||||
{
|
||||
lua_plugin->print_server (lua_plugin,
|
||||
"Lua error: wrong parameters for "
|
||||
"\"print_server\" function");
|
||||
lua_pushnumber (lua_current_interpreter, 0);
|
||||
return 1;
|
||||
}
|
||||
|
||||
lua_plugin->print_server (lua_plugin, "%s", (char *) message);
|
||||
|
||||
lua_pushnumber (lua_current_interpreter, 1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_lua_print_infobar: print message to infobar
|
||||
*/
|
||||
@ -350,7 +393,7 @@ weechat_lua_remove_infobar (lua_State *L)
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_lua_print: log message in server/channel (current or specified ones)
|
||||
* weechat_lua_log: log message in server/channel (current or specified ones)
|
||||
*/
|
||||
|
||||
static int
|
||||
@ -1543,6 +1586,226 @@ weechat_lua_get_irc_color (lua_State *L)
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_lua_get_window_info: get infos about windows
|
||||
*/
|
||||
|
||||
static int
|
||||
weechat_lua_get_window_info (lua_State *L)
|
||||
{
|
||||
t_plugin_window_info *window_info, *ptr_window;
|
||||
int i;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) L;
|
||||
|
||||
if (!lua_current_script)
|
||||
{
|
||||
lua_plugin->print_server (lua_plugin,
|
||||
"Lua error: unable to get window info, "
|
||||
"script not initialized");
|
||||
lua_pushnil (lua_current_interpreter);
|
||||
return 1;
|
||||
}
|
||||
|
||||
window_info = lua_plugin->get_window_info (lua_plugin);
|
||||
if (!window_info)
|
||||
{
|
||||
lua_pushboolean (lua_current_interpreter, 0);
|
||||
return 1;
|
||||
}
|
||||
|
||||
lua_newtable (lua_current_interpreter);
|
||||
|
||||
for (i = 0, ptr_window = window_info; ptr_window; ptr_window = ptr_window->next_window, i++)
|
||||
{
|
||||
lua_pushnumber (lua_current_interpreter, i);
|
||||
lua_newtable (lua_current_interpreter);
|
||||
|
||||
lua_pushstring (lua_current_interpreter, "num_buffer");
|
||||
lua_pushnumber (lua_current_interpreter, ptr_window->num_buffer);
|
||||
lua_rawset (lua_current_interpreter, -3);
|
||||
|
||||
lua_pushstring (lua_current_interpreter, "win_x");
|
||||
lua_pushnumber (lua_current_interpreter, ptr_window->win_x);
|
||||
lua_rawset (lua_current_interpreter, -3);
|
||||
|
||||
lua_pushstring (lua_current_interpreter, "win_y");
|
||||
lua_pushnumber (lua_current_interpreter, ptr_window->win_y);
|
||||
lua_rawset (lua_current_interpreter, -3);
|
||||
|
||||
lua_pushstring (lua_current_interpreter, "win_width");
|
||||
lua_pushnumber (lua_current_interpreter, ptr_window->win_width);
|
||||
lua_rawset (lua_current_interpreter, -3);
|
||||
|
||||
lua_pushstring (lua_current_interpreter, "win_height");
|
||||
lua_pushnumber (lua_current_interpreter, ptr_window->win_height);
|
||||
lua_rawset (lua_current_interpreter, -3);
|
||||
|
||||
lua_pushstring (lua_current_interpreter, "win_width_pct");
|
||||
lua_pushnumber (lua_current_interpreter, ptr_window->win_width_pct);
|
||||
lua_rawset (lua_current_interpreter, -3);
|
||||
|
||||
lua_pushstring (lua_current_interpreter, "win_height_pct");
|
||||
lua_pushnumber (lua_current_interpreter, ptr_window->win_height_pct);
|
||||
lua_rawset (lua_current_interpreter, -3);
|
||||
|
||||
lua_rawset (lua_current_interpreter, -3);
|
||||
}
|
||||
|
||||
lua_plugin->free_window_info (lua_plugin, window_info);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_lua_get_buffer_info: get infos about buffers
|
||||
*/
|
||||
|
||||
static int
|
||||
weechat_lua_get_buffer_info (lua_State *L)
|
||||
{
|
||||
t_plugin_buffer_info *buffer_info, *ptr_buffer;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) L;
|
||||
|
||||
if (!lua_current_script)
|
||||
{
|
||||
lua_plugin->print_server (lua_plugin,
|
||||
"Lua error: unable to get buffer info, "
|
||||
"script not initialized");
|
||||
lua_pushnil (lua_current_interpreter);
|
||||
return 1;
|
||||
}
|
||||
|
||||
buffer_info = lua_plugin->get_buffer_info (lua_plugin);
|
||||
if (!buffer_info) {
|
||||
lua_pushboolean (lua_current_interpreter, 0);
|
||||
return 1;
|
||||
}
|
||||
|
||||
lua_newtable (lua_current_interpreter);
|
||||
|
||||
for (ptr_buffer = buffer_info; ptr_buffer; ptr_buffer = ptr_buffer->next_buffer)
|
||||
{
|
||||
lua_pushnumber (lua_current_interpreter, ptr_buffer->number);
|
||||
lua_newtable (lua_current_interpreter);
|
||||
|
||||
lua_pushstring (lua_current_interpreter, "type");
|
||||
lua_pushnumber (lua_current_interpreter, ptr_buffer->type);
|
||||
lua_rawset (lua_current_interpreter, -3);
|
||||
|
||||
lua_pushstring (lua_current_interpreter, "num_displayed");
|
||||
lua_pushnumber (lua_current_interpreter, ptr_buffer->num_displayed);
|
||||
lua_rawset (lua_current_interpreter, -3);
|
||||
|
||||
lua_pushstring (lua_current_interpreter, "server");
|
||||
lua_pushstring (lua_current_interpreter,
|
||||
ptr_buffer->server_name == NULL ? "" : ptr_buffer->server_name);
|
||||
lua_rawset (lua_current_interpreter, -3);
|
||||
|
||||
lua_pushstring (lua_current_interpreter, "channel");
|
||||
lua_pushstring (lua_current_interpreter,
|
||||
ptr_buffer->channel_name == NULL ? "" : ptr_buffer->channel_name);
|
||||
lua_rawset (lua_current_interpreter, -3);
|
||||
|
||||
lua_pushstring (lua_current_interpreter, "notify_level");
|
||||
lua_pushnumber (lua_current_interpreter, ptr_buffer->notify_level);
|
||||
lua_rawset (lua_current_interpreter, -3);
|
||||
|
||||
lua_pushstring (lua_current_interpreter, "log_filename");
|
||||
lua_pushstring (lua_current_interpreter,
|
||||
ptr_buffer->log_filename == NULL ? "" : ptr_buffer->log_filename);
|
||||
lua_rawset (lua_current_interpreter, -3);
|
||||
|
||||
lua_rawset (lua_current_interpreter, -3);
|
||||
}
|
||||
|
||||
lua_plugin->free_buffer_info(lua_plugin, buffer_info);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_lua_get_buffer_data: get buffer content
|
||||
*/
|
||||
|
||||
static int
|
||||
weechat_lua_get_buffer_data (lua_State *L)
|
||||
{
|
||||
t_plugin_buffer_line *buffer_data, *ptr_data;
|
||||
const char *server, *channel;
|
||||
int i, n;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) L;
|
||||
|
||||
if (!lua_current_script)
|
||||
{
|
||||
lua_plugin->print_server (lua_plugin,
|
||||
"Lua error: unable to get buffer data, "
|
||||
"script not initialized");
|
||||
lua_pushnil (lua_current_interpreter);
|
||||
return 1;
|
||||
}
|
||||
|
||||
server = NULL;
|
||||
channel = NULL;
|
||||
|
||||
n = lua_gettop (lua_current_interpreter);
|
||||
|
||||
switch (n)
|
||||
{
|
||||
case 0:
|
||||
break;
|
||||
case 1:
|
||||
server = lua_tostring (lua_current_interpreter, -1);
|
||||
break;
|
||||
case 2:
|
||||
channel = lua_tostring (lua_current_interpreter, -2);
|
||||
server = lua_tostring (lua_current_interpreter, -1);
|
||||
break;
|
||||
default:
|
||||
lua_plugin->print_server (lua_plugin,
|
||||
"Lua error: wrong parameters for "
|
||||
"\"get_buffer_data\" function");
|
||||
lua_pushnumber (lua_current_interpreter, 0);
|
||||
return 1;
|
||||
}
|
||||
|
||||
buffer_data = lua_plugin->get_buffer_data (lua_plugin, (char *) server, (char *) channel);
|
||||
if (!buffer_data)
|
||||
{
|
||||
lua_pushboolean (lua_current_interpreter, 0);
|
||||
return 1;
|
||||
}
|
||||
|
||||
lua_newtable (lua_current_interpreter);
|
||||
|
||||
for (i = 0, ptr_data = buffer_data; ptr_data; ptr_data = ptr_data->next_line, i++)
|
||||
{
|
||||
lua_pushnumber (lua_current_interpreter, i);
|
||||
lua_newtable (lua_current_interpreter);
|
||||
|
||||
lua_pushstring (lua_current_interpreter, "nick");
|
||||
lua_pushstring (lua_current_interpreter,
|
||||
ptr_data->nick == NULL ? "" : ptr_data->nick);
|
||||
lua_rawset (lua_current_interpreter, -3);
|
||||
|
||||
lua_pushstring (lua_current_interpreter, "data");
|
||||
lua_pushstring (lua_current_interpreter,
|
||||
ptr_data->data == NULL ? "" : ptr_data->data);
|
||||
lua_rawset (lua_current_interpreter, -3);
|
||||
|
||||
lua_rawset (lua_current_interpreter, -3);
|
||||
}
|
||||
|
||||
lua_plugin->free_buffer_data (lua_plugin, buffer_data);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Lua constant as functions
|
||||
*/
|
||||
@ -1605,6 +1868,7 @@ static
|
||||
const struct luaL_reg weechat_lua_funcs[] = {
|
||||
{ "register", weechat_lua_register},
|
||||
{ "print", weechat_lua_print},
|
||||
{ "print_server", weechat_lua_print_server},
|
||||
{ "print_infobar", weechat_lua_print_infobar},
|
||||
{ "remove_infobar", weechat_lua_remove_infobar},
|
||||
{ "log", weechat_lua_log},
|
||||
@ -1626,6 +1890,9 @@ const struct luaL_reg weechat_lua_funcs[] = {
|
||||
{ "get_channel_info", weechat_lua_get_channel_info},
|
||||
{ "get_nick_info", weechat_lua_get_nick_info},
|
||||
{ "get_irc_color", weechat_lua_get_irc_color},
|
||||
{ "get_window_info", weechat_lua_get_window_info},
|
||||
{ "get_buffer_info", weechat_lua_get_buffer_info},
|
||||
{ "get_buffer_data", weechat_lua_get_buffer_data},
|
||||
/* define constants as function which returns values */
|
||||
{ "PLUGIN_RC_OK", weechat_lua_constant_plugin_rc_ok},
|
||||
{ "PLUGIN_RC_KO", weechat_lua_constant_plugin_rc_ko},
|
||||
|
@ -241,7 +241,6 @@ weechat_perl_keyboard_handler (t_weechat_plugin *plugin,
|
||||
static XS (XS_weechat_register)
|
||||
{
|
||||
char *name, *version, *shutdown_func, *description;
|
||||
unsigned int integer;
|
||||
dXSARGS;
|
||||
|
||||
/* make gcc happy */
|
||||
@ -258,10 +257,10 @@ static XS (XS_weechat_register)
|
||||
XSRETURN_NO;
|
||||
}
|
||||
|
||||
name = SvPV (ST (0), integer);
|
||||
version = SvPV (ST (1), integer);
|
||||
shutdown_func = SvPV (ST (2), integer);
|
||||
description = SvPV (ST (3), integer);
|
||||
name = SvPV (ST (0), PL_na);
|
||||
version = SvPV (ST (1), PL_na);
|
||||
shutdown_func = SvPV (ST (2), PL_na);
|
||||
description = SvPV (ST (3), PL_na);
|
||||
|
||||
if (weechat_script_search (perl_plugin, &perl_scripts, name))
|
||||
{
|
||||
@ -302,7 +301,6 @@ static XS (XS_weechat_register)
|
||||
|
||||
static XS (XS_weechat_print)
|
||||
{
|
||||
unsigned int integer;
|
||||
char *message, *channel_name, *server_name;
|
||||
dXSARGS;
|
||||
|
||||
@ -325,16 +323,16 @@ static XS (XS_weechat_print)
|
||||
XSRETURN_NO;
|
||||
}
|
||||
|
||||
message = SvPV (ST (0), integer);
|
||||
message = SvPV (ST (0), PL_na);
|
||||
|
||||
channel_name = NULL;
|
||||
server_name = NULL;
|
||||
|
||||
if (items > 1)
|
||||
{
|
||||
channel_name = SvPV (ST (1), integer);
|
||||
channel_name = SvPV (ST (1), PL_na);
|
||||
if (items > 2)
|
||||
server_name = SvPV (ST (2), integer);
|
||||
server_name = SvPV (ST (2), PL_na);
|
||||
}
|
||||
|
||||
perl_plugin->print (perl_plugin,
|
||||
@ -344,13 +342,47 @@ static XS (XS_weechat_print)
|
||||
XSRETURN_YES;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat::print_server: print message into a server buffer
|
||||
*/
|
||||
|
||||
static XS (XS_weechat_print_server)
|
||||
{
|
||||
char *message;
|
||||
dXSARGS;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) cv;
|
||||
|
||||
if (!perl_current_script)
|
||||
{
|
||||
perl_plugin->print_server (perl_plugin,
|
||||
"Perl error: unable to print message, "
|
||||
"script not initialized");
|
||||
XSRETURN_NO;
|
||||
}
|
||||
|
||||
if (items < 1)
|
||||
{
|
||||
perl_plugin->print_server (perl_plugin,
|
||||
"Perl error: wrong parameters for "
|
||||
"\"print_server\" function");
|
||||
XSRETURN_NO;
|
||||
}
|
||||
|
||||
message = SvPV (ST (0), PL_na);
|
||||
|
||||
perl_plugin->print_server (perl_plugin, "%s", message);
|
||||
|
||||
XSRETURN_YES;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat::print_infobar: print message to infobar
|
||||
*/
|
||||
|
||||
static XS (XS_weechat_print_infobar)
|
||||
{
|
||||
unsigned int integer;
|
||||
dXSARGS;
|
||||
|
||||
/* make gcc happy */
|
||||
@ -375,7 +407,7 @@ static XS (XS_weechat_print_infobar)
|
||||
perl_plugin->print_infobar (perl_plugin,
|
||||
SvIV (ST (0)),
|
||||
"%s",
|
||||
SvPV (ST (1), integer));
|
||||
SvPV (ST (1), PL_na));
|
||||
|
||||
XSRETURN_YES;
|
||||
}
|
||||
@ -411,7 +443,6 @@ static XS (XS_weechat_remove_infobar)
|
||||
|
||||
static XS (XS_weechat_log)
|
||||
{
|
||||
unsigned int integer;
|
||||
char *message, *channel_name, *server_name;
|
||||
dXSARGS;
|
||||
|
||||
@ -434,16 +465,16 @@ static XS (XS_weechat_log)
|
||||
XSRETURN_NO;
|
||||
}
|
||||
|
||||
message = SvPV (ST (0), integer);
|
||||
message = SvPV (ST (0), PL_na);
|
||||
|
||||
channel_name = NULL;
|
||||
server_name = NULL;
|
||||
|
||||
if (items > 1)
|
||||
{
|
||||
channel_name = SvPV (ST (1), integer);
|
||||
channel_name = SvPV (ST (1), PL_na);
|
||||
if (items > 2)
|
||||
server_name = SvPV (ST (2), integer);
|
||||
server_name = SvPV (ST (2), PL_na);
|
||||
}
|
||||
|
||||
perl_plugin->log (perl_plugin,
|
||||
@ -459,7 +490,6 @@ static XS (XS_weechat_log)
|
||||
|
||||
static XS (XS_weechat_command)
|
||||
{
|
||||
unsigned int integer;
|
||||
char *channel_name, *server_name;
|
||||
dXSARGS;
|
||||
|
||||
@ -487,14 +517,14 @@ static XS (XS_weechat_command)
|
||||
|
||||
if (items > 1)
|
||||
{
|
||||
channel_name = SvPV (ST (1), integer);
|
||||
channel_name = SvPV (ST (1), PL_na);
|
||||
if (items > 2)
|
||||
server_name = SvPV (ST (2), integer);
|
||||
server_name = SvPV (ST (2), PL_na);
|
||||
}
|
||||
|
||||
perl_plugin->exec_command (perl_plugin,
|
||||
server_name, channel_name,
|
||||
SvPV (ST (0), integer));
|
||||
SvPV (ST (0), PL_na));
|
||||
|
||||
XSRETURN_YES;
|
||||
}
|
||||
@ -506,7 +536,6 @@ static XS (XS_weechat_command)
|
||||
static XS (XS_weechat_add_message_handler)
|
||||
{
|
||||
char *irc_command, *function;
|
||||
unsigned int integer;
|
||||
dXSARGS;
|
||||
|
||||
/* make gcc happy */
|
||||
@ -528,8 +557,8 @@ static XS (XS_weechat_add_message_handler)
|
||||
XSRETURN_NO;
|
||||
}
|
||||
|
||||
irc_command = SvPV (ST (0), integer);
|
||||
function = SvPV (ST (1), integer);
|
||||
irc_command = SvPV (ST (0), PL_na);
|
||||
function = SvPV (ST (1), PL_na);
|
||||
|
||||
if (perl_plugin->msg_handler_add (perl_plugin, irc_command,
|
||||
weechat_perl_cmd_msg_handler, function,
|
||||
@ -547,7 +576,6 @@ static XS (XS_weechat_add_command_handler)
|
||||
{
|
||||
char *command, *function, *description, *arguments, *arguments_description;
|
||||
char *completion_template;
|
||||
unsigned int integer;
|
||||
dXSARGS;
|
||||
|
||||
/* make gcc happy */
|
||||
@ -569,12 +597,12 @@ static XS (XS_weechat_add_command_handler)
|
||||
XSRETURN_NO;
|
||||
}
|
||||
|
||||
command = SvPV (ST (0), integer);
|
||||
function = SvPV (ST (1), integer);
|
||||
description = (items >= 3) ? SvPV (ST (2), integer) : NULL;
|
||||
arguments = (items >= 4) ? SvPV (ST (3), integer) : NULL;
|
||||
arguments_description = (items >= 5) ? SvPV (ST (4), integer) : NULL;
|
||||
completion_template = (items >= 6) ? SvPV (ST (5), integer) : NULL;
|
||||
command = SvPV (ST (0), PL_na);
|
||||
function = SvPV (ST (1), PL_na);
|
||||
description = (items >= 3) ? SvPV (ST (2), PL_na) : NULL;
|
||||
arguments = (items >= 4) ? SvPV (ST (3), PL_na) : NULL;
|
||||
arguments_description = (items >= 5) ? SvPV (ST (4), PL_na) : NULL;
|
||||
completion_template = (items >= 6) ? SvPV (ST (5), PL_na) : NULL;
|
||||
|
||||
if (perl_plugin->cmd_handler_add (perl_plugin,
|
||||
command,
|
||||
@ -598,7 +626,6 @@ static XS (XS_weechat_add_timer_handler)
|
||||
{
|
||||
int interval;
|
||||
char *function;
|
||||
unsigned int integer;
|
||||
dXSARGS;
|
||||
|
||||
/* make gcc happy */
|
||||
@ -621,7 +648,7 @@ static XS (XS_weechat_add_timer_handler)
|
||||
}
|
||||
|
||||
interval = SvIV (ST (0));
|
||||
function = SvPV (ST (1), integer);
|
||||
function = SvPV (ST (1), PL_na);
|
||||
|
||||
if (perl_plugin->timer_handler_add (perl_plugin, interval,
|
||||
weechat_perl_timer_handler, function,
|
||||
@ -638,7 +665,6 @@ static XS (XS_weechat_add_timer_handler)
|
||||
static XS (XS_weechat_add_keyboard_handler)
|
||||
{
|
||||
char *function;
|
||||
unsigned int integer;
|
||||
dXSARGS;
|
||||
|
||||
/* make gcc happy */
|
||||
@ -660,7 +686,7 @@ static XS (XS_weechat_add_keyboard_handler)
|
||||
XSRETURN_NO;
|
||||
}
|
||||
|
||||
function = SvPV (ST (0), integer);
|
||||
function = SvPV (ST (0), PL_na);
|
||||
|
||||
if (perl_plugin->keyboard_handler_add (perl_plugin,
|
||||
weechat_perl_keyboard_handler,
|
||||
@ -678,7 +704,6 @@ static XS (XS_weechat_add_keyboard_handler)
|
||||
static XS (XS_weechat_remove_handler)
|
||||
{
|
||||
char *command, *function;
|
||||
unsigned int integer;
|
||||
dXSARGS;
|
||||
|
||||
/* make gcc happy */
|
||||
@ -700,8 +725,8 @@ static XS (XS_weechat_remove_handler)
|
||||
XSRETURN_NO;
|
||||
}
|
||||
|
||||
command = SvPV (ST (0), integer);
|
||||
function = SvPV (ST (1), integer);
|
||||
command = SvPV (ST (0), PL_na);
|
||||
function = SvPV (ST (1), PL_na);
|
||||
|
||||
weechat_script_remove_handler (perl_plugin, perl_current_script,
|
||||
command, function);
|
||||
@ -716,7 +741,6 @@ static XS (XS_weechat_remove_handler)
|
||||
static XS (XS_weechat_remove_timer_handler)
|
||||
{
|
||||
char *function;
|
||||
unsigned int integer;
|
||||
dXSARGS;
|
||||
|
||||
/* make gcc happy */
|
||||
@ -738,7 +762,7 @@ static XS (XS_weechat_remove_timer_handler)
|
||||
XSRETURN_NO;
|
||||
}
|
||||
|
||||
function = SvPV (ST (0), integer);
|
||||
function = SvPV (ST (0), PL_na);
|
||||
|
||||
weechat_script_remove_timer_handler (perl_plugin, perl_current_script,
|
||||
function);
|
||||
@ -753,7 +777,6 @@ static XS (XS_weechat_remove_timer_handler)
|
||||
static XS (XS_weechat_remove_keyboard_handler)
|
||||
{
|
||||
char *function;
|
||||
unsigned int integer;
|
||||
dXSARGS;
|
||||
|
||||
/* make gcc happy */
|
||||
@ -775,7 +798,7 @@ static XS (XS_weechat_remove_keyboard_handler)
|
||||
XSRETURN_NO;
|
||||
}
|
||||
|
||||
function = SvPV (ST (0), integer);
|
||||
function = SvPV (ST (0), PL_na);
|
||||
|
||||
weechat_script_remove_keyboard_handler (perl_plugin, perl_current_script,
|
||||
function);
|
||||
@ -790,7 +813,6 @@ static XS (XS_weechat_remove_keyboard_handler)
|
||||
static XS (XS_weechat_get_info)
|
||||
{
|
||||
char *arg, *info, *server_name;
|
||||
unsigned int integer;
|
||||
dXSARGS;
|
||||
|
||||
/* make gcc happy */
|
||||
@ -812,9 +834,9 @@ static XS (XS_weechat_get_info)
|
||||
XSRETURN_NO;
|
||||
}
|
||||
|
||||
server_name = (items == 2) ? SvPV (ST (1), integer) : NULL;
|
||||
server_name = (items == 2) ? SvPV (ST (1), PL_na) : NULL;
|
||||
|
||||
arg = SvPV (ST (0), integer);
|
||||
arg = SvPV (ST (0), PL_na);
|
||||
if (arg)
|
||||
{
|
||||
info = perl_plugin->get_info (perl_plugin, arg, server_name);
|
||||
@ -904,7 +926,6 @@ static XS (XS_weechat_get_dcc_info)
|
||||
static XS (XS_weechat_get_config)
|
||||
{
|
||||
char *option, *return_value;
|
||||
unsigned int integer;
|
||||
dXSARGS;
|
||||
|
||||
/* make gcc happy */
|
||||
@ -915,7 +936,7 @@ static XS (XS_weechat_get_config)
|
||||
perl_plugin->print_server (perl_plugin,
|
||||
"Perl error: unable to get config option, "
|
||||
"script not initialized");
|
||||
XSRETURN_NO;
|
||||
XSRETURN_EMPTY;
|
||||
}
|
||||
|
||||
if (items < 1)
|
||||
@ -923,10 +944,10 @@ static XS (XS_weechat_get_config)
|
||||
perl_plugin->print_server (perl_plugin,
|
||||
"Perl error: wrong parameters for "
|
||||
"\"get_config\" function");
|
||||
XSRETURN_NO;
|
||||
XSRETURN_EMPTY;
|
||||
}
|
||||
|
||||
option = SvPV (ST (0), integer);
|
||||
option = SvPV (ST (0), PL_na);
|
||||
|
||||
if (option)
|
||||
{
|
||||
@ -951,7 +972,6 @@ static XS (XS_weechat_get_config)
|
||||
static XS (XS_weechat_set_config)
|
||||
{
|
||||
char *option, *value;
|
||||
unsigned int integer;
|
||||
dXSARGS;
|
||||
|
||||
/* make gcc happy */
|
||||
@ -973,8 +993,8 @@ static XS (XS_weechat_set_config)
|
||||
XSRETURN_NO;
|
||||
}
|
||||
|
||||
option = SvPV (ST (0), integer);
|
||||
value = SvPV (ST (1), integer);
|
||||
option = SvPV (ST (0), PL_na);
|
||||
value = SvPV (ST (1), PL_na);
|
||||
|
||||
if (option && value)
|
||||
{
|
||||
@ -992,7 +1012,6 @@ static XS (XS_weechat_set_config)
|
||||
static XS (XS_weechat_get_plugin_config)
|
||||
{
|
||||
char *option, *return_value;
|
||||
unsigned int integer;
|
||||
dXSARGS;
|
||||
|
||||
/* make gcc happy */
|
||||
@ -1003,7 +1022,7 @@ static XS (XS_weechat_get_plugin_config)
|
||||
perl_plugin->print_server (perl_plugin,
|
||||
"Perl error: unable to get plugin config option, "
|
||||
"script not initialized");
|
||||
XSRETURN_NO;
|
||||
XSRETURN_EMPTY;
|
||||
}
|
||||
|
||||
if (items < 1)
|
||||
@ -1011,10 +1030,10 @@ static XS (XS_weechat_get_plugin_config)
|
||||
perl_plugin->print_server (perl_plugin,
|
||||
"Perl error: wrong parameters for "
|
||||
"\"get_plugin_config\" function");
|
||||
XSRETURN_NO;
|
||||
XSRETURN_EMPTY;
|
||||
}
|
||||
|
||||
option = SvPV (ST (0), integer);
|
||||
option = SvPV (ST (0), PL_na);
|
||||
|
||||
if (option)
|
||||
{
|
||||
@ -1041,7 +1060,6 @@ static XS (XS_weechat_get_plugin_config)
|
||||
static XS (XS_weechat_set_plugin_config)
|
||||
{
|
||||
char *option, *value;
|
||||
unsigned int integer;
|
||||
dXSARGS;
|
||||
|
||||
/* make gcc happy */
|
||||
@ -1063,8 +1081,8 @@ static XS (XS_weechat_set_plugin_config)
|
||||
XSRETURN_NO;
|
||||
}
|
||||
|
||||
option = SvPV (ST (0), integer);
|
||||
value = SvPV (ST (1), integer);
|
||||
option = SvPV (ST (0), PL_na);
|
||||
value = SvPV (ST (1), PL_na);
|
||||
|
||||
if (option && value)
|
||||
{
|
||||
@ -1152,7 +1170,6 @@ static XS (XS_weechat_get_server_info)
|
||||
}
|
||||
perl_plugin->free_server_info (perl_plugin, server_info);
|
||||
|
||||
//XPUSHs(newRV_inc((SV *) server_hash));
|
||||
ST (0) = newRV_inc((SV *) server_hash);
|
||||
XSRETURN (1);
|
||||
}
|
||||
@ -1165,7 +1182,6 @@ static XS (XS_weechat_get_channel_info)
|
||||
{
|
||||
t_plugin_channel_info *channel_info, *ptr_channel;
|
||||
char *server;
|
||||
unsigned int integer;
|
||||
HV *channel_hash, *channel_hash_member;
|
||||
dXSARGS;
|
||||
|
||||
@ -1188,7 +1204,7 @@ static XS (XS_weechat_get_channel_info)
|
||||
XSRETURN_EMPTY;
|
||||
}
|
||||
|
||||
server = SvPV (ST (0), integer);
|
||||
server = SvPV (ST (0), PL_na);
|
||||
if (!server)
|
||||
XSRETURN_EMPTY;
|
||||
|
||||
@ -1220,7 +1236,6 @@ static XS (XS_weechat_get_channel_info)
|
||||
}
|
||||
perl_plugin->free_channel_info (perl_plugin, channel_info);
|
||||
|
||||
//XPUSHs(newRV_inc((SV *) channel_hash));
|
||||
ST (0) = newRV_inc((SV *) channel_hash);
|
||||
XSRETURN (1);
|
||||
}
|
||||
@ -1233,7 +1248,6 @@ static XS (XS_weechat_get_nick_info)
|
||||
{
|
||||
t_plugin_nick_info *nick_info, *ptr_nick;
|
||||
char *server, *channel;
|
||||
unsigned int integer;
|
||||
HV *nick_hash;
|
||||
dXSARGS;
|
||||
|
||||
@ -1256,8 +1270,8 @@ static XS (XS_weechat_get_nick_info)
|
||||
XSRETURN_EMPTY;
|
||||
}
|
||||
|
||||
server = SvPV (ST (0), integer);
|
||||
channel = SvPV (ST (1), integer);
|
||||
server = SvPV (ST (0), PL_na);
|
||||
channel = SvPV (ST (1), PL_na);
|
||||
if (!server || !channel)
|
||||
XSRETURN_EMPTY;
|
||||
|
||||
@ -1286,7 +1300,6 @@ static XS (XS_weechat_get_nick_info)
|
||||
}
|
||||
perl_plugin->free_nick_info (perl_plugin, nick_info);
|
||||
|
||||
//XPUSHs(newRV_inc((SV *) nick_hash));
|
||||
ST (0) = newRV_inc((SV *) nick_hash);
|
||||
XSRETURN (1);
|
||||
}
|
||||
@ -1336,7 +1349,6 @@ static XS (XS_weechat_input_color)
|
||||
static XS (XS_weechat_get_irc_color)
|
||||
{
|
||||
char *color;
|
||||
unsigned int integer;
|
||||
dXSARGS;
|
||||
|
||||
/* make gcc happy */
|
||||
@ -1360,7 +1372,7 @@ static XS (XS_weechat_get_irc_color)
|
||||
XSRETURN (1);
|
||||
}
|
||||
|
||||
color = SvPV (ST (0), integer);
|
||||
color = SvPV (ST (0), PL_na);
|
||||
if (color)
|
||||
{
|
||||
XST_mIV (0, perl_plugin->get_irc_color (perl_plugin, color));
|
||||
@ -1371,6 +1383,176 @@ static XS (XS_weechat_get_irc_color)
|
||||
XSRETURN (-1);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat::get_window_info: get infos about windows
|
||||
*/
|
||||
|
||||
static XS (XS_weechat_get_window_info)
|
||||
{
|
||||
t_plugin_window_info *window_info, *ptr_window;
|
||||
int count;
|
||||
HV *window_hash_member;
|
||||
dXSARGS;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) cv;
|
||||
(void) items;
|
||||
|
||||
if (!perl_current_script)
|
||||
{
|
||||
perl_plugin->print_server (perl_plugin,
|
||||
"Perl error: unable to get window info, "
|
||||
"script not initialized");
|
||||
XSRETURN_EMPTY;
|
||||
}
|
||||
|
||||
window_info = perl_plugin->get_window_info (perl_plugin);
|
||||
count = 0;
|
||||
if (!window_info)
|
||||
XSRETURN_EMPTY;
|
||||
|
||||
for (ptr_window = window_info; ptr_window; ptr_window = ptr_window->next_window)
|
||||
{
|
||||
window_hash_member = (HV *) sv_2mortal((SV *) newHV());
|
||||
|
||||
hv_store (window_hash_member, "num_buffer", 10, newSViv (ptr_window->num_buffer), 0);
|
||||
hv_store (window_hash_member, "win_x", 5, newSViv (ptr_window->win_x), 0);
|
||||
hv_store (window_hash_member, "win_y", 5, newSViv (ptr_window->win_y), 0);
|
||||
hv_store (window_hash_member, "win_width", 9, newSViv (ptr_window->win_width), 0);
|
||||
hv_store (window_hash_member, "win_height", 10, newSViv (ptr_window->win_height), 0);
|
||||
hv_store (window_hash_member, "win_width_pct", 13, newSViv (ptr_window->win_width_pct), 0);
|
||||
hv_store (window_hash_member, "win_height_pct", 14, newSViv (ptr_window->win_height_pct), 0);
|
||||
|
||||
XPUSHs(newRV_inc((SV *) window_hash_member));
|
||||
count++;
|
||||
}
|
||||
perl_plugin->free_window_info (perl_plugin, window_info);
|
||||
|
||||
XSRETURN (count);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat::get_buffer_info: get infos about buffers
|
||||
*/
|
||||
|
||||
static XS (XS_weechat_get_buffer_info)
|
||||
{
|
||||
t_plugin_buffer_info *buffer_info, *ptr_buffer;
|
||||
HV *buffer_hash, *buffer_hash_member;
|
||||
char conv[8];
|
||||
dXSARGS;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) cv;
|
||||
(void) items;
|
||||
|
||||
if (!perl_current_script)
|
||||
{
|
||||
perl_plugin->print_server (perl_plugin,
|
||||
"Perl error: unable to get buffer info, "
|
||||
"script not initialized");
|
||||
XSRETURN_EMPTY;
|
||||
}
|
||||
|
||||
buffer_info = perl_plugin->get_buffer_info (perl_plugin);
|
||||
if (!buffer_info)
|
||||
{
|
||||
XSRETURN_EMPTY;
|
||||
}
|
||||
|
||||
buffer_hash = (HV *) sv_2mortal((SV *) newHV());
|
||||
if (!buffer_hash)
|
||||
{
|
||||
perl_plugin->free_buffer_info (perl_plugin, buffer_info);
|
||||
XSRETURN_EMPTY;
|
||||
}
|
||||
|
||||
for (ptr_buffer = buffer_info; ptr_buffer; ptr_buffer = ptr_buffer->next_buffer)
|
||||
{
|
||||
buffer_hash_member = (HV *) sv_2mortal((SV *) newHV());
|
||||
|
||||
hv_store (buffer_hash_member, "type", 4, newSViv (ptr_buffer->type), 0);
|
||||
hv_store (buffer_hash_member, "num_displayed", 13, newSViv (ptr_buffer->num_displayed), 0);
|
||||
hv_store (buffer_hash_member, "server", 6,
|
||||
newSVpv (ptr_buffer->server_name == NULL ? "" : ptr_buffer->server_name, 0), 0);
|
||||
hv_store (buffer_hash_member, "channel", 7,
|
||||
newSVpv (ptr_buffer->channel_name == NULL ? "" : ptr_buffer->channel_name, 0), 0);
|
||||
hv_store (buffer_hash_member, "notify_level", 12, newSViv (ptr_buffer->notify_level), 0);
|
||||
hv_store (buffer_hash_member, "log_filename", 12,
|
||||
newSVpv (ptr_buffer->log_filename == NULL ? "" : ptr_buffer->log_filename, 0), 0);
|
||||
|
||||
snprintf(conv, sizeof(conv), "%d", ptr_buffer->number);
|
||||
hv_store (buffer_hash, conv, strlen(conv), newRV_inc((SV *) buffer_hash_member), 0);
|
||||
}
|
||||
perl_plugin->free_buffer_info (perl_plugin, buffer_info);
|
||||
|
||||
ST (0) = newRV_inc((SV *) buffer_hash);
|
||||
XSRETURN (1);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat::get_buffer_data: get buffer content
|
||||
*/
|
||||
|
||||
static XS (XS_weechat_get_buffer_data)
|
||||
{
|
||||
t_plugin_buffer_line *buffer_data, *ptr_data;
|
||||
HV *data_list_member;
|
||||
char *server, *channel;
|
||||
int count;
|
||||
|
||||
dXSARGS;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) cv;
|
||||
(void) items;
|
||||
|
||||
if (!perl_current_script)
|
||||
{
|
||||
perl_plugin->print_server (perl_plugin,
|
||||
"Perl error: unable to get buffer data, "
|
||||
"script not initialized");
|
||||
XSRETURN_EMPTY;
|
||||
}
|
||||
|
||||
if (items > 2)
|
||||
{
|
||||
perl_plugin->print_server (perl_plugin,
|
||||
"Perl error: wrong parameters for "
|
||||
"\"get_buffer_data\" function");
|
||||
XSRETURN_EMPTY;
|
||||
}
|
||||
|
||||
channel = NULL;
|
||||
server = NULL;
|
||||
|
||||
if (items >= 1)
|
||||
server = SvPV (ST (0), PL_na);
|
||||
if (items >= 2)
|
||||
channel = SvPV (ST (1), PL_na);
|
||||
|
||||
buffer_data = perl_plugin->get_buffer_data (perl_plugin, server, channel);
|
||||
count = 0;
|
||||
if (!buffer_data)
|
||||
XSRETURN_EMPTY;
|
||||
|
||||
for (ptr_data = buffer_data; ptr_data; ptr_data = ptr_data->next_line)
|
||||
{
|
||||
data_list_member = (HV *) sv_2mortal((SV *) newHV());
|
||||
|
||||
hv_store (data_list_member, "nick", 4,
|
||||
newSVpv (ptr_data->nick == NULL ? "" : ptr_data->nick, 0), 0);
|
||||
hv_store (data_list_member, "data", 4,
|
||||
newSVpv (ptr_data->data == NULL ? "" : ptr_data->data, 0), 0);
|
||||
|
||||
XPUSHs(newRV_inc((SV *) data_list_member));
|
||||
count++;
|
||||
}
|
||||
perl_plugin->free_buffer_data (perl_plugin, buffer_data);
|
||||
|
||||
XSRETURN (count);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_perl_xs_init: initialize subroutines
|
||||
*/
|
||||
@ -1385,6 +1567,7 @@ weechat_perl_xs_init (pTHX)
|
||||
/* interface functions */
|
||||
newXS ("weechat::register", XS_weechat_register, "weechat");
|
||||
newXS ("weechat::print", XS_weechat_print, "weechat");
|
||||
newXS ("weechat::print_server", XS_weechat_print_server, "weechat");
|
||||
newXS ("weechat::print_infobar", XS_weechat_print_infobar, "weechat");
|
||||
newXS ("weechat::remove_infobar", XS_weechat_remove_infobar, "weechat");
|
||||
newXS ("weechat::log", XS_weechat_log, "weechat");
|
||||
@ -1407,6 +1590,9 @@ weechat_perl_xs_init (pTHX)
|
||||
newXS ("weechat::get_nick_info", XS_weechat_get_nick_info, "weechat");
|
||||
newXS ("weechat::input_color", XS_weechat_input_color, "weechat");
|
||||
newXS ("weechat::get_irc_color", XS_weechat_get_irc_color, "weechat");
|
||||
newXS ("weechat::get_window_info", XS_weechat_get_window_info, "weechat");
|
||||
newXS ("weechat::get_buffer_info", XS_weechat_get_buffer_info, "weechat");
|
||||
newXS ("weechat::get_buffer_data", XS_weechat_get_buffer_data, "weechat");
|
||||
|
||||
/* interface constants */
|
||||
stash = gv_stashpv ("weechat", TRUE);
|
||||
|
@ -267,6 +267,41 @@ weechat_python_print (PyObject *self, PyObject *args)
|
||||
return Py_BuildValue ("i", 1);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_python_print_server: print message into a buffer server
|
||||
*/
|
||||
|
||||
static PyObject *
|
||||
weechat_python_print_server (PyObject *self, PyObject *args)
|
||||
{
|
||||
char *message;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) self;
|
||||
|
||||
if (!python_current_script)
|
||||
{
|
||||
python_plugin->print_server (python_plugin,
|
||||
"Python error: unable to print message (server), "
|
||||
"script not initialized");
|
||||
return Py_BuildValue ("i", 0);
|
||||
}
|
||||
|
||||
message = NULL;
|
||||
|
||||
if (!PyArg_ParseTuple (args, "s", &message))
|
||||
{
|
||||
python_plugin->print_server (python_plugin,
|
||||
"Python error: wrong parameters for "
|
||||
"\"print_server\" function");
|
||||
return Py_BuildValue ("i", 0);
|
||||
}
|
||||
|
||||
python_plugin->print_server (python_plugin, "%s", message);
|
||||
|
||||
return Py_BuildValue ("i", 1);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_python_print_infobar: print message to infobar
|
||||
*/
|
||||
@ -822,22 +857,9 @@ weechat_python_get_dcc_info (PyObject *self, PyObject *args)
|
||||
PyDict_SetItem(dcc_list_member, Py_BuildValue("s", "start_resume"),
|
||||
Py_BuildValue("k", ptr_dcc->start_resume));
|
||||
PyDict_SetItem(dcc_list_member, Py_BuildValue("s", "cps"),
|
||||
Py_BuildValue("k", ptr_dcc->bytes_per_sec));
|
||||
Py_BuildValue("k", ptr_dcc->bytes_per_sec));
|
||||
|
||||
|
||||
if (PyList_Append(dcc_list, dcc_list_member) != 0)
|
||||
{
|
||||
Py_DECREF(dcc_list_member);
|
||||
Py_DECREF(dcc_list);
|
||||
python_plugin->free_dcc_info (python_plugin, dcc_info);
|
||||
return Py_None;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Py_DECREF(dcc_list);
|
||||
python_plugin->free_dcc_info (python_plugin, dcc_info);
|
||||
return Py_None;
|
||||
PyList_Append(dcc_list, dcc_list_member);
|
||||
}
|
||||
}
|
||||
|
||||
@ -864,7 +886,7 @@ weechat_python_get_config (PyObject *self, PyObject *args)
|
||||
python_plugin->print_server (python_plugin,
|
||||
"Python error: unable to get config option, "
|
||||
"script not initialized");
|
||||
return Py_BuildValue ("i", 0);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
option = NULL;
|
||||
@ -874,7 +896,7 @@ weechat_python_get_config (PyObject *self, PyObject *args)
|
||||
python_plugin->print_server (python_plugin,
|
||||
"Python error: wrong parameters for "
|
||||
"\"get_config\" function");
|
||||
return Py_BuildValue ("i", 0);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
if (option)
|
||||
@ -950,7 +972,7 @@ weechat_python_get_plugin_config (PyObject *self, PyObject *args)
|
||||
python_plugin->print_server (python_plugin,
|
||||
"Python error: unable to get plugin config option, "
|
||||
"script not initialized");
|
||||
return Py_BuildValue ("i", 0);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
option = NULL;
|
||||
@ -960,7 +982,7 @@ weechat_python_get_plugin_config (PyObject *self, PyObject *args)
|
||||
python_plugin->print_server (python_plugin,
|
||||
"Python error: wrong parameters for "
|
||||
"\"get_plugin_config\" function");
|
||||
return Py_BuildValue ("i", 0);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
if (option)
|
||||
@ -1042,7 +1064,7 @@ weechat_python_get_server_info (PyObject *self, PyObject *args)
|
||||
python_plugin->print_server (python_plugin,
|
||||
"Python error: unable to get server infos, "
|
||||
"script not initialized");
|
||||
return Py_BuildValue ("i", 0);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
server_hash = PyDict_New ();
|
||||
@ -1145,7 +1167,7 @@ weechat_python_get_channel_info (PyObject *self, PyObject *args)
|
||||
python_plugin->print_server (python_plugin,
|
||||
"Python error: unable to get channel infos, "
|
||||
"script not initialized");
|
||||
return Py_BuildValue ("i", 0);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
server = NULL;
|
||||
@ -1154,7 +1176,7 @@ weechat_python_get_channel_info (PyObject *self, PyObject *args)
|
||||
python_plugin->print_server (python_plugin,
|
||||
"Python error: wrong parameters for "
|
||||
"\"get_channel_info\" function");
|
||||
return Py_BuildValue ("i", 0);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
channel_hash = PyDict_New ();
|
||||
@ -1212,7 +1234,7 @@ weechat_python_get_nick_info (PyObject *self, PyObject *args)
|
||||
python_plugin->print_server (python_plugin,
|
||||
"Python error: unable to get nick infos, "
|
||||
"script not initialized");
|
||||
return Py_BuildValue ("i", 0);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
server = NULL;
|
||||
@ -1222,7 +1244,7 @@ weechat_python_get_nick_info (PyObject *self, PyObject *args)
|
||||
python_plugin->print_server (python_plugin,
|
||||
"Python error: wrong parameters for "
|
||||
"\"get_nick_info\" function");
|
||||
return Py_BuildValue ("i", 0);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
nick_hash = PyDict_New ();
|
||||
@ -1290,6 +1312,184 @@ weechat_python_get_irc_color (PyObject *self, PyObject *args)
|
||||
return Py_BuildValue ("i", -1);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_python_get_window_info: get infos about windows
|
||||
*/
|
||||
|
||||
static PyObject *
|
||||
weechat_python_get_window_info (PyObject *self, PyObject *args)
|
||||
{
|
||||
t_plugin_window_info *window_info, *ptr_window;
|
||||
PyObject *window_list, *window_list_member;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) self;
|
||||
(void) args;
|
||||
|
||||
if (!python_current_script)
|
||||
{
|
||||
python_plugin->print_server (python_plugin,
|
||||
"Python error: unable to get window info, "
|
||||
"script not initialized");
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
window_list = PyList_New (0);
|
||||
if (!window_list)
|
||||
return Py_None;
|
||||
|
||||
window_info = python_plugin->get_window_info (python_plugin);
|
||||
if (!window_info)
|
||||
return window_list;
|
||||
|
||||
for(ptr_window = window_info; ptr_window; ptr_window = ptr_window->next_window)
|
||||
{
|
||||
window_list_member = PyDict_New();
|
||||
|
||||
if (window_list_member)
|
||||
{
|
||||
PyDict_SetItem(window_list_member, Py_BuildValue("s", "num_buffer"),
|
||||
Py_BuildValue("i", ptr_window->num_buffer));
|
||||
PyDict_SetItem(window_list_member, Py_BuildValue("s", "win_x"),
|
||||
Py_BuildValue("i", ptr_window->win_x));
|
||||
PyDict_SetItem(window_list_member, Py_BuildValue("s", "win_y"),
|
||||
Py_BuildValue("i", ptr_window->win_y));
|
||||
PyDict_SetItem(window_list_member, Py_BuildValue("s", "win_width"),
|
||||
Py_BuildValue("i", ptr_window->win_width));
|
||||
PyDict_SetItem(window_list_member, Py_BuildValue("s", "win_height"),
|
||||
Py_BuildValue("i", ptr_window->win_height));
|
||||
PyDict_SetItem(window_list_member, Py_BuildValue("s", "win_width_pct"),
|
||||
Py_BuildValue("i", ptr_window->win_width_pct));
|
||||
PyDict_SetItem(window_list_member, Py_BuildValue("s", "win_height_pct"),
|
||||
Py_BuildValue("i", ptr_window->win_height_pct));
|
||||
|
||||
PyList_Append(window_list, window_list_member);
|
||||
}
|
||||
}
|
||||
|
||||
python_plugin->free_window_info(python_plugin, window_info);
|
||||
|
||||
return window_list;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_python_get_buffer_info: get infos about buffers
|
||||
*/
|
||||
|
||||
static PyObject *
|
||||
weechat_python_get_buffer_info (PyObject *self, PyObject *args)
|
||||
{
|
||||
t_plugin_buffer_info *buffer_info, *ptr_buffer;
|
||||
PyObject *buffer_hash, *buffer_hash_member;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) self;
|
||||
(void) args;
|
||||
|
||||
if (!python_current_script)
|
||||
{
|
||||
python_plugin->print_server (python_plugin,
|
||||
"Python error: unable to get buffer info, "
|
||||
"script not initialized");
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
buffer_hash = PyDict_New ();
|
||||
if (!buffer_hash)
|
||||
return Py_None;
|
||||
|
||||
buffer_info = python_plugin->get_buffer_info (python_plugin);
|
||||
if (!buffer_info)
|
||||
return buffer_hash;
|
||||
|
||||
for(ptr_buffer = buffer_info; ptr_buffer; ptr_buffer = ptr_buffer->next_buffer)
|
||||
{
|
||||
buffer_hash_member = PyDict_New();
|
||||
|
||||
if (buffer_hash_member)
|
||||
{
|
||||
PyDict_SetItem(buffer_hash_member, Py_BuildValue("s", "type"),
|
||||
Py_BuildValue("i", ptr_buffer->type));
|
||||
PyDict_SetItem(buffer_hash_member, Py_BuildValue("s", "num_displayed"),
|
||||
Py_BuildValue("i", ptr_buffer->num_displayed));
|
||||
PyDict_SetItem(buffer_hash_member, Py_BuildValue("s", "server"),
|
||||
Py_BuildValue("s", ptr_buffer->server_name == NULL ? "" : ptr_buffer->server_name));
|
||||
PyDict_SetItem(buffer_hash_member, Py_BuildValue("s", "channel"),
|
||||
Py_BuildValue("s", ptr_buffer->channel_name == NULL ? "" : ptr_buffer->channel_name));
|
||||
PyDict_SetItem(buffer_hash_member, Py_BuildValue("s", "notify_level"),
|
||||
Py_BuildValue("i", ptr_buffer->notify_level));
|
||||
PyDict_SetItem(buffer_hash_member, Py_BuildValue("s", "log_filename"),
|
||||
Py_BuildValue("s", ptr_buffer->log_filename == NULL ? "" : ptr_buffer->log_filename));
|
||||
|
||||
PyDict_SetItem(buffer_hash,
|
||||
Py_BuildValue("i", ptr_buffer->number), buffer_hash_member);
|
||||
}
|
||||
}
|
||||
|
||||
python_plugin->free_buffer_info(python_plugin, buffer_info);
|
||||
|
||||
return buffer_hash;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_python_get_buffer_data: get buffer content
|
||||
*/
|
||||
|
||||
static PyObject *
|
||||
weechat_python_get_buffer_data (PyObject *self, PyObject *args)
|
||||
{
|
||||
t_plugin_buffer_line *buffer_data, *ptr_data;
|
||||
PyObject *data_list, *data_list_member;
|
||||
char *server, *channel;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) self;
|
||||
(void) args;
|
||||
|
||||
if (!python_current_script)
|
||||
{
|
||||
python_plugin->print_server (python_plugin,
|
||||
"Python error: unable to get buffer data, "
|
||||
"script not initialized");
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
if (!PyArg_ParseTuple (args, "|ss", &server, &channel))
|
||||
{
|
||||
python_plugin->print_server (python_plugin,
|
||||
"Python error: wrong parameters for "
|
||||
"\"get_buffer_data\" function");
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
data_list = PyList_New (0);
|
||||
if (!data_list)
|
||||
return Py_None;
|
||||
|
||||
buffer_data = python_plugin->get_buffer_data (python_plugin, server, channel);
|
||||
if (!buffer_data)
|
||||
return data_list;
|
||||
|
||||
for(ptr_data = buffer_data; ptr_data; ptr_data = ptr_data->next_line)
|
||||
{
|
||||
data_list_member= PyDict_New();
|
||||
|
||||
if (data_list_member)
|
||||
{
|
||||
PyDict_SetItem(data_list_member, Py_BuildValue("s", "nick"),
|
||||
Py_BuildValue("s", ptr_data->nick == NULL ? "" : ptr_data->nick));
|
||||
PyDict_SetItem(data_list_member, Py_BuildValue("s", "data"),
|
||||
Py_BuildValue("s", ptr_data->data == NULL ? "" : ptr_data->data));
|
||||
|
||||
PyList_Append(data_list, data_list_member);
|
||||
}
|
||||
}
|
||||
|
||||
python_plugin->free_buffer_data (python_plugin, buffer_data);
|
||||
|
||||
return data_list;
|
||||
}
|
||||
|
||||
/*
|
||||
* Python subroutines
|
||||
*/
|
||||
@ -1298,6 +1498,7 @@ static
|
||||
PyMethodDef weechat_python_funcs[] = {
|
||||
{ "register", weechat_python_register, METH_VARARGS, "" },
|
||||
{ "prnt", weechat_python_print, METH_VARARGS, "" },
|
||||
{ "print_server", weechat_python_print_server, METH_VARARGS, "" },
|
||||
{ "print_infobar", weechat_python_print_infobar, METH_VARARGS, "" },
|
||||
{ "remove_infobar", weechat_python_remove_infobar, METH_VARARGS, "" },
|
||||
{ "log", weechat_python_log, METH_VARARGS, "" },
|
||||
@ -1319,6 +1520,9 @@ PyMethodDef weechat_python_funcs[] = {
|
||||
{ "get_channel_info", weechat_python_get_channel_info, METH_VARARGS, "" },
|
||||
{ "get_nick_info", weechat_python_get_nick_info, METH_VARARGS, "" },
|
||||
{ "get_irc_color", weechat_python_get_irc_color, METH_VARARGS, "" },
|
||||
{ "get_window_info", weechat_python_get_window_info, METH_VARARGS, "" },
|
||||
{ "get_buffer_info", weechat_python_get_buffer_info, METH_VARARGS, "" },
|
||||
{ "get_buffer_data", weechat_python_get_buffer_data, METH_VARARGS, "" },
|
||||
{ NULL, NULL, 0, NULL }
|
||||
};
|
||||
|
||||
|
@ -336,6 +336,44 @@ weechat_ruby_print (int argc, VALUE *argv, VALUE class)
|
||||
return INT2FIX (1);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_ruby_print_server: print message into a buffer server
|
||||
*/
|
||||
|
||||
static VALUE
|
||||
weechat_ruby_print_server (VALUE class, VALUE message)
|
||||
{
|
||||
char *c_message;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) class;
|
||||
|
||||
if (!ruby_current_script)
|
||||
{
|
||||
ruby_plugin->print_server (ruby_plugin,
|
||||
"Ruby error: unable to print message, "
|
||||
"script not initialized");
|
||||
return INT2FIX (0);
|
||||
}
|
||||
|
||||
c_message = NULL;
|
||||
|
||||
if (NIL_P (message))
|
||||
{
|
||||
ruby_plugin->print_server (ruby_plugin,
|
||||
"Ruby error: wrong parameters for "
|
||||
"\"print_server\" function");
|
||||
return INT2FIX (0);
|
||||
}
|
||||
|
||||
Check_Type (message, T_STRING);
|
||||
c_message = STR2CSTR (message);
|
||||
|
||||
ruby_plugin->print_server (ruby_plugin, "%s", c_message);
|
||||
|
||||
return INT2FIX (1);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_ruby_print_infobar: print message to infobar
|
||||
*/
|
||||
@ -1024,20 +1062,8 @@ weechat_ruby_get_dcc_info (VALUE class)
|
||||
rb_hash_aset (dcc_list_member, rb_str_new2("cps"),
|
||||
INT2FIX(ptr_dcc->bytes_per_sec));
|
||||
|
||||
if (NIL_P (rb_ary_push (dcc_list, dcc_list_member)))
|
||||
{
|
||||
rb_gc_unregister_address (&dcc_list_member);
|
||||
rb_gc_unregister_address (&dcc_list);
|
||||
ruby_plugin->free_dcc_info (ruby_plugin, dcc_info);
|
||||
return Qnil;
|
||||
}
|
||||
rb_ary_push (dcc_list, dcc_list_member);
|
||||
}
|
||||
else
|
||||
{
|
||||
rb_gc_unregister_address (&dcc_list);
|
||||
ruby_plugin->free_dcc_info (ruby_plugin, dcc_info);
|
||||
return Qnil;
|
||||
}
|
||||
}
|
||||
|
||||
ruby_plugin->free_dcc_info (ruby_plugin, dcc_info);
|
||||
@ -1522,6 +1548,193 @@ weechat_ruby_get_irc_color (VALUE class, VALUE color)
|
||||
return INT2FIX (ruby_plugin->get_irc_color (ruby_plugin, c_color));
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_ruby_get_window_info: get infos about windows
|
||||
*/
|
||||
|
||||
static VALUE
|
||||
weechat_ruby_get_window_info (VALUE class)
|
||||
{
|
||||
t_plugin_window_info *window_info, *ptr_window;
|
||||
VALUE window_list, window_list_member;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) class;
|
||||
|
||||
if (!ruby_current_script)
|
||||
{
|
||||
ruby_plugin->print_server (ruby_plugin,
|
||||
"Ruby error: unable to get window info, "
|
||||
"script not initialized");
|
||||
return INT2FIX (0);
|
||||
}
|
||||
|
||||
window_list = rb_ary_new();
|
||||
|
||||
if (NIL_P (window_list))
|
||||
return Qnil;
|
||||
|
||||
window_info = ruby_plugin->get_window_info (ruby_plugin);
|
||||
if (!window_info)
|
||||
return window_list;
|
||||
|
||||
for(ptr_window = window_info; ptr_window; ptr_window = ptr_window->next_window)
|
||||
{
|
||||
window_list_member = rb_hash_new ();
|
||||
|
||||
if (!NIL_P (window_list_member))
|
||||
{
|
||||
rb_hash_aset (window_list_member, rb_str_new2("num_buffer"),
|
||||
INT2FIX(ptr_window->num_buffer));
|
||||
rb_hash_aset (window_list_member, rb_str_new2("win_x"),
|
||||
INT2FIX(ptr_window->win_x));
|
||||
rb_hash_aset (window_list_member, rb_str_new2("win_y"),
|
||||
INT2FIX(ptr_window->win_y));
|
||||
rb_hash_aset (window_list_member, rb_str_new2("win_width"),
|
||||
INT2FIX(ptr_window->win_width));
|
||||
rb_hash_aset (window_list_member, rb_str_new2("win_height"),
|
||||
INT2FIX(ptr_window->win_height));
|
||||
rb_hash_aset (window_list_member, rb_str_new2("win_width_pct"),
|
||||
INT2FIX(ptr_window->win_width_pct));
|
||||
rb_hash_aset (window_list_member, rb_str_new2("win_height_pct"),
|
||||
INT2FIX(ptr_window->win_height_pct));
|
||||
|
||||
rb_ary_push (window_list, window_list_member);
|
||||
}
|
||||
}
|
||||
|
||||
ruby_plugin->free_window_info (ruby_plugin, window_info);
|
||||
|
||||
return window_list;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_ruby_get_buffer_info: get infos about buffers
|
||||
*/
|
||||
|
||||
static VALUE
|
||||
weechat_ruby_get_buffer_info (VALUE class)
|
||||
{
|
||||
t_plugin_buffer_info *buffer_info, *ptr_buffer;
|
||||
VALUE buffer_hash, buffer_hash_member;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) class;
|
||||
|
||||
if (!ruby_current_script)
|
||||
{
|
||||
ruby_plugin->print_server (ruby_plugin,
|
||||
"Ruby error: unable to get buffer info, "
|
||||
"script not initialized");
|
||||
return INT2FIX (0);
|
||||
}
|
||||
|
||||
buffer_hash = rb_hash_new ();
|
||||
if (!buffer_hash)
|
||||
return Qnil;
|
||||
|
||||
buffer_info = ruby_plugin->get_buffer_info (ruby_plugin);
|
||||
if (!buffer_info)
|
||||
return buffer_hash;
|
||||
|
||||
for(ptr_buffer = buffer_info; ptr_buffer; ptr_buffer = ptr_buffer->next_buffer)
|
||||
{
|
||||
buffer_hash_member = rb_hash_new ();
|
||||
|
||||
if (buffer_hash_member)
|
||||
{
|
||||
rb_hash_aset (buffer_hash_member, rb_str_new2("type"),
|
||||
INT2FIX(ptr_buffer->type));
|
||||
rb_hash_aset (buffer_hash_member, rb_str_new2("num_displayed"),
|
||||
INT2FIX(ptr_buffer->num_displayed));
|
||||
rb_hash_aset (buffer_hash_member, rb_str_new2("server"),
|
||||
rb_str_new2(ptr_buffer->server_name == NULL ? "" : ptr_buffer->server_name));
|
||||
rb_hash_aset (buffer_hash_member, rb_str_new2("channel"),
|
||||
rb_str_new2(ptr_buffer->channel_name == NULL ? "" : ptr_buffer->channel_name));
|
||||
rb_hash_aset (buffer_hash_member, rb_str_new2("notify_level"),
|
||||
INT2FIX(ptr_buffer->notify_level));
|
||||
rb_hash_aset (buffer_hash_member, rb_str_new2("log_filename"),
|
||||
rb_str_new2(ptr_buffer->log_filename == NULL ? "" : ptr_buffer->log_filename));
|
||||
|
||||
rb_hash_aset (buffer_hash, INT2FIX(ptr_buffer->number), buffer_hash_member);
|
||||
}
|
||||
}
|
||||
|
||||
ruby_plugin->free_buffer_info(ruby_plugin, buffer_info);
|
||||
|
||||
return buffer_hash;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_ruby_get_buffer_data: get buffer content
|
||||
*/
|
||||
|
||||
static VALUE
|
||||
weechat_ruby_get_buffer_data (int argc, VALUE *argv, VALUE class)
|
||||
{
|
||||
t_plugin_buffer_line *buffer_data, *ptr_data;
|
||||
VALUE data_list, data_list_member;
|
||||
VALUE server, channel;
|
||||
char *c_server, *c_channel;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) class;
|
||||
|
||||
if (!ruby_current_script)
|
||||
{
|
||||
ruby_plugin->print_server (ruby_plugin,
|
||||
"Ruby error: unable to get buffer data, "
|
||||
"script not initialized");
|
||||
return INT2FIX (0);
|
||||
}
|
||||
|
||||
server = Qnil;
|
||||
channel = Qnil;
|
||||
c_server = NULL;
|
||||
c_channel = NULL;
|
||||
|
||||
rb_scan_args (argc, argv, "02", &server, &channel);
|
||||
|
||||
if (!NIL_P (server))
|
||||
{
|
||||
Check_Type (server, T_STRING);
|
||||
c_server = STR2CSTR (server);
|
||||
}
|
||||
|
||||
if (!NIL_P (channel))
|
||||
{
|
||||
Check_Type (channel, T_STRING);
|
||||
c_channel = STR2CSTR (channel);
|
||||
}
|
||||
|
||||
data_list = rb_ary_new();
|
||||
if (NIL_P (data_list))
|
||||
return Qnil;
|
||||
|
||||
buffer_data = ruby_plugin->get_buffer_data (ruby_plugin, c_server, c_channel);
|
||||
if (!buffer_data)
|
||||
return data_list;
|
||||
|
||||
for(ptr_data = buffer_data; ptr_data; ptr_data = ptr_data->next_line)
|
||||
{
|
||||
data_list_member = rb_hash_new ();
|
||||
|
||||
if (!NIL_P (data_list_member))
|
||||
{
|
||||
rb_hash_aset (data_list_member, rb_str_new2("nick"),
|
||||
rb_str_new2(ptr_data->nick == NULL ? "" : ptr_data->nick));
|
||||
rb_hash_aset (data_list_member, rb_str_new2("data"),
|
||||
rb_str_new2(ptr_data->data == NULL ? "" : ptr_data->data));
|
||||
|
||||
rb_ary_push (data_list, data_list_member);
|
||||
}
|
||||
}
|
||||
|
||||
ruby_plugin->free_buffer_data (ruby_plugin, buffer_data);
|
||||
|
||||
return data_list;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_ruby_output : redirection for stdout and stderr
|
||||
*/
|
||||
@ -1964,6 +2177,7 @@ weechat_plugin_init (t_weechat_plugin *plugin)
|
||||
rb_define_const(ruby_mWeechat, "PLUGIN_RC_OK_IGNORE_ALL", INT2NUM(PLUGIN_RC_OK_IGNORE_ALL));
|
||||
rb_define_module_function (ruby_mWeechat, "register", weechat_ruby_register, 4);
|
||||
rb_define_module_function (ruby_mWeechat, "print", weechat_ruby_print, -1);
|
||||
rb_define_module_function (ruby_mWeechat, "print_server", weechat_ruby_print_server, 1);
|
||||
rb_define_module_function (ruby_mWeechat, "print_infobar", weechat_ruby_print_infobar, 2);
|
||||
rb_define_module_function (ruby_mWeechat, "remove_infobar", weechat_ruby_remove_infobar, -1);
|
||||
rb_define_module_function (ruby_mWeechat, "log", weechat_ruby_log, -1);
|
||||
@ -1985,7 +2199,10 @@ weechat_plugin_init (t_weechat_plugin *plugin)
|
||||
rb_define_module_function (ruby_mWeechat, "get_channel_info", weechat_ruby_get_channel_info, 1);
|
||||
rb_define_module_function (ruby_mWeechat, "get_nick_info", weechat_ruby_get_nick_info, 2);
|
||||
rb_define_module_function (ruby_mWeechat, "get_irc_color", weechat_ruby_get_irc_color, 1);
|
||||
|
||||
rb_define_module_function (ruby_mWeechat, "get_window_info", weechat_ruby_get_window_info, 0);
|
||||
rb_define_module_function (ruby_mWeechat, "get_buffer_info", weechat_ruby_get_buffer_info, 0);
|
||||
rb_define_module_function (ruby_mWeechat, "get_buffer_data", weechat_ruby_get_buffer_data, -1);
|
||||
|
||||
/* redirect stdin and stdout */
|
||||
ruby_mWeechatOutputs = rb_define_module("WeechatOutputs");
|
||||
rb_define_singleton_method(ruby_mWeechatOutputs, "write", weechat_ruby_output, 1);
|
||||
|
@ -241,24 +241,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,
|
||||
@ -270,6 +270,49 @@ weechat_lua_print (lua_State *L)
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_lua_print_server: print message into a buffer server
|
||||
*/
|
||||
|
||||
static int
|
||||
weechat_lua_print_server (lua_State *L)
|
||||
{
|
||||
const char *message;
|
||||
int n;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) L;
|
||||
|
||||
if (!lua_current_script)
|
||||
{
|
||||
lua_plugin->print_server (lua_plugin,
|
||||
"Lua error: unable to print message, "
|
||||
"script not initialized");
|
||||
lua_pushnumber (lua_current_interpreter, 0);
|
||||
return 1;
|
||||
}
|
||||
|
||||
message = NULL;
|
||||
|
||||
n = lua_gettop (lua_current_interpreter);
|
||||
|
||||
if (n == 1)
|
||||
message = lua_tostring (lua_current_interpreter, -1);
|
||||
else
|
||||
{
|
||||
lua_plugin->print_server (lua_plugin,
|
||||
"Lua error: wrong parameters for "
|
||||
"\"print_server\" function");
|
||||
lua_pushnumber (lua_current_interpreter, 0);
|
||||
return 1;
|
||||
}
|
||||
|
||||
lua_plugin->print_server (lua_plugin, "%s", (char *) message);
|
||||
|
||||
lua_pushnumber (lua_current_interpreter, 1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_lua_print_infobar: print message to infobar
|
||||
*/
|
||||
@ -350,7 +393,7 @@ weechat_lua_remove_infobar (lua_State *L)
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_lua_print: log message in server/channel (current or specified ones)
|
||||
* weechat_lua_log: log message in server/channel (current or specified ones)
|
||||
*/
|
||||
|
||||
static int
|
||||
@ -1543,6 +1586,226 @@ weechat_lua_get_irc_color (lua_State *L)
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_lua_get_window_info: get infos about windows
|
||||
*/
|
||||
|
||||
static int
|
||||
weechat_lua_get_window_info (lua_State *L)
|
||||
{
|
||||
t_plugin_window_info *window_info, *ptr_window;
|
||||
int i;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) L;
|
||||
|
||||
if (!lua_current_script)
|
||||
{
|
||||
lua_plugin->print_server (lua_plugin,
|
||||
"Lua error: unable to get window info, "
|
||||
"script not initialized");
|
||||
lua_pushnil (lua_current_interpreter);
|
||||
return 1;
|
||||
}
|
||||
|
||||
window_info = lua_plugin->get_window_info (lua_plugin);
|
||||
if (!window_info)
|
||||
{
|
||||
lua_pushboolean (lua_current_interpreter, 0);
|
||||
return 1;
|
||||
}
|
||||
|
||||
lua_newtable (lua_current_interpreter);
|
||||
|
||||
for (i = 0, ptr_window = window_info; ptr_window; ptr_window = ptr_window->next_window, i++)
|
||||
{
|
||||
lua_pushnumber (lua_current_interpreter, i);
|
||||
lua_newtable (lua_current_interpreter);
|
||||
|
||||
lua_pushstring (lua_current_interpreter, "num_buffer");
|
||||
lua_pushnumber (lua_current_interpreter, ptr_window->num_buffer);
|
||||
lua_rawset (lua_current_interpreter, -3);
|
||||
|
||||
lua_pushstring (lua_current_interpreter, "win_x");
|
||||
lua_pushnumber (lua_current_interpreter, ptr_window->win_x);
|
||||
lua_rawset (lua_current_interpreter, -3);
|
||||
|
||||
lua_pushstring (lua_current_interpreter, "win_y");
|
||||
lua_pushnumber (lua_current_interpreter, ptr_window->win_y);
|
||||
lua_rawset (lua_current_interpreter, -3);
|
||||
|
||||
lua_pushstring (lua_current_interpreter, "win_width");
|
||||
lua_pushnumber (lua_current_interpreter, ptr_window->win_width);
|
||||
lua_rawset (lua_current_interpreter, -3);
|
||||
|
||||
lua_pushstring (lua_current_interpreter, "win_height");
|
||||
lua_pushnumber (lua_current_interpreter, ptr_window->win_height);
|
||||
lua_rawset (lua_current_interpreter, -3);
|
||||
|
||||
lua_pushstring (lua_current_interpreter, "win_width_pct");
|
||||
lua_pushnumber (lua_current_interpreter, ptr_window->win_width_pct);
|
||||
lua_rawset (lua_current_interpreter, -3);
|
||||
|
||||
lua_pushstring (lua_current_interpreter, "win_height_pct");
|
||||
lua_pushnumber (lua_current_interpreter, ptr_window->win_height_pct);
|
||||
lua_rawset (lua_current_interpreter, -3);
|
||||
|
||||
lua_rawset (lua_current_interpreter, -3);
|
||||
}
|
||||
|
||||
lua_plugin->free_window_info (lua_plugin, window_info);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_lua_get_buffer_info: get infos about buffers
|
||||
*/
|
||||
|
||||
static int
|
||||
weechat_lua_get_buffer_info (lua_State *L)
|
||||
{
|
||||
t_plugin_buffer_info *buffer_info, *ptr_buffer;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) L;
|
||||
|
||||
if (!lua_current_script)
|
||||
{
|
||||
lua_plugin->print_server (lua_plugin,
|
||||
"Lua error: unable to get buffer info, "
|
||||
"script not initialized");
|
||||
lua_pushnil (lua_current_interpreter);
|
||||
return 1;
|
||||
}
|
||||
|
||||
buffer_info = lua_plugin->get_buffer_info (lua_plugin);
|
||||
if (!buffer_info) {
|
||||
lua_pushboolean (lua_current_interpreter, 0);
|
||||
return 1;
|
||||
}
|
||||
|
||||
lua_newtable (lua_current_interpreter);
|
||||
|
||||
for (ptr_buffer = buffer_info; ptr_buffer; ptr_buffer = ptr_buffer->next_buffer)
|
||||
{
|
||||
lua_pushnumber (lua_current_interpreter, ptr_buffer->number);
|
||||
lua_newtable (lua_current_interpreter);
|
||||
|
||||
lua_pushstring (lua_current_interpreter, "type");
|
||||
lua_pushnumber (lua_current_interpreter, ptr_buffer->type);
|
||||
lua_rawset (lua_current_interpreter, -3);
|
||||
|
||||
lua_pushstring (lua_current_interpreter, "num_displayed");
|
||||
lua_pushnumber (lua_current_interpreter, ptr_buffer->num_displayed);
|
||||
lua_rawset (lua_current_interpreter, -3);
|
||||
|
||||
lua_pushstring (lua_current_interpreter, "server");
|
||||
lua_pushstring (lua_current_interpreter,
|
||||
ptr_buffer->server_name == NULL ? "" : ptr_buffer->server_name);
|
||||
lua_rawset (lua_current_interpreter, -3);
|
||||
|
||||
lua_pushstring (lua_current_interpreter, "channel");
|
||||
lua_pushstring (lua_current_interpreter,
|
||||
ptr_buffer->channel_name == NULL ? "" : ptr_buffer->channel_name);
|
||||
lua_rawset (lua_current_interpreter, -3);
|
||||
|
||||
lua_pushstring (lua_current_interpreter, "notify_level");
|
||||
lua_pushnumber (lua_current_interpreter, ptr_buffer->notify_level);
|
||||
lua_rawset (lua_current_interpreter, -3);
|
||||
|
||||
lua_pushstring (lua_current_interpreter, "log_filename");
|
||||
lua_pushstring (lua_current_interpreter,
|
||||
ptr_buffer->log_filename == NULL ? "" : ptr_buffer->log_filename);
|
||||
lua_rawset (lua_current_interpreter, -3);
|
||||
|
||||
lua_rawset (lua_current_interpreter, -3);
|
||||
}
|
||||
|
||||
lua_plugin->free_buffer_info(lua_plugin, buffer_info);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_lua_get_buffer_data: get buffer content
|
||||
*/
|
||||
|
||||
static int
|
||||
weechat_lua_get_buffer_data (lua_State *L)
|
||||
{
|
||||
t_plugin_buffer_line *buffer_data, *ptr_data;
|
||||
const char *server, *channel;
|
||||
int i, n;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) L;
|
||||
|
||||
if (!lua_current_script)
|
||||
{
|
||||
lua_plugin->print_server (lua_plugin,
|
||||
"Lua error: unable to get buffer data, "
|
||||
"script not initialized");
|
||||
lua_pushnil (lua_current_interpreter);
|
||||
return 1;
|
||||
}
|
||||
|
||||
server = NULL;
|
||||
channel = NULL;
|
||||
|
||||
n = lua_gettop (lua_current_interpreter);
|
||||
|
||||
switch (n)
|
||||
{
|
||||
case 0:
|
||||
break;
|
||||
case 1:
|
||||
server = lua_tostring (lua_current_interpreter, -1);
|
||||
break;
|
||||
case 2:
|
||||
channel = lua_tostring (lua_current_interpreter, -2);
|
||||
server = lua_tostring (lua_current_interpreter, -1);
|
||||
break;
|
||||
default:
|
||||
lua_plugin->print_server (lua_plugin,
|
||||
"Lua error: wrong parameters for "
|
||||
"\"get_buffer_data\" function");
|
||||
lua_pushnumber (lua_current_interpreter, 0);
|
||||
return 1;
|
||||
}
|
||||
|
||||
buffer_data = lua_plugin->get_buffer_data (lua_plugin, (char *) server, (char *) channel);
|
||||
if (!buffer_data)
|
||||
{
|
||||
lua_pushboolean (lua_current_interpreter, 0);
|
||||
return 1;
|
||||
}
|
||||
|
||||
lua_newtable (lua_current_interpreter);
|
||||
|
||||
for (i = 0, ptr_data = buffer_data; ptr_data; ptr_data = ptr_data->next_line, i++)
|
||||
{
|
||||
lua_pushnumber (lua_current_interpreter, i);
|
||||
lua_newtable (lua_current_interpreter);
|
||||
|
||||
lua_pushstring (lua_current_interpreter, "nick");
|
||||
lua_pushstring (lua_current_interpreter,
|
||||
ptr_data->nick == NULL ? "" : ptr_data->nick);
|
||||
lua_rawset (lua_current_interpreter, -3);
|
||||
|
||||
lua_pushstring (lua_current_interpreter, "data");
|
||||
lua_pushstring (lua_current_interpreter,
|
||||
ptr_data->data == NULL ? "" : ptr_data->data);
|
||||
lua_rawset (lua_current_interpreter, -3);
|
||||
|
||||
lua_rawset (lua_current_interpreter, -3);
|
||||
}
|
||||
|
||||
lua_plugin->free_buffer_data (lua_plugin, buffer_data);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Lua constant as functions
|
||||
*/
|
||||
@ -1605,6 +1868,7 @@ static
|
||||
const struct luaL_reg weechat_lua_funcs[] = {
|
||||
{ "register", weechat_lua_register},
|
||||
{ "print", weechat_lua_print},
|
||||
{ "print_server", weechat_lua_print_server},
|
||||
{ "print_infobar", weechat_lua_print_infobar},
|
||||
{ "remove_infobar", weechat_lua_remove_infobar},
|
||||
{ "log", weechat_lua_log},
|
||||
@ -1626,6 +1890,9 @@ const struct luaL_reg weechat_lua_funcs[] = {
|
||||
{ "get_channel_info", weechat_lua_get_channel_info},
|
||||
{ "get_nick_info", weechat_lua_get_nick_info},
|
||||
{ "get_irc_color", weechat_lua_get_irc_color},
|
||||
{ "get_window_info", weechat_lua_get_window_info},
|
||||
{ "get_buffer_info", weechat_lua_get_buffer_info},
|
||||
{ "get_buffer_data", weechat_lua_get_buffer_data},
|
||||
/* define constants as function which returns values */
|
||||
{ "PLUGIN_RC_OK", weechat_lua_constant_plugin_rc_ok},
|
||||
{ "PLUGIN_RC_KO", weechat_lua_constant_plugin_rc_ko},
|
||||
|
@ -241,7 +241,6 @@ weechat_perl_keyboard_handler (t_weechat_plugin *plugin,
|
||||
static XS (XS_weechat_register)
|
||||
{
|
||||
char *name, *version, *shutdown_func, *description;
|
||||
unsigned int integer;
|
||||
dXSARGS;
|
||||
|
||||
/* make gcc happy */
|
||||
@ -258,10 +257,10 @@ static XS (XS_weechat_register)
|
||||
XSRETURN_NO;
|
||||
}
|
||||
|
||||
name = SvPV (ST (0), integer);
|
||||
version = SvPV (ST (1), integer);
|
||||
shutdown_func = SvPV (ST (2), integer);
|
||||
description = SvPV (ST (3), integer);
|
||||
name = SvPV (ST (0), PL_na);
|
||||
version = SvPV (ST (1), PL_na);
|
||||
shutdown_func = SvPV (ST (2), PL_na);
|
||||
description = SvPV (ST (3), PL_na);
|
||||
|
||||
if (weechat_script_search (perl_plugin, &perl_scripts, name))
|
||||
{
|
||||
@ -302,7 +301,6 @@ static XS (XS_weechat_register)
|
||||
|
||||
static XS (XS_weechat_print)
|
||||
{
|
||||
unsigned int integer;
|
||||
char *message, *channel_name, *server_name;
|
||||
dXSARGS;
|
||||
|
||||
@ -325,16 +323,16 @@ static XS (XS_weechat_print)
|
||||
XSRETURN_NO;
|
||||
}
|
||||
|
||||
message = SvPV (ST (0), integer);
|
||||
message = SvPV (ST (0), PL_na);
|
||||
|
||||
channel_name = NULL;
|
||||
server_name = NULL;
|
||||
|
||||
if (items > 1)
|
||||
{
|
||||
channel_name = SvPV (ST (1), integer);
|
||||
channel_name = SvPV (ST (1), PL_na);
|
||||
if (items > 2)
|
||||
server_name = SvPV (ST (2), integer);
|
||||
server_name = SvPV (ST (2), PL_na);
|
||||
}
|
||||
|
||||
perl_plugin->print (perl_plugin,
|
||||
@ -344,13 +342,47 @@ static XS (XS_weechat_print)
|
||||
XSRETURN_YES;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat::print_server: print message into a server buffer
|
||||
*/
|
||||
|
||||
static XS (XS_weechat_print_server)
|
||||
{
|
||||
char *message;
|
||||
dXSARGS;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) cv;
|
||||
|
||||
if (!perl_current_script)
|
||||
{
|
||||
perl_plugin->print_server (perl_plugin,
|
||||
"Perl error: unable to print message, "
|
||||
"script not initialized");
|
||||
XSRETURN_NO;
|
||||
}
|
||||
|
||||
if (items < 1)
|
||||
{
|
||||
perl_plugin->print_server (perl_plugin,
|
||||
"Perl error: wrong parameters for "
|
||||
"\"print_server\" function");
|
||||
XSRETURN_NO;
|
||||
}
|
||||
|
||||
message = SvPV (ST (0), PL_na);
|
||||
|
||||
perl_plugin->print_server (perl_plugin, "%s", message);
|
||||
|
||||
XSRETURN_YES;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat::print_infobar: print message to infobar
|
||||
*/
|
||||
|
||||
static XS (XS_weechat_print_infobar)
|
||||
{
|
||||
unsigned int integer;
|
||||
dXSARGS;
|
||||
|
||||
/* make gcc happy */
|
||||
@ -375,7 +407,7 @@ static XS (XS_weechat_print_infobar)
|
||||
perl_plugin->print_infobar (perl_plugin,
|
||||
SvIV (ST (0)),
|
||||
"%s",
|
||||
SvPV (ST (1), integer));
|
||||
SvPV (ST (1), PL_na));
|
||||
|
||||
XSRETURN_YES;
|
||||
}
|
||||
@ -411,7 +443,6 @@ static XS (XS_weechat_remove_infobar)
|
||||
|
||||
static XS (XS_weechat_log)
|
||||
{
|
||||
unsigned int integer;
|
||||
char *message, *channel_name, *server_name;
|
||||
dXSARGS;
|
||||
|
||||
@ -434,16 +465,16 @@ static XS (XS_weechat_log)
|
||||
XSRETURN_NO;
|
||||
}
|
||||
|
||||
message = SvPV (ST (0), integer);
|
||||
message = SvPV (ST (0), PL_na);
|
||||
|
||||
channel_name = NULL;
|
||||
server_name = NULL;
|
||||
|
||||
if (items > 1)
|
||||
{
|
||||
channel_name = SvPV (ST (1), integer);
|
||||
channel_name = SvPV (ST (1), PL_na);
|
||||
if (items > 2)
|
||||
server_name = SvPV (ST (2), integer);
|
||||
server_name = SvPV (ST (2), PL_na);
|
||||
}
|
||||
|
||||
perl_plugin->log (perl_plugin,
|
||||
@ -459,7 +490,6 @@ static XS (XS_weechat_log)
|
||||
|
||||
static XS (XS_weechat_command)
|
||||
{
|
||||
unsigned int integer;
|
||||
char *channel_name, *server_name;
|
||||
dXSARGS;
|
||||
|
||||
@ -487,14 +517,14 @@ static XS (XS_weechat_command)
|
||||
|
||||
if (items > 1)
|
||||
{
|
||||
channel_name = SvPV (ST (1), integer);
|
||||
channel_name = SvPV (ST (1), PL_na);
|
||||
if (items > 2)
|
||||
server_name = SvPV (ST (2), integer);
|
||||
server_name = SvPV (ST (2), PL_na);
|
||||
}
|
||||
|
||||
perl_plugin->exec_command (perl_plugin,
|
||||
server_name, channel_name,
|
||||
SvPV (ST (0), integer));
|
||||
SvPV (ST (0), PL_na));
|
||||
|
||||
XSRETURN_YES;
|
||||
}
|
||||
@ -506,7 +536,6 @@ static XS (XS_weechat_command)
|
||||
static XS (XS_weechat_add_message_handler)
|
||||
{
|
||||
char *irc_command, *function;
|
||||
unsigned int integer;
|
||||
dXSARGS;
|
||||
|
||||
/* make gcc happy */
|
||||
@ -528,8 +557,8 @@ static XS (XS_weechat_add_message_handler)
|
||||
XSRETURN_NO;
|
||||
}
|
||||
|
||||
irc_command = SvPV (ST (0), integer);
|
||||
function = SvPV (ST (1), integer);
|
||||
irc_command = SvPV (ST (0), PL_na);
|
||||
function = SvPV (ST (1), PL_na);
|
||||
|
||||
if (perl_plugin->msg_handler_add (perl_plugin, irc_command,
|
||||
weechat_perl_cmd_msg_handler, function,
|
||||
@ -547,7 +576,6 @@ static XS (XS_weechat_add_command_handler)
|
||||
{
|
||||
char *command, *function, *description, *arguments, *arguments_description;
|
||||
char *completion_template;
|
||||
unsigned int integer;
|
||||
dXSARGS;
|
||||
|
||||
/* make gcc happy */
|
||||
@ -569,12 +597,12 @@ static XS (XS_weechat_add_command_handler)
|
||||
XSRETURN_NO;
|
||||
}
|
||||
|
||||
command = SvPV (ST (0), integer);
|
||||
function = SvPV (ST (1), integer);
|
||||
description = (items >= 3) ? SvPV (ST (2), integer) : NULL;
|
||||
arguments = (items >= 4) ? SvPV (ST (3), integer) : NULL;
|
||||
arguments_description = (items >= 5) ? SvPV (ST (4), integer) : NULL;
|
||||
completion_template = (items >= 6) ? SvPV (ST (5), integer) : NULL;
|
||||
command = SvPV (ST (0), PL_na);
|
||||
function = SvPV (ST (1), PL_na);
|
||||
description = (items >= 3) ? SvPV (ST (2), PL_na) : NULL;
|
||||
arguments = (items >= 4) ? SvPV (ST (3), PL_na) : NULL;
|
||||
arguments_description = (items >= 5) ? SvPV (ST (4), PL_na) : NULL;
|
||||
completion_template = (items >= 6) ? SvPV (ST (5), PL_na) : NULL;
|
||||
|
||||
if (perl_plugin->cmd_handler_add (perl_plugin,
|
||||
command,
|
||||
@ -598,7 +626,6 @@ static XS (XS_weechat_add_timer_handler)
|
||||
{
|
||||
int interval;
|
||||
char *function;
|
||||
unsigned int integer;
|
||||
dXSARGS;
|
||||
|
||||
/* make gcc happy */
|
||||
@ -621,7 +648,7 @@ static XS (XS_weechat_add_timer_handler)
|
||||
}
|
||||
|
||||
interval = SvIV (ST (0));
|
||||
function = SvPV (ST (1), integer);
|
||||
function = SvPV (ST (1), PL_na);
|
||||
|
||||
if (perl_plugin->timer_handler_add (perl_plugin, interval,
|
||||
weechat_perl_timer_handler, function,
|
||||
@ -638,7 +665,6 @@ static XS (XS_weechat_add_timer_handler)
|
||||
static XS (XS_weechat_add_keyboard_handler)
|
||||
{
|
||||
char *function;
|
||||
unsigned int integer;
|
||||
dXSARGS;
|
||||
|
||||
/* make gcc happy */
|
||||
@ -660,7 +686,7 @@ static XS (XS_weechat_add_keyboard_handler)
|
||||
XSRETURN_NO;
|
||||
}
|
||||
|
||||
function = SvPV (ST (0), integer);
|
||||
function = SvPV (ST (0), PL_na);
|
||||
|
||||
if (perl_plugin->keyboard_handler_add (perl_plugin,
|
||||
weechat_perl_keyboard_handler,
|
||||
@ -678,7 +704,6 @@ static XS (XS_weechat_add_keyboard_handler)
|
||||
static XS (XS_weechat_remove_handler)
|
||||
{
|
||||
char *command, *function;
|
||||
unsigned int integer;
|
||||
dXSARGS;
|
||||
|
||||
/* make gcc happy */
|
||||
@ -700,8 +725,8 @@ static XS (XS_weechat_remove_handler)
|
||||
XSRETURN_NO;
|
||||
}
|
||||
|
||||
command = SvPV (ST (0), integer);
|
||||
function = SvPV (ST (1), integer);
|
||||
command = SvPV (ST (0), PL_na);
|
||||
function = SvPV (ST (1), PL_na);
|
||||
|
||||
weechat_script_remove_handler (perl_plugin, perl_current_script,
|
||||
command, function);
|
||||
@ -716,7 +741,6 @@ static XS (XS_weechat_remove_handler)
|
||||
static XS (XS_weechat_remove_timer_handler)
|
||||
{
|
||||
char *function;
|
||||
unsigned int integer;
|
||||
dXSARGS;
|
||||
|
||||
/* make gcc happy */
|
||||
@ -738,7 +762,7 @@ static XS (XS_weechat_remove_timer_handler)
|
||||
XSRETURN_NO;
|
||||
}
|
||||
|
||||
function = SvPV (ST (0), integer);
|
||||
function = SvPV (ST (0), PL_na);
|
||||
|
||||
weechat_script_remove_timer_handler (perl_plugin, perl_current_script,
|
||||
function);
|
||||
@ -753,7 +777,6 @@ static XS (XS_weechat_remove_timer_handler)
|
||||
static XS (XS_weechat_remove_keyboard_handler)
|
||||
{
|
||||
char *function;
|
||||
unsigned int integer;
|
||||
dXSARGS;
|
||||
|
||||
/* make gcc happy */
|
||||
@ -775,7 +798,7 @@ static XS (XS_weechat_remove_keyboard_handler)
|
||||
XSRETURN_NO;
|
||||
}
|
||||
|
||||
function = SvPV (ST (0), integer);
|
||||
function = SvPV (ST (0), PL_na);
|
||||
|
||||
weechat_script_remove_keyboard_handler (perl_plugin, perl_current_script,
|
||||
function);
|
||||
@ -790,7 +813,6 @@ static XS (XS_weechat_remove_keyboard_handler)
|
||||
static XS (XS_weechat_get_info)
|
||||
{
|
||||
char *arg, *info, *server_name;
|
||||
unsigned int integer;
|
||||
dXSARGS;
|
||||
|
||||
/* make gcc happy */
|
||||
@ -812,9 +834,9 @@ static XS (XS_weechat_get_info)
|
||||
XSRETURN_NO;
|
||||
}
|
||||
|
||||
server_name = (items == 2) ? SvPV (ST (1), integer) : NULL;
|
||||
server_name = (items == 2) ? SvPV (ST (1), PL_na) : NULL;
|
||||
|
||||
arg = SvPV (ST (0), integer);
|
||||
arg = SvPV (ST (0), PL_na);
|
||||
if (arg)
|
||||
{
|
||||
info = perl_plugin->get_info (perl_plugin, arg, server_name);
|
||||
@ -904,7 +926,6 @@ static XS (XS_weechat_get_dcc_info)
|
||||
static XS (XS_weechat_get_config)
|
||||
{
|
||||
char *option, *return_value;
|
||||
unsigned int integer;
|
||||
dXSARGS;
|
||||
|
||||
/* make gcc happy */
|
||||
@ -915,7 +936,7 @@ static XS (XS_weechat_get_config)
|
||||
perl_plugin->print_server (perl_plugin,
|
||||
"Perl error: unable to get config option, "
|
||||
"script not initialized");
|
||||
XSRETURN_NO;
|
||||
XSRETURN_EMPTY;
|
||||
}
|
||||
|
||||
if (items < 1)
|
||||
@ -923,10 +944,10 @@ static XS (XS_weechat_get_config)
|
||||
perl_plugin->print_server (perl_plugin,
|
||||
"Perl error: wrong parameters for "
|
||||
"\"get_config\" function");
|
||||
XSRETURN_NO;
|
||||
XSRETURN_EMPTY;
|
||||
}
|
||||
|
||||
option = SvPV (ST (0), integer);
|
||||
option = SvPV (ST (0), PL_na);
|
||||
|
||||
if (option)
|
||||
{
|
||||
@ -951,7 +972,6 @@ static XS (XS_weechat_get_config)
|
||||
static XS (XS_weechat_set_config)
|
||||
{
|
||||
char *option, *value;
|
||||
unsigned int integer;
|
||||
dXSARGS;
|
||||
|
||||
/* make gcc happy */
|
||||
@ -973,8 +993,8 @@ static XS (XS_weechat_set_config)
|
||||
XSRETURN_NO;
|
||||
}
|
||||
|
||||
option = SvPV (ST (0), integer);
|
||||
value = SvPV (ST (1), integer);
|
||||
option = SvPV (ST (0), PL_na);
|
||||
value = SvPV (ST (1), PL_na);
|
||||
|
||||
if (option && value)
|
||||
{
|
||||
@ -992,7 +1012,6 @@ static XS (XS_weechat_set_config)
|
||||
static XS (XS_weechat_get_plugin_config)
|
||||
{
|
||||
char *option, *return_value;
|
||||
unsigned int integer;
|
||||
dXSARGS;
|
||||
|
||||
/* make gcc happy */
|
||||
@ -1003,7 +1022,7 @@ static XS (XS_weechat_get_plugin_config)
|
||||
perl_plugin->print_server (perl_plugin,
|
||||
"Perl error: unable to get plugin config option, "
|
||||
"script not initialized");
|
||||
XSRETURN_NO;
|
||||
XSRETURN_EMPTY;
|
||||
}
|
||||
|
||||
if (items < 1)
|
||||
@ -1011,10 +1030,10 @@ static XS (XS_weechat_get_plugin_config)
|
||||
perl_plugin->print_server (perl_plugin,
|
||||
"Perl error: wrong parameters for "
|
||||
"\"get_plugin_config\" function");
|
||||
XSRETURN_NO;
|
||||
XSRETURN_EMPTY;
|
||||
}
|
||||
|
||||
option = SvPV (ST (0), integer);
|
||||
option = SvPV (ST (0), PL_na);
|
||||
|
||||
if (option)
|
||||
{
|
||||
@ -1041,7 +1060,6 @@ static XS (XS_weechat_get_plugin_config)
|
||||
static XS (XS_weechat_set_plugin_config)
|
||||
{
|
||||
char *option, *value;
|
||||
unsigned int integer;
|
||||
dXSARGS;
|
||||
|
||||
/* make gcc happy */
|
||||
@ -1063,8 +1081,8 @@ static XS (XS_weechat_set_plugin_config)
|
||||
XSRETURN_NO;
|
||||
}
|
||||
|
||||
option = SvPV (ST (0), integer);
|
||||
value = SvPV (ST (1), integer);
|
||||
option = SvPV (ST (0), PL_na);
|
||||
value = SvPV (ST (1), PL_na);
|
||||
|
||||
if (option && value)
|
||||
{
|
||||
@ -1152,7 +1170,6 @@ static XS (XS_weechat_get_server_info)
|
||||
}
|
||||
perl_plugin->free_server_info (perl_plugin, server_info);
|
||||
|
||||
//XPUSHs(newRV_inc((SV *) server_hash));
|
||||
ST (0) = newRV_inc((SV *) server_hash);
|
||||
XSRETURN (1);
|
||||
}
|
||||
@ -1165,7 +1182,6 @@ static XS (XS_weechat_get_channel_info)
|
||||
{
|
||||
t_plugin_channel_info *channel_info, *ptr_channel;
|
||||
char *server;
|
||||
unsigned int integer;
|
||||
HV *channel_hash, *channel_hash_member;
|
||||
dXSARGS;
|
||||
|
||||
@ -1188,7 +1204,7 @@ static XS (XS_weechat_get_channel_info)
|
||||
XSRETURN_EMPTY;
|
||||
}
|
||||
|
||||
server = SvPV (ST (0), integer);
|
||||
server = SvPV (ST (0), PL_na);
|
||||
if (!server)
|
||||
XSRETURN_EMPTY;
|
||||
|
||||
@ -1220,7 +1236,6 @@ static XS (XS_weechat_get_channel_info)
|
||||
}
|
||||
perl_plugin->free_channel_info (perl_plugin, channel_info);
|
||||
|
||||
//XPUSHs(newRV_inc((SV *) channel_hash));
|
||||
ST (0) = newRV_inc((SV *) channel_hash);
|
||||
XSRETURN (1);
|
||||
}
|
||||
@ -1233,7 +1248,6 @@ static XS (XS_weechat_get_nick_info)
|
||||
{
|
||||
t_plugin_nick_info *nick_info, *ptr_nick;
|
||||
char *server, *channel;
|
||||
unsigned int integer;
|
||||
HV *nick_hash;
|
||||
dXSARGS;
|
||||
|
||||
@ -1256,8 +1270,8 @@ static XS (XS_weechat_get_nick_info)
|
||||
XSRETURN_EMPTY;
|
||||
}
|
||||
|
||||
server = SvPV (ST (0), integer);
|
||||
channel = SvPV (ST (1), integer);
|
||||
server = SvPV (ST (0), PL_na);
|
||||
channel = SvPV (ST (1), PL_na);
|
||||
if (!server || !channel)
|
||||
XSRETURN_EMPTY;
|
||||
|
||||
@ -1286,7 +1300,6 @@ static XS (XS_weechat_get_nick_info)
|
||||
}
|
||||
perl_plugin->free_nick_info (perl_plugin, nick_info);
|
||||
|
||||
//XPUSHs(newRV_inc((SV *) nick_hash));
|
||||
ST (0) = newRV_inc((SV *) nick_hash);
|
||||
XSRETURN (1);
|
||||
}
|
||||
@ -1336,7 +1349,6 @@ static XS (XS_weechat_input_color)
|
||||
static XS (XS_weechat_get_irc_color)
|
||||
{
|
||||
char *color;
|
||||
unsigned int integer;
|
||||
dXSARGS;
|
||||
|
||||
/* make gcc happy */
|
||||
@ -1360,7 +1372,7 @@ static XS (XS_weechat_get_irc_color)
|
||||
XSRETURN (1);
|
||||
}
|
||||
|
||||
color = SvPV (ST (0), integer);
|
||||
color = SvPV (ST (0), PL_na);
|
||||
if (color)
|
||||
{
|
||||
XST_mIV (0, perl_plugin->get_irc_color (perl_plugin, color));
|
||||
@ -1371,6 +1383,176 @@ static XS (XS_weechat_get_irc_color)
|
||||
XSRETURN (-1);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat::get_window_info: get infos about windows
|
||||
*/
|
||||
|
||||
static XS (XS_weechat_get_window_info)
|
||||
{
|
||||
t_plugin_window_info *window_info, *ptr_window;
|
||||
int count;
|
||||
HV *window_hash_member;
|
||||
dXSARGS;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) cv;
|
||||
(void) items;
|
||||
|
||||
if (!perl_current_script)
|
||||
{
|
||||
perl_plugin->print_server (perl_plugin,
|
||||
"Perl error: unable to get window info, "
|
||||
"script not initialized");
|
||||
XSRETURN_EMPTY;
|
||||
}
|
||||
|
||||
window_info = perl_plugin->get_window_info (perl_plugin);
|
||||
count = 0;
|
||||
if (!window_info)
|
||||
XSRETURN_EMPTY;
|
||||
|
||||
for (ptr_window = window_info; ptr_window; ptr_window = ptr_window->next_window)
|
||||
{
|
||||
window_hash_member = (HV *) sv_2mortal((SV *) newHV());
|
||||
|
||||
hv_store (window_hash_member, "num_buffer", 10, newSViv (ptr_window->num_buffer), 0);
|
||||
hv_store (window_hash_member, "win_x", 5, newSViv (ptr_window->win_x), 0);
|
||||
hv_store (window_hash_member, "win_y", 5, newSViv (ptr_window->win_y), 0);
|
||||
hv_store (window_hash_member, "win_width", 9, newSViv (ptr_window->win_width), 0);
|
||||
hv_store (window_hash_member, "win_height", 10, newSViv (ptr_window->win_height), 0);
|
||||
hv_store (window_hash_member, "win_width_pct", 13, newSViv (ptr_window->win_width_pct), 0);
|
||||
hv_store (window_hash_member, "win_height_pct", 14, newSViv (ptr_window->win_height_pct), 0);
|
||||
|
||||
XPUSHs(newRV_inc((SV *) window_hash_member));
|
||||
count++;
|
||||
}
|
||||
perl_plugin->free_window_info (perl_plugin, window_info);
|
||||
|
||||
XSRETURN (count);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat::get_buffer_info: get infos about buffers
|
||||
*/
|
||||
|
||||
static XS (XS_weechat_get_buffer_info)
|
||||
{
|
||||
t_plugin_buffer_info *buffer_info, *ptr_buffer;
|
||||
HV *buffer_hash, *buffer_hash_member;
|
||||
char conv[8];
|
||||
dXSARGS;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) cv;
|
||||
(void) items;
|
||||
|
||||
if (!perl_current_script)
|
||||
{
|
||||
perl_plugin->print_server (perl_plugin,
|
||||
"Perl error: unable to get buffer info, "
|
||||
"script not initialized");
|
||||
XSRETURN_EMPTY;
|
||||
}
|
||||
|
||||
buffer_info = perl_plugin->get_buffer_info (perl_plugin);
|
||||
if (!buffer_info)
|
||||
{
|
||||
XSRETURN_EMPTY;
|
||||
}
|
||||
|
||||
buffer_hash = (HV *) sv_2mortal((SV *) newHV());
|
||||
if (!buffer_hash)
|
||||
{
|
||||
perl_plugin->free_buffer_info (perl_plugin, buffer_info);
|
||||
XSRETURN_EMPTY;
|
||||
}
|
||||
|
||||
for (ptr_buffer = buffer_info; ptr_buffer; ptr_buffer = ptr_buffer->next_buffer)
|
||||
{
|
||||
buffer_hash_member = (HV *) sv_2mortal((SV *) newHV());
|
||||
|
||||
hv_store (buffer_hash_member, "type", 4, newSViv (ptr_buffer->type), 0);
|
||||
hv_store (buffer_hash_member, "num_displayed", 13, newSViv (ptr_buffer->num_displayed), 0);
|
||||
hv_store (buffer_hash_member, "server", 6,
|
||||
newSVpv (ptr_buffer->server_name == NULL ? "" : ptr_buffer->server_name, 0), 0);
|
||||
hv_store (buffer_hash_member, "channel", 7,
|
||||
newSVpv (ptr_buffer->channel_name == NULL ? "" : ptr_buffer->channel_name, 0), 0);
|
||||
hv_store (buffer_hash_member, "notify_level", 12, newSViv (ptr_buffer->notify_level), 0);
|
||||
hv_store (buffer_hash_member, "log_filename", 12,
|
||||
newSVpv (ptr_buffer->log_filename == NULL ? "" : ptr_buffer->log_filename, 0), 0);
|
||||
|
||||
snprintf(conv, sizeof(conv), "%d", ptr_buffer->number);
|
||||
hv_store (buffer_hash, conv, strlen(conv), newRV_inc((SV *) buffer_hash_member), 0);
|
||||
}
|
||||
perl_plugin->free_buffer_info (perl_plugin, buffer_info);
|
||||
|
||||
ST (0) = newRV_inc((SV *) buffer_hash);
|
||||
XSRETURN (1);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat::get_buffer_data: get buffer content
|
||||
*/
|
||||
|
||||
static XS (XS_weechat_get_buffer_data)
|
||||
{
|
||||
t_plugin_buffer_line *buffer_data, *ptr_data;
|
||||
HV *data_list_member;
|
||||
char *server, *channel;
|
||||
int count;
|
||||
|
||||
dXSARGS;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) cv;
|
||||
(void) items;
|
||||
|
||||
if (!perl_current_script)
|
||||
{
|
||||
perl_plugin->print_server (perl_plugin,
|
||||
"Perl error: unable to get buffer data, "
|
||||
"script not initialized");
|
||||
XSRETURN_EMPTY;
|
||||
}
|
||||
|
||||
if (items > 2)
|
||||
{
|
||||
perl_plugin->print_server (perl_plugin,
|
||||
"Perl error: wrong parameters for "
|
||||
"\"get_buffer_data\" function");
|
||||
XSRETURN_EMPTY;
|
||||
}
|
||||
|
||||
channel = NULL;
|
||||
server = NULL;
|
||||
|
||||
if (items >= 1)
|
||||
server = SvPV (ST (0), PL_na);
|
||||
if (items >= 2)
|
||||
channel = SvPV (ST (1), PL_na);
|
||||
|
||||
buffer_data = perl_plugin->get_buffer_data (perl_plugin, server, channel);
|
||||
count = 0;
|
||||
if (!buffer_data)
|
||||
XSRETURN_EMPTY;
|
||||
|
||||
for (ptr_data = buffer_data; ptr_data; ptr_data = ptr_data->next_line)
|
||||
{
|
||||
data_list_member = (HV *) sv_2mortal((SV *) newHV());
|
||||
|
||||
hv_store (data_list_member, "nick", 4,
|
||||
newSVpv (ptr_data->nick == NULL ? "" : ptr_data->nick, 0), 0);
|
||||
hv_store (data_list_member, "data", 4,
|
||||
newSVpv (ptr_data->data == NULL ? "" : ptr_data->data, 0), 0);
|
||||
|
||||
XPUSHs(newRV_inc((SV *) data_list_member));
|
||||
count++;
|
||||
}
|
||||
perl_plugin->free_buffer_data (perl_plugin, buffer_data);
|
||||
|
||||
XSRETURN (count);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_perl_xs_init: initialize subroutines
|
||||
*/
|
||||
@ -1385,6 +1567,7 @@ weechat_perl_xs_init (pTHX)
|
||||
/* interface functions */
|
||||
newXS ("weechat::register", XS_weechat_register, "weechat");
|
||||
newXS ("weechat::print", XS_weechat_print, "weechat");
|
||||
newXS ("weechat::print_server", XS_weechat_print_server, "weechat");
|
||||
newXS ("weechat::print_infobar", XS_weechat_print_infobar, "weechat");
|
||||
newXS ("weechat::remove_infobar", XS_weechat_remove_infobar, "weechat");
|
||||
newXS ("weechat::log", XS_weechat_log, "weechat");
|
||||
@ -1407,6 +1590,9 @@ weechat_perl_xs_init (pTHX)
|
||||
newXS ("weechat::get_nick_info", XS_weechat_get_nick_info, "weechat");
|
||||
newXS ("weechat::input_color", XS_weechat_input_color, "weechat");
|
||||
newXS ("weechat::get_irc_color", XS_weechat_get_irc_color, "weechat");
|
||||
newXS ("weechat::get_window_info", XS_weechat_get_window_info, "weechat");
|
||||
newXS ("weechat::get_buffer_info", XS_weechat_get_buffer_info, "weechat");
|
||||
newXS ("weechat::get_buffer_data", XS_weechat_get_buffer_data, "weechat");
|
||||
|
||||
/* interface constants */
|
||||
stash = gv_stashpv ("weechat", TRUE);
|
||||
|
@ -267,6 +267,41 @@ weechat_python_print (PyObject *self, PyObject *args)
|
||||
return Py_BuildValue ("i", 1);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_python_print_server: print message into a buffer server
|
||||
*/
|
||||
|
||||
static PyObject *
|
||||
weechat_python_print_server (PyObject *self, PyObject *args)
|
||||
{
|
||||
char *message;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) self;
|
||||
|
||||
if (!python_current_script)
|
||||
{
|
||||
python_plugin->print_server (python_plugin,
|
||||
"Python error: unable to print message (server), "
|
||||
"script not initialized");
|
||||
return Py_BuildValue ("i", 0);
|
||||
}
|
||||
|
||||
message = NULL;
|
||||
|
||||
if (!PyArg_ParseTuple (args, "s", &message))
|
||||
{
|
||||
python_plugin->print_server (python_plugin,
|
||||
"Python error: wrong parameters for "
|
||||
"\"print_server\" function");
|
||||
return Py_BuildValue ("i", 0);
|
||||
}
|
||||
|
||||
python_plugin->print_server (python_plugin, "%s", message);
|
||||
|
||||
return Py_BuildValue ("i", 1);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_python_print_infobar: print message to infobar
|
||||
*/
|
||||
@ -822,22 +857,9 @@ weechat_python_get_dcc_info (PyObject *self, PyObject *args)
|
||||
PyDict_SetItem(dcc_list_member, Py_BuildValue("s", "start_resume"),
|
||||
Py_BuildValue("k", ptr_dcc->start_resume));
|
||||
PyDict_SetItem(dcc_list_member, Py_BuildValue("s", "cps"),
|
||||
Py_BuildValue("k", ptr_dcc->bytes_per_sec));
|
||||
Py_BuildValue("k", ptr_dcc->bytes_per_sec));
|
||||
|
||||
|
||||
if (PyList_Append(dcc_list, dcc_list_member) != 0)
|
||||
{
|
||||
Py_DECREF(dcc_list_member);
|
||||
Py_DECREF(dcc_list);
|
||||
python_plugin->free_dcc_info (python_plugin, dcc_info);
|
||||
return Py_None;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Py_DECREF(dcc_list);
|
||||
python_plugin->free_dcc_info (python_plugin, dcc_info);
|
||||
return Py_None;
|
||||
PyList_Append(dcc_list, dcc_list_member);
|
||||
}
|
||||
}
|
||||
|
||||
@ -864,7 +886,7 @@ weechat_python_get_config (PyObject *self, PyObject *args)
|
||||
python_plugin->print_server (python_plugin,
|
||||
"Python error: unable to get config option, "
|
||||
"script not initialized");
|
||||
return Py_BuildValue ("i", 0);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
option = NULL;
|
||||
@ -874,7 +896,7 @@ weechat_python_get_config (PyObject *self, PyObject *args)
|
||||
python_plugin->print_server (python_plugin,
|
||||
"Python error: wrong parameters for "
|
||||
"\"get_config\" function");
|
||||
return Py_BuildValue ("i", 0);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
if (option)
|
||||
@ -950,7 +972,7 @@ weechat_python_get_plugin_config (PyObject *self, PyObject *args)
|
||||
python_plugin->print_server (python_plugin,
|
||||
"Python error: unable to get plugin config option, "
|
||||
"script not initialized");
|
||||
return Py_BuildValue ("i", 0);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
option = NULL;
|
||||
@ -960,7 +982,7 @@ weechat_python_get_plugin_config (PyObject *self, PyObject *args)
|
||||
python_plugin->print_server (python_plugin,
|
||||
"Python error: wrong parameters for "
|
||||
"\"get_plugin_config\" function");
|
||||
return Py_BuildValue ("i", 0);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
if (option)
|
||||
@ -1042,7 +1064,7 @@ weechat_python_get_server_info (PyObject *self, PyObject *args)
|
||||
python_plugin->print_server (python_plugin,
|
||||
"Python error: unable to get server infos, "
|
||||
"script not initialized");
|
||||
return Py_BuildValue ("i", 0);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
server_hash = PyDict_New ();
|
||||
@ -1145,7 +1167,7 @@ weechat_python_get_channel_info (PyObject *self, PyObject *args)
|
||||
python_plugin->print_server (python_plugin,
|
||||
"Python error: unable to get channel infos, "
|
||||
"script not initialized");
|
||||
return Py_BuildValue ("i", 0);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
server = NULL;
|
||||
@ -1154,7 +1176,7 @@ weechat_python_get_channel_info (PyObject *self, PyObject *args)
|
||||
python_plugin->print_server (python_plugin,
|
||||
"Python error: wrong parameters for "
|
||||
"\"get_channel_info\" function");
|
||||
return Py_BuildValue ("i", 0);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
channel_hash = PyDict_New ();
|
||||
@ -1212,7 +1234,7 @@ weechat_python_get_nick_info (PyObject *self, PyObject *args)
|
||||
python_plugin->print_server (python_plugin,
|
||||
"Python error: unable to get nick infos, "
|
||||
"script not initialized");
|
||||
return Py_BuildValue ("i", 0);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
server = NULL;
|
||||
@ -1222,7 +1244,7 @@ weechat_python_get_nick_info (PyObject *self, PyObject *args)
|
||||
python_plugin->print_server (python_plugin,
|
||||
"Python error: wrong parameters for "
|
||||
"\"get_nick_info\" function");
|
||||
return Py_BuildValue ("i", 0);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
nick_hash = PyDict_New ();
|
||||
@ -1290,6 +1312,184 @@ weechat_python_get_irc_color (PyObject *self, PyObject *args)
|
||||
return Py_BuildValue ("i", -1);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_python_get_window_info: get infos about windows
|
||||
*/
|
||||
|
||||
static PyObject *
|
||||
weechat_python_get_window_info (PyObject *self, PyObject *args)
|
||||
{
|
||||
t_plugin_window_info *window_info, *ptr_window;
|
||||
PyObject *window_list, *window_list_member;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) self;
|
||||
(void) args;
|
||||
|
||||
if (!python_current_script)
|
||||
{
|
||||
python_plugin->print_server (python_plugin,
|
||||
"Python error: unable to get window info, "
|
||||
"script not initialized");
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
window_list = PyList_New (0);
|
||||
if (!window_list)
|
||||
return Py_None;
|
||||
|
||||
window_info = python_plugin->get_window_info (python_plugin);
|
||||
if (!window_info)
|
||||
return window_list;
|
||||
|
||||
for(ptr_window = window_info; ptr_window; ptr_window = ptr_window->next_window)
|
||||
{
|
||||
window_list_member = PyDict_New();
|
||||
|
||||
if (window_list_member)
|
||||
{
|
||||
PyDict_SetItem(window_list_member, Py_BuildValue("s", "num_buffer"),
|
||||
Py_BuildValue("i", ptr_window->num_buffer));
|
||||
PyDict_SetItem(window_list_member, Py_BuildValue("s", "win_x"),
|
||||
Py_BuildValue("i", ptr_window->win_x));
|
||||
PyDict_SetItem(window_list_member, Py_BuildValue("s", "win_y"),
|
||||
Py_BuildValue("i", ptr_window->win_y));
|
||||
PyDict_SetItem(window_list_member, Py_BuildValue("s", "win_width"),
|
||||
Py_BuildValue("i", ptr_window->win_width));
|
||||
PyDict_SetItem(window_list_member, Py_BuildValue("s", "win_height"),
|
||||
Py_BuildValue("i", ptr_window->win_height));
|
||||
PyDict_SetItem(window_list_member, Py_BuildValue("s", "win_width_pct"),
|
||||
Py_BuildValue("i", ptr_window->win_width_pct));
|
||||
PyDict_SetItem(window_list_member, Py_BuildValue("s", "win_height_pct"),
|
||||
Py_BuildValue("i", ptr_window->win_height_pct));
|
||||
|
||||
PyList_Append(window_list, window_list_member);
|
||||
}
|
||||
}
|
||||
|
||||
python_plugin->free_window_info(python_plugin, window_info);
|
||||
|
||||
return window_list;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_python_get_buffer_info: get infos about buffers
|
||||
*/
|
||||
|
||||
static PyObject *
|
||||
weechat_python_get_buffer_info (PyObject *self, PyObject *args)
|
||||
{
|
||||
t_plugin_buffer_info *buffer_info, *ptr_buffer;
|
||||
PyObject *buffer_hash, *buffer_hash_member;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) self;
|
||||
(void) args;
|
||||
|
||||
if (!python_current_script)
|
||||
{
|
||||
python_plugin->print_server (python_plugin,
|
||||
"Python error: unable to get buffer info, "
|
||||
"script not initialized");
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
buffer_hash = PyDict_New ();
|
||||
if (!buffer_hash)
|
||||
return Py_None;
|
||||
|
||||
buffer_info = python_plugin->get_buffer_info (python_plugin);
|
||||
if (!buffer_info)
|
||||
return buffer_hash;
|
||||
|
||||
for(ptr_buffer = buffer_info; ptr_buffer; ptr_buffer = ptr_buffer->next_buffer)
|
||||
{
|
||||
buffer_hash_member = PyDict_New();
|
||||
|
||||
if (buffer_hash_member)
|
||||
{
|
||||
PyDict_SetItem(buffer_hash_member, Py_BuildValue("s", "type"),
|
||||
Py_BuildValue("i", ptr_buffer->type));
|
||||
PyDict_SetItem(buffer_hash_member, Py_BuildValue("s", "num_displayed"),
|
||||
Py_BuildValue("i", ptr_buffer->num_displayed));
|
||||
PyDict_SetItem(buffer_hash_member, Py_BuildValue("s", "server"),
|
||||
Py_BuildValue("s", ptr_buffer->server_name == NULL ? "" : ptr_buffer->server_name));
|
||||
PyDict_SetItem(buffer_hash_member, Py_BuildValue("s", "channel"),
|
||||
Py_BuildValue("s", ptr_buffer->channel_name == NULL ? "" : ptr_buffer->channel_name));
|
||||
PyDict_SetItem(buffer_hash_member, Py_BuildValue("s", "notify_level"),
|
||||
Py_BuildValue("i", ptr_buffer->notify_level));
|
||||
PyDict_SetItem(buffer_hash_member, Py_BuildValue("s", "log_filename"),
|
||||
Py_BuildValue("s", ptr_buffer->log_filename == NULL ? "" : ptr_buffer->log_filename));
|
||||
|
||||
PyDict_SetItem(buffer_hash,
|
||||
Py_BuildValue("i", ptr_buffer->number), buffer_hash_member);
|
||||
}
|
||||
}
|
||||
|
||||
python_plugin->free_buffer_info(python_plugin, buffer_info);
|
||||
|
||||
return buffer_hash;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_python_get_buffer_data: get buffer content
|
||||
*/
|
||||
|
||||
static PyObject *
|
||||
weechat_python_get_buffer_data (PyObject *self, PyObject *args)
|
||||
{
|
||||
t_plugin_buffer_line *buffer_data, *ptr_data;
|
||||
PyObject *data_list, *data_list_member;
|
||||
char *server, *channel;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) self;
|
||||
(void) args;
|
||||
|
||||
if (!python_current_script)
|
||||
{
|
||||
python_plugin->print_server (python_plugin,
|
||||
"Python error: unable to get buffer data, "
|
||||
"script not initialized");
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
if (!PyArg_ParseTuple (args, "|ss", &server, &channel))
|
||||
{
|
||||
python_plugin->print_server (python_plugin,
|
||||
"Python error: wrong parameters for "
|
||||
"\"get_buffer_data\" function");
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
data_list = PyList_New (0);
|
||||
if (!data_list)
|
||||
return Py_None;
|
||||
|
||||
buffer_data = python_plugin->get_buffer_data (python_plugin, server, channel);
|
||||
if (!buffer_data)
|
||||
return data_list;
|
||||
|
||||
for(ptr_data = buffer_data; ptr_data; ptr_data = ptr_data->next_line)
|
||||
{
|
||||
data_list_member= PyDict_New();
|
||||
|
||||
if (data_list_member)
|
||||
{
|
||||
PyDict_SetItem(data_list_member, Py_BuildValue("s", "nick"),
|
||||
Py_BuildValue("s", ptr_data->nick == NULL ? "" : ptr_data->nick));
|
||||
PyDict_SetItem(data_list_member, Py_BuildValue("s", "data"),
|
||||
Py_BuildValue("s", ptr_data->data == NULL ? "" : ptr_data->data));
|
||||
|
||||
PyList_Append(data_list, data_list_member);
|
||||
}
|
||||
}
|
||||
|
||||
python_plugin->free_buffer_data (python_plugin, buffer_data);
|
||||
|
||||
return data_list;
|
||||
}
|
||||
|
||||
/*
|
||||
* Python subroutines
|
||||
*/
|
||||
@ -1298,6 +1498,7 @@ static
|
||||
PyMethodDef weechat_python_funcs[] = {
|
||||
{ "register", weechat_python_register, METH_VARARGS, "" },
|
||||
{ "prnt", weechat_python_print, METH_VARARGS, "" },
|
||||
{ "print_server", weechat_python_print_server, METH_VARARGS, "" },
|
||||
{ "print_infobar", weechat_python_print_infobar, METH_VARARGS, "" },
|
||||
{ "remove_infobar", weechat_python_remove_infobar, METH_VARARGS, "" },
|
||||
{ "log", weechat_python_log, METH_VARARGS, "" },
|
||||
@ -1319,6 +1520,9 @@ PyMethodDef weechat_python_funcs[] = {
|
||||
{ "get_channel_info", weechat_python_get_channel_info, METH_VARARGS, "" },
|
||||
{ "get_nick_info", weechat_python_get_nick_info, METH_VARARGS, "" },
|
||||
{ "get_irc_color", weechat_python_get_irc_color, METH_VARARGS, "" },
|
||||
{ "get_window_info", weechat_python_get_window_info, METH_VARARGS, "" },
|
||||
{ "get_buffer_info", weechat_python_get_buffer_info, METH_VARARGS, "" },
|
||||
{ "get_buffer_data", weechat_python_get_buffer_data, METH_VARARGS, "" },
|
||||
{ NULL, NULL, 0, NULL }
|
||||
};
|
||||
|
||||
|
@ -336,6 +336,44 @@ weechat_ruby_print (int argc, VALUE *argv, VALUE class)
|
||||
return INT2FIX (1);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_ruby_print_server: print message into a buffer server
|
||||
*/
|
||||
|
||||
static VALUE
|
||||
weechat_ruby_print_server (VALUE class, VALUE message)
|
||||
{
|
||||
char *c_message;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) class;
|
||||
|
||||
if (!ruby_current_script)
|
||||
{
|
||||
ruby_plugin->print_server (ruby_plugin,
|
||||
"Ruby error: unable to print message, "
|
||||
"script not initialized");
|
||||
return INT2FIX (0);
|
||||
}
|
||||
|
||||
c_message = NULL;
|
||||
|
||||
if (NIL_P (message))
|
||||
{
|
||||
ruby_plugin->print_server (ruby_plugin,
|
||||
"Ruby error: wrong parameters for "
|
||||
"\"print_server\" function");
|
||||
return INT2FIX (0);
|
||||
}
|
||||
|
||||
Check_Type (message, T_STRING);
|
||||
c_message = STR2CSTR (message);
|
||||
|
||||
ruby_plugin->print_server (ruby_plugin, "%s", c_message);
|
||||
|
||||
return INT2FIX (1);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_ruby_print_infobar: print message to infobar
|
||||
*/
|
||||
@ -1024,20 +1062,8 @@ weechat_ruby_get_dcc_info (VALUE class)
|
||||
rb_hash_aset (dcc_list_member, rb_str_new2("cps"),
|
||||
INT2FIX(ptr_dcc->bytes_per_sec));
|
||||
|
||||
if (NIL_P (rb_ary_push (dcc_list, dcc_list_member)))
|
||||
{
|
||||
rb_gc_unregister_address (&dcc_list_member);
|
||||
rb_gc_unregister_address (&dcc_list);
|
||||
ruby_plugin->free_dcc_info (ruby_plugin, dcc_info);
|
||||
return Qnil;
|
||||
}
|
||||
rb_ary_push (dcc_list, dcc_list_member);
|
||||
}
|
||||
else
|
||||
{
|
||||
rb_gc_unregister_address (&dcc_list);
|
||||
ruby_plugin->free_dcc_info (ruby_plugin, dcc_info);
|
||||
return Qnil;
|
||||
}
|
||||
}
|
||||
|
||||
ruby_plugin->free_dcc_info (ruby_plugin, dcc_info);
|
||||
@ -1522,6 +1548,193 @@ weechat_ruby_get_irc_color (VALUE class, VALUE color)
|
||||
return INT2FIX (ruby_plugin->get_irc_color (ruby_plugin, c_color));
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_ruby_get_window_info: get infos about windows
|
||||
*/
|
||||
|
||||
static VALUE
|
||||
weechat_ruby_get_window_info (VALUE class)
|
||||
{
|
||||
t_plugin_window_info *window_info, *ptr_window;
|
||||
VALUE window_list, window_list_member;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) class;
|
||||
|
||||
if (!ruby_current_script)
|
||||
{
|
||||
ruby_plugin->print_server (ruby_plugin,
|
||||
"Ruby error: unable to get window info, "
|
||||
"script not initialized");
|
||||
return INT2FIX (0);
|
||||
}
|
||||
|
||||
window_list = rb_ary_new();
|
||||
|
||||
if (NIL_P (window_list))
|
||||
return Qnil;
|
||||
|
||||
window_info = ruby_plugin->get_window_info (ruby_plugin);
|
||||
if (!window_info)
|
||||
return window_list;
|
||||
|
||||
for(ptr_window = window_info; ptr_window; ptr_window = ptr_window->next_window)
|
||||
{
|
||||
window_list_member = rb_hash_new ();
|
||||
|
||||
if (!NIL_P (window_list_member))
|
||||
{
|
||||
rb_hash_aset (window_list_member, rb_str_new2("num_buffer"),
|
||||
INT2FIX(ptr_window->num_buffer));
|
||||
rb_hash_aset (window_list_member, rb_str_new2("win_x"),
|
||||
INT2FIX(ptr_window->win_x));
|
||||
rb_hash_aset (window_list_member, rb_str_new2("win_y"),
|
||||
INT2FIX(ptr_window->win_y));
|
||||
rb_hash_aset (window_list_member, rb_str_new2("win_width"),
|
||||
INT2FIX(ptr_window->win_width));
|
||||
rb_hash_aset (window_list_member, rb_str_new2("win_height"),
|
||||
INT2FIX(ptr_window->win_height));
|
||||
rb_hash_aset (window_list_member, rb_str_new2("win_width_pct"),
|
||||
INT2FIX(ptr_window->win_width_pct));
|
||||
rb_hash_aset (window_list_member, rb_str_new2("win_height_pct"),
|
||||
INT2FIX(ptr_window->win_height_pct));
|
||||
|
||||
rb_ary_push (window_list, window_list_member);
|
||||
}
|
||||
}
|
||||
|
||||
ruby_plugin->free_window_info (ruby_plugin, window_info);
|
||||
|
||||
return window_list;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_ruby_get_buffer_info: get infos about buffers
|
||||
*/
|
||||
|
||||
static VALUE
|
||||
weechat_ruby_get_buffer_info (VALUE class)
|
||||
{
|
||||
t_plugin_buffer_info *buffer_info, *ptr_buffer;
|
||||
VALUE buffer_hash, buffer_hash_member;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) class;
|
||||
|
||||
if (!ruby_current_script)
|
||||
{
|
||||
ruby_plugin->print_server (ruby_plugin,
|
||||
"Ruby error: unable to get buffer info, "
|
||||
"script not initialized");
|
||||
return INT2FIX (0);
|
||||
}
|
||||
|
||||
buffer_hash = rb_hash_new ();
|
||||
if (!buffer_hash)
|
||||
return Qnil;
|
||||
|
||||
buffer_info = ruby_plugin->get_buffer_info (ruby_plugin);
|
||||
if (!buffer_info)
|
||||
return buffer_hash;
|
||||
|
||||
for(ptr_buffer = buffer_info; ptr_buffer; ptr_buffer = ptr_buffer->next_buffer)
|
||||
{
|
||||
buffer_hash_member = rb_hash_new ();
|
||||
|
||||
if (buffer_hash_member)
|
||||
{
|
||||
rb_hash_aset (buffer_hash_member, rb_str_new2("type"),
|
||||
INT2FIX(ptr_buffer->type));
|
||||
rb_hash_aset (buffer_hash_member, rb_str_new2("num_displayed"),
|
||||
INT2FIX(ptr_buffer->num_displayed));
|
||||
rb_hash_aset (buffer_hash_member, rb_str_new2("server"),
|
||||
rb_str_new2(ptr_buffer->server_name == NULL ? "" : ptr_buffer->server_name));
|
||||
rb_hash_aset (buffer_hash_member, rb_str_new2("channel"),
|
||||
rb_str_new2(ptr_buffer->channel_name == NULL ? "" : ptr_buffer->channel_name));
|
||||
rb_hash_aset (buffer_hash_member, rb_str_new2("notify_level"),
|
||||
INT2FIX(ptr_buffer->notify_level));
|
||||
rb_hash_aset (buffer_hash_member, rb_str_new2("log_filename"),
|
||||
rb_str_new2(ptr_buffer->log_filename == NULL ? "" : ptr_buffer->log_filename));
|
||||
|
||||
rb_hash_aset (buffer_hash, INT2FIX(ptr_buffer->number), buffer_hash_member);
|
||||
}
|
||||
}
|
||||
|
||||
ruby_plugin->free_buffer_info(ruby_plugin, buffer_info);
|
||||
|
||||
return buffer_hash;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_ruby_get_buffer_data: get buffer content
|
||||
*/
|
||||
|
||||
static VALUE
|
||||
weechat_ruby_get_buffer_data (int argc, VALUE *argv, VALUE class)
|
||||
{
|
||||
t_plugin_buffer_line *buffer_data, *ptr_data;
|
||||
VALUE data_list, data_list_member;
|
||||
VALUE server, channel;
|
||||
char *c_server, *c_channel;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) class;
|
||||
|
||||
if (!ruby_current_script)
|
||||
{
|
||||
ruby_plugin->print_server (ruby_plugin,
|
||||
"Ruby error: unable to get buffer data, "
|
||||
"script not initialized");
|
||||
return INT2FIX (0);
|
||||
}
|
||||
|
||||
server = Qnil;
|
||||
channel = Qnil;
|
||||
c_server = NULL;
|
||||
c_channel = NULL;
|
||||
|
||||
rb_scan_args (argc, argv, "02", &server, &channel);
|
||||
|
||||
if (!NIL_P (server))
|
||||
{
|
||||
Check_Type (server, T_STRING);
|
||||
c_server = STR2CSTR (server);
|
||||
}
|
||||
|
||||
if (!NIL_P (channel))
|
||||
{
|
||||
Check_Type (channel, T_STRING);
|
||||
c_channel = STR2CSTR (channel);
|
||||
}
|
||||
|
||||
data_list = rb_ary_new();
|
||||
if (NIL_P (data_list))
|
||||
return Qnil;
|
||||
|
||||
buffer_data = ruby_plugin->get_buffer_data (ruby_plugin, c_server, c_channel);
|
||||
if (!buffer_data)
|
||||
return data_list;
|
||||
|
||||
for(ptr_data = buffer_data; ptr_data; ptr_data = ptr_data->next_line)
|
||||
{
|
||||
data_list_member = rb_hash_new ();
|
||||
|
||||
if (!NIL_P (data_list_member))
|
||||
{
|
||||
rb_hash_aset (data_list_member, rb_str_new2("nick"),
|
||||
rb_str_new2(ptr_data->nick == NULL ? "" : ptr_data->nick));
|
||||
rb_hash_aset (data_list_member, rb_str_new2("data"),
|
||||
rb_str_new2(ptr_data->data == NULL ? "" : ptr_data->data));
|
||||
|
||||
rb_ary_push (data_list, data_list_member);
|
||||
}
|
||||
}
|
||||
|
||||
ruby_plugin->free_buffer_data (ruby_plugin, buffer_data);
|
||||
|
||||
return data_list;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_ruby_output : redirection for stdout and stderr
|
||||
*/
|
||||
@ -1964,6 +2177,7 @@ weechat_plugin_init (t_weechat_plugin *plugin)
|
||||
rb_define_const(ruby_mWeechat, "PLUGIN_RC_OK_IGNORE_ALL", INT2NUM(PLUGIN_RC_OK_IGNORE_ALL));
|
||||
rb_define_module_function (ruby_mWeechat, "register", weechat_ruby_register, 4);
|
||||
rb_define_module_function (ruby_mWeechat, "print", weechat_ruby_print, -1);
|
||||
rb_define_module_function (ruby_mWeechat, "print_server", weechat_ruby_print_server, 1);
|
||||
rb_define_module_function (ruby_mWeechat, "print_infobar", weechat_ruby_print_infobar, 2);
|
||||
rb_define_module_function (ruby_mWeechat, "remove_infobar", weechat_ruby_remove_infobar, -1);
|
||||
rb_define_module_function (ruby_mWeechat, "log", weechat_ruby_log, -1);
|
||||
@ -1985,7 +2199,10 @@ weechat_plugin_init (t_weechat_plugin *plugin)
|
||||
rb_define_module_function (ruby_mWeechat, "get_channel_info", weechat_ruby_get_channel_info, 1);
|
||||
rb_define_module_function (ruby_mWeechat, "get_nick_info", weechat_ruby_get_nick_info, 2);
|
||||
rb_define_module_function (ruby_mWeechat, "get_irc_color", weechat_ruby_get_irc_color, 1);
|
||||
|
||||
rb_define_module_function (ruby_mWeechat, "get_window_info", weechat_ruby_get_window_info, 0);
|
||||
rb_define_module_function (ruby_mWeechat, "get_buffer_info", weechat_ruby_get_buffer_info, 0);
|
||||
rb_define_module_function (ruby_mWeechat, "get_buffer_data", weechat_ruby_get_buffer_data, -1);
|
||||
|
||||
/* redirect stdin and stdout */
|
||||
ruby_mWeechatOutputs = rb_define_module("WeechatOutputs");
|
||||
rb_define_singleton_method(ruby_mWeechatOutputs, "write", weechat_ruby_output, 1);
|
||||
|
Loading…
x
Reference in New Issue
Block a user