1
0
mirror of https://github.com/weechat/weechat.git synced 2026-07-01 07:16:37 +02:00

add get_irc_color function in plugins/scripts

This commit is contained in:
Emmanuel Bouthenot
2006-06-10 21:34:16 +00:00
parent 08aa5570d8
commit b48fb5c0ec
8 changed files with 330 additions and 2 deletions
+43
View File
@@ -1504,6 +1504,48 @@ weechat_lua_get_nick_info (lua_State *L)
return 1;
}
/*
* weechat_lua_get_irc_color:
* get the numeric value which identify an irc color by its name
*/
static int
weechat_lua_get_irc_color (lua_State *L)
{
const char *color;
int n;
/* make gcc happy */
(void) L;
if (!lua_current_script)
{
lua_plugin->print_server (lua_plugin,
"Lua error: unable to get irc color, "
"script not initialized");
lua_pushnumber (lua_current_interpreter, -1);
return 1;
}
color = NULL;
n = lua_gettop (lua_current_interpreter);
if (n != 1)
{
lua_plugin->print_server (lua_plugin,
"Lua error: wrong parameters for "
"\"get_irc_color\" function");
lua_pushnumber (lua_current_interpreter, -1);
return 1;
}
color = lua_tostring (lua_current_interpreter, -1);
lua_pushnumber (lua_current_interpreter,
lua_plugin->get_irc_color (lua_plugin, (char *) color));
return 1;
}
/*
* Lua constant as functions
@@ -1587,6 +1629,7 @@ const struct luaL_reg weechat_lua_funcs[] = {
{ "get_server_info", weechat_lua_get_server_info},
{ "get_channel_info", weechat_lua_get_channel_info},
{ "get_nick_info", weechat_lua_get_nick_info},
{ "get_irc_color", weechat_lua_get_irc_color},
/* 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},
+45 -1
View File
@@ -1332,6 +1332,49 @@ static XS (XS_weechat_input_color)
XSRETURN_YES;
}
/*
* weechat::get_irc_color:
* get the numeric value which identify an irc color by its name
*/
static XS (XS_weechat_get_irc_color)
{
char *color;
unsigned int integer;
dXSARGS;
/* make gcc happy */
(void) cv;
if (!perl_current_script)
{
perl_plugin->print_server (perl_plugin,
"Perl error: unable to get irc color, "
"script not initialized");
XST_mIV (0, -1);
XSRETURN (1);
}
if (items != 1)
{
perl_plugin->print_server (perl_plugin,
"Perl error: wrong parameters for "
"\"get_irc_info\" function");
XST_mIV (0, -1);
XSRETURN (1);
}
color = SvPV (ST (0), integer);
if (color)
{
XST_mIV (0, perl_plugin->get_irc_color (perl_plugin, color));
XSRETURN (1);
}
XST_mIV (0, -1);
XSRETURN (-1);
}
/*
* weechat_perl_xs_init: initialize subroutines
*/
@@ -1367,7 +1410,8 @@ weechat_perl_xs_init (pTHX)
newXS ("weechat::get_channel_info", XS_weechat_get_channel_info, "weechat");
newXS ("weechat::get_nick_info", XS_weechat_get_nick_info, "weechat");
newXS ("weechat::input_color", XS_weechat_input_color, "weechat");
newXS ("weechat::get_irc_color", XS_weechat_get_irc_color, "weechat");
/* interface constants */
stash = gv_stashpv ("weechat", TRUE);
newCONSTSUB (stash, "weechat::PLUGIN_RC_KO", newSViv (PLUGIN_RC_KO));
@@ -1250,6 +1250,43 @@ weechat_python_get_nick_info (PyObject *self, PyObject *args)
return nick_hash;
}
/*
* weechat_python_get_irc_color:
* get the numeric value which identify an irc color by its name
*/
static PyObject *
weechat_python_get_irc_color (PyObject *self, PyObject *args)
{
char *color;
/* make gcc happy */
(void) self;
if (!python_current_script)
{
python_plugin->print_server (python_plugin,
"Python error: unable to get irc color, "
"script not initialized");
return Py_BuildValue ("i", -1);
}
color = NULL;
if (!PyArg_ParseTuple (args, "s", &color))
{
python_plugin->print_server (python_plugin,
"Python error: wrong parameters for "
"\"get_irc_color\" function");
return Py_BuildValue ("i", -1);
}
if (color)
return Py_BuildValue ("i", python_plugin->get_irc_color (python_plugin, color));
return Py_BuildValue ("i", -1);
}
/*
* Python subroutines
*/
@@ -1278,6 +1315,7 @@ PyMethodDef weechat_python_funcs[] = {
{ "get_server_info", weechat_python_get_server_info, METH_VARARGS, "" },
{ "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, "" },
{ NULL, NULL, 0, NULL }
};
+39
View File
@@ -1490,6 +1490,44 @@ weechat_ruby_get_nick_info (VALUE class, VALUE server, VALUE channel)
return nick_hash;
}
/*
* weechat_ruby_get_irc_color:
* get the numeric value which identify an irc color by its name
*/
static VALUE
weechat_ruby_get_irc_color (VALUE class, VALUE color)
{
char *c_color;
/* make gcc happy */
(void) class;
if (!ruby_current_script)
{
ruby_plugin->print_server (ruby_plugin,
"Ruby error: unable to get irc color, "
"script not initialized");
return INT2FIX (-1);
}
c_color = NULL;
if (NIL_P (color))
{
ruby_plugin->print_server (ruby_plugin,
"Ruby error: wrong parameters for "
"\"get_irc_color\" function");
return INT2FIX (-1);
}
Check_Type (color, T_STRING);
c_color = STR2CSTR (color);
return INT2FIX (ruby_plugin->get_irc_color (ruby_plugin, c_color));
}
/*
* weechat_ruby_output : redirection for stdout and stderr
*/
@@ -1952,6 +1990,7 @@ weechat_plugin_init (t_weechat_plugin *plugin)
rb_define_module_function (mWeechat, "get_server_info", weechat_ruby_get_server_info, 0);
rb_define_module_function (mWeechat, "get_channel_info", weechat_ruby_get_channel_info, 1);
rb_define_module_function (mWeechat, "get_nick_info", weechat_ruby_get_nick_info, 2);
rb_define_module_function (mWeechat, "get_irc_color", weechat_ruby_get_irc_color, 1);
/* redirect stdin and stdout */
mWeechatOutputs = rb_define_module("WeechatOutputs");