From 8855d39f44892dc91f7aaef536e49082ff8517f7 Mon Sep 17 00:00:00 2001 From: Emmanuel Bouthenot Date: Thu, 16 Feb 2006 16:10:25 +0000 Subject: make possible to log with plugins / scripts --- src/plugins/scripts/perl/weechat-perl.c | 49 +++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) (limited to 'src/plugins/scripts/perl/weechat-perl.c') diff --git a/src/plugins/scripts/perl/weechat-perl.c b/src/plugins/scripts/perl/weechat-perl.c index ca20365d2..d50bf1d8f 100644 --- a/src/plugins/scripts/perl/weechat-perl.c +++ b/src/plugins/scripts/perl/weechat-perl.c @@ -336,6 +336,54 @@ static XS (XS_weechat_print_infobar) XSRETURN_YES; } +/* + * weechat::log: log message in server/channel (current or specified ones) + */ + +static XS (XS_weechat_log) +{ + unsigned int integer; + char *message, *channel_name, *server_name; + dXSARGS; + + /* make gcc happy */ + (void) cv; + + if (!perl_current_script) + { + perl_plugin->printf_server (perl_plugin, + "Perl error: unable to print message, " + "script not initialized"); + XSRETURN_NO; + } + + if (items < 1) + { + perl_plugin->printf_server (perl_plugin, + "Perl error: wrong parameters for " + "\"log\" function"); + XSRETURN_NO; + } + + message = SvPV (ST (0), integer); + + channel_name = NULL; + server_name = NULL; + + if (items > 1) + { + channel_name = SvPV (ST (1), integer); + if (items > 2) + server_name = SvPV (ST (2), integer); + } + + perl_plugin->log (perl_plugin, + server_name, channel_name, + "%s", message); + + XSRETURN_YES; +} + /* * weechat::command: send command to server */ @@ -1032,6 +1080,7 @@ weechat_perl_xs_init (pTHX) newXS ("weechat::register", XS_weechat_register, "weechat"); newXS ("weechat::print", XS_weechat_print, "weechat"); newXS ("weechat::print_infobar", XS_weechat_print_infobar, "weechat"); + newXS ("weechat::log", XS_weechat_log, "weechat"); newXS ("weechat::command", XS_weechat_command, "weechat"); newXS ("weechat::add_message_handler", XS_weechat_add_message_handler, "weechat"); newXS ("weechat::add_command_handler", XS_weechat_add_command_handler, "weechat"); -- cgit v1.2.3