mirror of
https://github.com/weechat/weechat.git
synced 2026-06-25 12:26:40 +02:00
make possible to log with plugins / scripts
This commit is contained in:
@@ -272,6 +272,64 @@ weechat_lua_print_infobar (lua_State *L)
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_lua_print: log message in server/channel (current or specified ones)
|
||||
*/
|
||||
|
||||
static int
|
||||
weechat_lua_log (lua_State *L)
|
||||
{
|
||||
const char *message, *channel_name, *server_name;
|
||||
int n;
|
||||
/* make gcc happy */
|
||||
(void) L;
|
||||
|
||||
if (!lua_current_script)
|
||||
{
|
||||
lua_plugin->printf_server (lua_plugin,
|
||||
"Lua error: unable to print message, "
|
||||
"script not initialized");
|
||||
lua_pushnumber (lua_current_interpreter, 0);
|
||||
return 1;
|
||||
}
|
||||
|
||||
message = NULL;
|
||||
channel_name = NULL;
|
||||
server_name = NULL;
|
||||
|
||||
n = lua_gettop (lua_current_interpreter);
|
||||
|
||||
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->printf_server (lua_plugin,
|
||||
"Lua error: wrong parameters for "
|
||||
"\"log\" function");
|
||||
lua_pushnumber (lua_current_interpreter, 0);
|
||||
return 1;
|
||||
}
|
||||
|
||||
lua_plugin->log (lua_plugin,
|
||||
(char *) server_name,
|
||||
(char *) channel_name,
|
||||
"%s", (char *) message);
|
||||
|
||||
lua_pushnumber (lua_current_interpreter, 1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_lua_command: send command to server
|
||||
*/
|
||||
@@ -1213,6 +1271,7 @@ const struct luaL_reg weechat_lua_funcs[] = {
|
||||
{ "register", weechat_lua_register},
|
||||
{ "print", weechat_lua_print},
|
||||
{ "print_infobar", weechat_lua_print_infobar},
|
||||
{ "log", weechat_lua_log},
|
||||
{ "command", weechat_lua_command},
|
||||
{ "add_message_handler", weechat_lua_add_message_handler},
|
||||
{ "add_command_handler", weechat_lua_add_command_handler},
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -247,6 +247,45 @@ weechat_python_print_infobar (PyObject *self, PyObject *args)
|
||||
return Py_BuildValue ("i", 1);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_python_log: log message in server/channel (current or specified ones)
|
||||
*/
|
||||
|
||||
static PyObject *
|
||||
weechat_python_log (PyObject *self, PyObject *args)
|
||||
{
|
||||
char *message, *channel_name, *server_name;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) self;
|
||||
|
||||
if (!python_current_script)
|
||||
{
|
||||
python_plugin->printf_server (python_plugin,
|
||||
"Python error: unable to log message, "
|
||||
"script not initialized");
|
||||
return Py_BuildValue ("i", 0);
|
||||
}
|
||||
|
||||
message = NULL;
|
||||
channel_name = NULL;
|
||||
server_name = NULL;
|
||||
|
||||
if (!PyArg_ParseTuple (args, "s|ss", &message, &channel_name, &server_name))
|
||||
{
|
||||
python_plugin->printf_server (python_plugin,
|
||||
"Python error: wrong parameters for "
|
||||
"\"log\" function");
|
||||
return Py_BuildValue ("i", 0);
|
||||
}
|
||||
|
||||
python_plugin->log (python_plugin,
|
||||
server_name, channel_name,
|
||||
"%s", message);
|
||||
|
||||
return Py_BuildValue ("i", 1);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_python_command: send command to server
|
||||
*/
|
||||
@@ -976,6 +1015,7 @@ PyMethodDef weechat_python_funcs[] = {
|
||||
{ "register", weechat_python_register, METH_VARARGS, "" },
|
||||
{ "prnt", weechat_python_print, METH_VARARGS, "" },
|
||||
{ "print_infobar", weechat_python_print_infobar, METH_VARARGS, "" },
|
||||
{ "log", weechat_python_log, METH_VARARGS, "" },
|
||||
{ "command", weechat_python_command, METH_VARARGS, "" },
|
||||
{ "add_message_handler", weechat_python_add_message_handler, METH_VARARGS, "" },
|
||||
{ "add_command_handler", weechat_python_add_command_handler, METH_VARARGS, "" },
|
||||
|
||||
@@ -319,6 +319,66 @@ weechat_ruby_print_infobar (VALUE class, VALUE delay, VALUE message)
|
||||
return INT2FIX (1);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_ruby_log: log message in server/channel (current or specified ones)
|
||||
*/
|
||||
|
||||
static VALUE
|
||||
weechat_ruby_log (int argc, VALUE *argv, VALUE class)
|
||||
{
|
||||
VALUE message, channel_name, server_name;
|
||||
char *c_message, *c_channel_name, *c_server_name;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) class;
|
||||
|
||||
if (!ruby_current_script)
|
||||
{
|
||||
ruby_plugin->printf_server (ruby_plugin,
|
||||
"Ruby error: unable to log message, "
|
||||
"script not initialized");
|
||||
return INT2FIX (0);
|
||||
}
|
||||
|
||||
message = Qnil;
|
||||
channel_name = Qnil;
|
||||
server_name = Qnil;
|
||||
c_message = NULL;
|
||||
c_channel_name = NULL;
|
||||
c_server_name = NULL;
|
||||
|
||||
rb_scan_args (argc, argv, "12", &message, &channel_name, &server_name);
|
||||
|
||||
if (NIL_P (message))
|
||||
{
|
||||
ruby_plugin->printf_server (ruby_plugin,
|
||||
"Ruby error: wrong parameters for "
|
||||
"\"log\" function");
|
||||
return INT2FIX (0);
|
||||
}
|
||||
|
||||
Check_Type (message, T_STRING);
|
||||
c_message = STR2CSTR (message);
|
||||
|
||||
if (!NIL_P (channel_name))
|
||||
{
|
||||
Check_Type (channel_name, T_STRING);
|
||||
c_channel_name = STR2CSTR (channel_name);
|
||||
}
|
||||
|
||||
if (!NIL_P (server_name))
|
||||
{
|
||||
Check_Type (server_name, T_STRING);
|
||||
c_server_name = STR2CSTR (server_name);
|
||||
}
|
||||
|
||||
ruby_plugin->log (ruby_plugin,
|
||||
c_server_name, c_channel_name,
|
||||
"%s", c_message);
|
||||
|
||||
return INT2FIX (1);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_ruby_command: send command to server
|
||||
*/
|
||||
@@ -1548,6 +1608,7 @@ weechat_plugin_init (t_weechat_plugin *plugin)
|
||||
rb_define_module_function (mWeechat, "register", weechat_ruby_register, 4);
|
||||
rb_define_module_function (mWeechat, "print", weechat_ruby_print, -1);
|
||||
rb_define_module_function (mWeechat, "print_infobar", weechat_ruby_print_infobar, 2);
|
||||
rb_define_module_function (mWeechat, "log", weechat_ruby_log, 2);
|
||||
rb_define_module_function (mWeechat, "command", weechat_ruby_command, -1);
|
||||
rb_define_module_function (mWeechat, "add_message_handler", weechat_ruby_add_message_handler, 2);
|
||||
rb_define_module_function (mWeechat, "add_command_handler", weechat_ruby_add_command_handler, -1);
|
||||
|
||||
Reference in New Issue
Block a user