mirror of
https://github.com/weechat/weechat.git
synced 2026-06-25 20:36:38 +02:00
Add new hooks (info and infolist), IRC plugin now return infos and infolists
This commit is contained in:
@@ -3075,6 +3075,145 @@ weechat_lua_api_hook_modifier_exec (lua_State *L)
|
||||
LUA_RETURN_STRING_FREE(result);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_lua_api_hook_info_cb: callback for info hooked
|
||||
*/
|
||||
|
||||
char *
|
||||
weechat_lua_api_hook_info_cb (void *data, const char *info_name,
|
||||
const char *arguments)
|
||||
{
|
||||
struct t_script_callback *script_callback;
|
||||
char *lua_argv[3];
|
||||
|
||||
script_callback = (struct t_script_callback *)data;
|
||||
|
||||
lua_argv[0] = (char *)info_name;
|
||||
lua_argv[1] = (char *)arguments;
|
||||
lua_argv[2] = NULL;
|
||||
|
||||
return (char *)weechat_lua_exec (script_callback->script,
|
||||
WEECHAT_SCRIPT_EXEC_STRING,
|
||||
script_callback->function,
|
||||
lua_argv);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_lua_api_hook_info: hook an info
|
||||
*/
|
||||
|
||||
static int
|
||||
weechat_lua_api_hook_info (lua_State *L)
|
||||
{
|
||||
const char *info_name, *function;
|
||||
char *result;
|
||||
int n;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) L;
|
||||
|
||||
if (!lua_current_script)
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("hook_info");
|
||||
LUA_RETURN_EMPTY;
|
||||
}
|
||||
|
||||
info_name = NULL;
|
||||
function = NULL;
|
||||
|
||||
n = lua_gettop (lua_current_interpreter);
|
||||
|
||||
if (n < 2)
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("hook_info");
|
||||
LUA_RETURN_EMPTY;
|
||||
}
|
||||
|
||||
info_name = lua_tostring (lua_current_interpreter, -2);
|
||||
function = lua_tostring (lua_current_interpreter, -1);
|
||||
|
||||
result = script_ptr2str (script_api_hook_info (weechat_lua_plugin,
|
||||
lua_current_script,
|
||||
info_name,
|
||||
&weechat_lua_api_hook_info_cb,
|
||||
function));
|
||||
|
||||
LUA_RETURN_STRING_FREE(result);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_lua_api_hook_infolist_cb: callback for infolist hooked
|
||||
*/
|
||||
|
||||
struct t_infolist *
|
||||
weechat_lua_api_hook_infolist_cb (void *data, const char *info_name,
|
||||
void *pointer, const char *arguments)
|
||||
{
|
||||
struct t_script_callback *script_callback;
|
||||
char *lua_argv[4];
|
||||
struct t_infolist *value;
|
||||
|
||||
script_callback = (struct t_script_callback *)data;
|
||||
|
||||
lua_argv[0] = (char *)info_name;
|
||||
lua_argv[1] = script_ptr2str (pointer);
|
||||
lua_argv[2] = (char *)arguments;
|
||||
lua_argv[3] = NULL;
|
||||
|
||||
value = (struct t_infolist *)weechat_lua_exec (script_callback->script,
|
||||
WEECHAT_SCRIPT_EXEC_STRING,
|
||||
script_callback->function,
|
||||
lua_argv);
|
||||
|
||||
if (lua_argv[1])
|
||||
free (lua_argv[1]);
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_lua_api_hook_infolist: hook an infolist
|
||||
*/
|
||||
|
||||
static int
|
||||
weechat_lua_api_hook_infolist (lua_State *L)
|
||||
{
|
||||
const char *infolist_name, *function;
|
||||
char *result;
|
||||
int n;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) L;
|
||||
|
||||
if (!lua_current_script)
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("hook_infolist");
|
||||
LUA_RETURN_EMPTY;
|
||||
}
|
||||
|
||||
infolist_name = NULL;
|
||||
function = NULL;
|
||||
|
||||
n = lua_gettop (lua_current_interpreter);
|
||||
|
||||
if (n < 2)
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("hook_infolist");
|
||||
LUA_RETURN_EMPTY;
|
||||
}
|
||||
|
||||
infolist_name = lua_tostring (lua_current_interpreter, -2);
|
||||
function = lua_tostring (lua_current_interpreter, -1);
|
||||
|
||||
result = script_ptr2str (script_api_hook_infolist (weechat_lua_plugin,
|
||||
lua_current_script,
|
||||
infolist_name,
|
||||
&weechat_lua_api_hook_infolist_cb,
|
||||
function));
|
||||
|
||||
LUA_RETURN_STRING_FREE(result);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_lua_api_unhook: unhook something
|
||||
*/
|
||||
@@ -4308,7 +4447,7 @@ weechat_lua_api_command (lua_State *L)
|
||||
static int
|
||||
weechat_lua_api_info_get (lua_State *L)
|
||||
{
|
||||
const char *info;
|
||||
const char *info_name, *arguments;
|
||||
char *value;
|
||||
int n;
|
||||
|
||||
@@ -4321,19 +4460,21 @@ weechat_lua_api_info_get (lua_State *L)
|
||||
LUA_RETURN_EMPTY;
|
||||
}
|
||||
|
||||
info = NULL;
|
||||
info_name = NULL;
|
||||
arguments = NULL;
|
||||
|
||||
n = lua_gettop (lua_current_interpreter);
|
||||
|
||||
if (n < 1)
|
||||
|
||||
if (n < 2)
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("info_get");
|
||||
LUA_RETURN_EMPTY;
|
||||
}
|
||||
|
||||
info = lua_tostring (lua_current_interpreter, -1);
|
||||
|
||||
value = weechat_info_get (info);
|
||||
info_name = lua_tostring (lua_current_interpreter, -2);
|
||||
arguments = lua_tostring (lua_current_interpreter, -1);
|
||||
|
||||
value = weechat_info_get (info_name, arguments);
|
||||
|
||||
LUA_RETURN_STRING(value);
|
||||
}
|
||||
@@ -5017,6 +5158,8 @@ const struct luaL_reg weechat_lua_api_funcs[] = {
|
||||
{ "hook_completion_list_add", &weechat_lua_api_hook_completion_list_add },
|
||||
{ "hook_modifier", &weechat_lua_api_hook_modifier },
|
||||
{ "hook_modifier_exec", &weechat_lua_api_hook_modifier_exec },
|
||||
{ "hook_info", &weechat_lua_api_hook_info },
|
||||
{ "hook_infolist", &weechat_lua_api_hook_infolist },
|
||||
{ "unhook", &weechat_lua_api_unhook },
|
||||
{ "unhook_all", &weechat_lua_api_unhook_all },
|
||||
{ "buffer_new", &weechat_lua_api_buffer_new },
|
||||
|
||||
@@ -2568,6 +2568,129 @@ static XS (XS_weechat_hook_modifier_exec)
|
||||
PERL_RETURN_STRING_FREE(result);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_perl_api_hook_info_cb: callback for info hooked
|
||||
*/
|
||||
|
||||
char *
|
||||
weechat_perl_api_hook_info_cb (void *data, const char *info_name,
|
||||
const char *arguments)
|
||||
{
|
||||
struct t_script_callback *script_callback;
|
||||
char *perl_argv[3];
|
||||
|
||||
script_callback = (struct t_script_callback *)data;
|
||||
|
||||
perl_argv[0] = (char *)info_name;
|
||||
perl_argv[1] = (char *)arguments;
|
||||
perl_argv[2] = NULL;
|
||||
|
||||
return (char *)weechat_perl_exec (script_callback->script,
|
||||
WEECHAT_SCRIPT_EXEC_STRING,
|
||||
script_callback->function,
|
||||
perl_argv);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat::hook_info: hook an info
|
||||
*/
|
||||
|
||||
static XS (XS_weechat_hook_info)
|
||||
{
|
||||
char *result, *info_name, *perl_fn;
|
||||
dXSARGS;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) cv;
|
||||
|
||||
if (!perl_current_script)
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("hook_info");
|
||||
PERL_RETURN_EMPTY;
|
||||
}
|
||||
|
||||
if (items < 2)
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("hook_info");
|
||||
PERL_RETURN_EMPTY;
|
||||
}
|
||||
|
||||
info_name = SvPV (ST (0), PL_na);
|
||||
perl_fn = SvPV (ST (1), PL_na);
|
||||
result = script_ptr2str (script_api_hook_info (weechat_perl_plugin,
|
||||
perl_current_script,
|
||||
info_name,
|
||||
&weechat_perl_api_hook_info_cb,
|
||||
perl_fn));
|
||||
|
||||
PERL_RETURN_STRING_FREE(result);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_perl_api_hook_infolist_cb: callback for infolist hooked
|
||||
*/
|
||||
|
||||
struct t_infolist *
|
||||
weechat_perl_api_hook_infolist_cb (void *data, const char *infolist_name,
|
||||
void *pointer, const char *arguments)
|
||||
{
|
||||
struct t_script_callback *script_callback;
|
||||
char *perl_argv[4];
|
||||
struct t_infolist *value;
|
||||
|
||||
script_callback = (struct t_script_callback *)data;
|
||||
|
||||
perl_argv[0] = (char *)infolist_name;
|
||||
perl_argv[1] = script_ptr2str (pointer);
|
||||
perl_argv[2] = (char *)arguments;
|
||||
perl_argv[3] = NULL;
|
||||
|
||||
value = (struct t_infolist *)weechat_perl_exec (script_callback->script,
|
||||
WEECHAT_SCRIPT_EXEC_STRING,
|
||||
script_callback->function,
|
||||
perl_argv);
|
||||
|
||||
if (perl_argv[1])
|
||||
free (perl_argv[1]);
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat::hook_infolist: hook an infolist
|
||||
*/
|
||||
|
||||
static XS (XS_weechat_hook_infolist)
|
||||
{
|
||||
char *result, *infolist_name, *perl_fn;
|
||||
dXSARGS;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) cv;
|
||||
|
||||
if (!perl_current_script)
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("hook_infolist");
|
||||
PERL_RETURN_EMPTY;
|
||||
}
|
||||
|
||||
if (items < 2)
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("hook_infolist");
|
||||
PERL_RETURN_EMPTY;
|
||||
}
|
||||
|
||||
infolist_name = SvPV (ST (0), PL_na);
|
||||
perl_fn = SvPV (ST (1), PL_na);
|
||||
result = script_ptr2str (script_api_hook_infolist (weechat_perl_plugin,
|
||||
perl_current_script,
|
||||
infolist_name,
|
||||
&weechat_perl_api_hook_infolist_cb,
|
||||
perl_fn));
|
||||
|
||||
PERL_RETURN_STRING_FREE(result);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat::unhook: unhook something
|
||||
*/
|
||||
@@ -3578,13 +3701,14 @@ static XS (XS_weechat_info_get)
|
||||
PERL_RETURN_EMPTY;
|
||||
}
|
||||
|
||||
if (items < 1)
|
||||
if (items < 2)
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("info_get");
|
||||
PERL_RETURN_EMPTY;
|
||||
}
|
||||
|
||||
value = weechat_info_get (SvPV (ST (0), PL_na));
|
||||
value = weechat_info_get (SvPV (ST (0), PL_na),
|
||||
SvPV (ST (1), PL_na));
|
||||
|
||||
PERL_RETURN_STRING(value);
|
||||
}
|
||||
@@ -3940,6 +4064,8 @@ weechat_perl_api_init (pTHX)
|
||||
newXS ("weechat::hook_completion_list_add", XS_weechat_hook_completion_list_add, "weechat");
|
||||
newXS ("weechat::hook_modifier", XS_weechat_hook_modifier, "weechat");
|
||||
newXS ("weechat::hook_modifier_exec", XS_weechat_hook_modifier_exec, "weechat");
|
||||
newXS ("weechat::hook_info", XS_weechat_hook_info, "weechat");
|
||||
newXS ("weechat::hook_infolist", XS_weechat_hook_infolist, "weechat");
|
||||
newXS ("weechat::unhook", XS_weechat_unhook, "weechat");
|
||||
newXS ("weechat::unhook_all", XS_weechat_unhook_all, "weechat");
|
||||
newXS ("weechat::buffer_new", XS_weechat_buffer_new, "weechat");
|
||||
|
||||
@@ -2724,6 +2724,133 @@ weechat_python_api_hook_modifier_exec (PyObject *self, PyObject *args)
|
||||
PYTHON_RETURN_STRING_FREE(result);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_python_api_hook_info_cb: callback for info hooked
|
||||
*/
|
||||
|
||||
char *
|
||||
weechat_python_api_hook_info_cb (void *data, const char *info_name,
|
||||
const char *arguments)
|
||||
{
|
||||
struct t_script_callback *script_callback;
|
||||
char *python_argv[3];
|
||||
|
||||
script_callback = (struct t_script_callback *)data;
|
||||
|
||||
python_argv[0] = (char *)info_name;
|
||||
python_argv[1] = (char *)arguments;
|
||||
python_argv[2] = NULL;
|
||||
|
||||
return (char *)weechat_python_exec (script_callback->script,
|
||||
WEECHAT_SCRIPT_EXEC_STRING,
|
||||
script_callback->function,
|
||||
python_argv);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_python_api_hook_info: hook an info
|
||||
*/
|
||||
|
||||
static PyObject *
|
||||
weechat_python_api_hook_info (PyObject *self, PyObject *args)
|
||||
{
|
||||
char *info_name, *function, *result;
|
||||
PyObject *object;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) self;
|
||||
|
||||
if (!python_current_script)
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("hook_info");
|
||||
PYTHON_RETURN_EMPTY;
|
||||
}
|
||||
|
||||
info_name = NULL;
|
||||
function = NULL;
|
||||
|
||||
if (!PyArg_ParseTuple (args, "ss", &info_name, &function))
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("hook_info");
|
||||
PYTHON_RETURN_EMPTY;
|
||||
}
|
||||
|
||||
result = script_ptr2str(script_api_hook_info (weechat_python_plugin,
|
||||
python_current_script,
|
||||
info_name,
|
||||
&weechat_python_api_hook_info_cb,
|
||||
function));
|
||||
|
||||
PYTHON_RETURN_STRING_FREE(result);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_python_api_hook_infolist_cb: callback for infolist hooked
|
||||
*/
|
||||
|
||||
struct t_infolist *
|
||||
weechat_python_api_hook_infolist_cb (void *data, const char *infolist_name,
|
||||
void *pointer, const char *arguments)
|
||||
{
|
||||
struct t_script_callback *script_callback;
|
||||
char *python_argv[4];
|
||||
struct t_infolist *value;
|
||||
|
||||
script_callback = (struct t_script_callback *)data;
|
||||
|
||||
python_argv[0] = (char *)infolist_name;
|
||||
python_argv[1] = script_ptr2str (pointer);
|
||||
python_argv[2] = (char *)arguments;
|
||||
python_argv[3] = NULL;
|
||||
|
||||
value = (struct t_infolist *)weechat_python_exec (script_callback->script,
|
||||
WEECHAT_SCRIPT_EXEC_STRING,
|
||||
script_callback->function,
|
||||
python_argv);
|
||||
|
||||
if (python_argv[1])
|
||||
free (python_argv[1]);
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_python_api_hook_infolist: hook an infolist
|
||||
*/
|
||||
|
||||
static PyObject *
|
||||
weechat_python_api_hook_infolist (PyObject *self, PyObject *args)
|
||||
{
|
||||
char *infolist_name, *function, *result;
|
||||
PyObject *object;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) self;
|
||||
|
||||
if (!python_current_script)
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("hook_infolist");
|
||||
PYTHON_RETURN_EMPTY;
|
||||
}
|
||||
|
||||
infolist_name = NULL;
|
||||
function = NULL;
|
||||
|
||||
if (!PyArg_ParseTuple (args, "ss", &infolist_name, &function))
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("hook_infolist");
|
||||
PYTHON_RETURN_EMPTY;
|
||||
}
|
||||
|
||||
result = script_ptr2str(script_api_hook_infolist (weechat_python_plugin,
|
||||
python_current_script,
|
||||
infolist_name,
|
||||
&weechat_python_api_hook_infolist_cb,
|
||||
function));
|
||||
|
||||
PYTHON_RETURN_STRING_FREE(result);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_python_api_unhook: unhook something
|
||||
*/
|
||||
@@ -3794,7 +3921,7 @@ weechat_python_api_command (PyObject *self, PyObject *args)
|
||||
static PyObject *
|
||||
weechat_python_api_info_get (PyObject *self, PyObject *args)
|
||||
{
|
||||
char *info, *value;
|
||||
char *info_name, *arguments, *value;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) self;
|
||||
@@ -3805,15 +3932,15 @@ weechat_python_api_info_get (PyObject *self, PyObject *args)
|
||||
PYTHON_RETURN_EMPTY;
|
||||
}
|
||||
|
||||
info = NULL;
|
||||
info_name = NULL;
|
||||
|
||||
if (!PyArg_ParseTuple (args, "s", &info))
|
||||
if (!PyArg_ParseTuple (args, "ss", &info_name, &arguments))
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("info_get");
|
||||
PYTHON_RETURN_EMPTY;
|
||||
}
|
||||
|
||||
value = weechat_info_get (info);
|
||||
value = weechat_info_get (info_name, arguments);
|
||||
|
||||
PYTHON_RETURN_STRING(value);
|
||||
}
|
||||
@@ -4184,6 +4311,8 @@ PyMethodDef weechat_python_funcs[] =
|
||||
{ "hook_completion_list_add", &weechat_python_api_hook_completion_list_add, METH_VARARGS, "" },
|
||||
{ "hook_modifier", &weechat_python_api_hook_modifier, METH_VARARGS, "" },
|
||||
{ "hook_modifier_exec", &weechat_python_api_hook_modifier_exec, METH_VARARGS, "" },
|
||||
{ "hook_info", &weechat_python_api_hook_info, METH_VARARGS, "" },
|
||||
{ "hook_infolist", &weechat_python_api_hook_infolist, METH_VARARGS, "" },
|
||||
{ "unhook", &weechat_python_api_unhook, METH_VARARGS, "" },
|
||||
{ "unhook_all", &weechat_python_api_unhook_all, METH_VARARGS, "" },
|
||||
{ "buffer_new", &weechat_python_api_buffer_new, METH_VARARGS, "" },
|
||||
|
||||
@@ -314,7 +314,7 @@ weechat_python_load (const char *filename)
|
||||
|
||||
/* adding $weechat_dir/python in $PYTHONPATH */
|
||||
python_path = PySys_GetObject ("path");
|
||||
w_home = weechat_info_get ("weechat_dir");
|
||||
w_home = weechat_info_get ("weechat_dir", "");
|
||||
if (w_home)
|
||||
{
|
||||
len = strlen (w_home) + 1 + strlen("python") + 1;
|
||||
|
||||
@@ -3134,6 +3134,145 @@ weechat_ruby_api_hook_modifier_exec (VALUE class, VALUE modifier,
|
||||
RUBY_RETURN_STRING_FREE(result);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_ruby_api_hook_info_cb: callback for info hooked
|
||||
*/
|
||||
|
||||
char *
|
||||
weechat_ruby_api_hook_info_cb (void *data, const char *info_name,
|
||||
const char *arguments)
|
||||
{
|
||||
struct t_script_callback *script_callback;
|
||||
char *ruby_argv[3];
|
||||
|
||||
script_callback = (struct t_script_callback *)data;
|
||||
|
||||
ruby_argv[0] = (char *)info_name;
|
||||
ruby_argv[1] = (char *)arguments;
|
||||
ruby_argv[2] = NULL;
|
||||
|
||||
return (char *)weechat_ruby_exec (script_callback->script,
|
||||
WEECHAT_SCRIPT_EXEC_STRING,
|
||||
script_callback->function,
|
||||
ruby_argv);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_ruby_api_hook_info: hook an info
|
||||
*/
|
||||
|
||||
static VALUE
|
||||
weechat_ruby_api_hook_info (VALUE class, VALUE info_name, VALUE function)
|
||||
{
|
||||
char *c_info_name, *c_function, *result;
|
||||
VALUE return_value;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) class;
|
||||
|
||||
if (!ruby_current_script)
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("hook_info");
|
||||
RUBY_RETURN_EMPTY;
|
||||
}
|
||||
|
||||
c_info_name = NULL;
|
||||
c_function = NULL;
|
||||
|
||||
if (NIL_P (info_name) || NIL_P (function))
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("hook_info");
|
||||
RUBY_RETURN_EMPTY;
|
||||
}
|
||||
|
||||
Check_Type (info_name, T_STRING);
|
||||
Check_Type (function, T_STRING);
|
||||
|
||||
c_info_name = STR2CSTR (info_name);
|
||||
c_function = STR2CSTR (function);
|
||||
|
||||
result = script_ptr2str (script_api_hook_info (weechat_ruby_plugin,
|
||||
ruby_current_script,
|
||||
c_info_name,
|
||||
&weechat_ruby_api_hook_info_cb,
|
||||
c_function));
|
||||
|
||||
RUBY_RETURN_STRING_FREE(result);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_ruby_api_hook_infolist_cb: callback for infolist hooked
|
||||
*/
|
||||
|
||||
struct t_infolist *
|
||||
weechat_ruby_api_hook_infolist_cb (void *data, const char *infolist_name,
|
||||
void *pointer, const char *arguments)
|
||||
{
|
||||
struct t_script_callback *script_callback;
|
||||
char *ruby_argv[4];
|
||||
struct t_infolist *value;
|
||||
|
||||
script_callback = (struct t_script_callback *)data;
|
||||
|
||||
ruby_argv[0] = (char *)infolist_name;
|
||||
ruby_argv[1] = script_ptr2str (pointer);
|
||||
ruby_argv[2] = (char *)arguments;
|
||||
ruby_argv[3] = NULL;
|
||||
|
||||
value = (struct t_infolist *)weechat_ruby_exec (script_callback->script,
|
||||
WEECHAT_SCRIPT_EXEC_STRING,
|
||||
script_callback->function,
|
||||
ruby_argv);
|
||||
|
||||
if (ruby_argv[1])
|
||||
free (ruby_argv[1]);
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_ruby_api_hook_infolist: hook an infolist
|
||||
*/
|
||||
|
||||
static VALUE
|
||||
weechat_ruby_api_hook_infolist (VALUE class, VALUE infolist_name, VALUE function)
|
||||
{
|
||||
char *c_infolist_name, *c_function, *result;
|
||||
VALUE return_value;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) class;
|
||||
|
||||
if (!ruby_current_script)
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("hook_infolist");
|
||||
RUBY_RETURN_EMPTY;
|
||||
}
|
||||
|
||||
c_infolist_name = NULL;
|
||||
c_function = NULL;
|
||||
|
||||
if (NIL_P (infolist_name) || NIL_P (function))
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("hook_infolist");
|
||||
RUBY_RETURN_EMPTY;
|
||||
}
|
||||
|
||||
Check_Type (infolist_name, T_STRING);
|
||||
Check_Type (function, T_STRING);
|
||||
|
||||
c_infolist_name = STR2CSTR (infolist_name);
|
||||
c_function = STR2CSTR (function);
|
||||
|
||||
result = script_ptr2str (script_api_hook_infolist (weechat_ruby_plugin,
|
||||
ruby_current_script,
|
||||
c_infolist_name,
|
||||
&weechat_ruby_api_hook_infolist_cb,
|
||||
c_function));
|
||||
|
||||
RUBY_RETURN_STRING_FREE(result);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_ruby_api_unhook: unhook something
|
||||
*/
|
||||
@@ -4376,9 +4515,9 @@ weechat_ruby_api_command (VALUE class, VALUE buffer, VALUE command)
|
||||
*/
|
||||
|
||||
static VALUE
|
||||
weechat_ruby_api_info_get (VALUE class, VALUE info)
|
||||
weechat_ruby_api_info_get (VALUE class, VALUE info_name, VALUE arguments)
|
||||
{
|
||||
char *c_info, *value;
|
||||
char *c_info_name, *c_arguments, *value;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) class;
|
||||
@@ -4389,17 +4528,19 @@ weechat_ruby_api_info_get (VALUE class, VALUE info)
|
||||
RUBY_RETURN_EMPTY;
|
||||
}
|
||||
|
||||
if (NIL_P (info))
|
||||
if (NIL_P (info_name) || NIL_P (arguments))
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("info_get");
|
||||
RUBY_RETURN_EMPTY;
|
||||
}
|
||||
|
||||
Check_Type (info, T_STRING);
|
||||
Check_Type (info_name, T_STRING);
|
||||
Check_Type (arguments, T_STRING);
|
||||
|
||||
c_info = STR2CSTR (info);
|
||||
|
||||
value = weechat_info_get (c_info);
|
||||
c_info_name = STR2CSTR (info_name);
|
||||
c_arguments = STR2CSTR (arguments);
|
||||
|
||||
value = weechat_info_get (c_info_name, c_arguments);
|
||||
|
||||
RUBY_RETURN_STRING(value);
|
||||
}
|
||||
@@ -4823,6 +4964,8 @@ weechat_ruby_api_init (VALUE ruby_mWeechat)
|
||||
rb_define_module_function (ruby_mWeechat, "hook_completion_list_add", &weechat_ruby_api_hook_completion_list_add, 4);
|
||||
rb_define_module_function (ruby_mWeechat, "hook_modifier", &weechat_ruby_api_hook_modifier, 2);
|
||||
rb_define_module_function (ruby_mWeechat, "hook_modifier_exec", &weechat_ruby_api_hook_modifier_exec, 3);
|
||||
rb_define_module_function (ruby_mWeechat, "hook_info", &weechat_ruby_api_hook_info, 2);
|
||||
rb_define_module_function (ruby_mWeechat, "hook_infolist", &weechat_ruby_api_hook_infolist, 2);
|
||||
rb_define_module_function (ruby_mWeechat, "unhook", &weechat_ruby_api_unhook, 1);
|
||||
rb_define_module_function (ruby_mWeechat, "unhook_all", &weechat_ruby_api_unhook_all, 0);
|
||||
rb_define_module_function (ruby_mWeechat, "buffer_new", &weechat_ruby_api_buffer_new, 4);
|
||||
@@ -4850,7 +4993,7 @@ weechat_ruby_api_init (VALUE ruby_mWeechat)
|
||||
rb_define_module_function (ruby_mWeechat, "bar_update", &weechat_ruby_api_bar_update, 1);
|
||||
rb_define_module_function (ruby_mWeechat, "bar_remove", &weechat_ruby_api_bar_remove, 1);
|
||||
rb_define_module_function (ruby_mWeechat, "command", &weechat_ruby_api_command, 2);
|
||||
rb_define_module_function (ruby_mWeechat, "info_get", &weechat_ruby_api_info_get, 1);
|
||||
rb_define_module_function (ruby_mWeechat, "info_get", &weechat_ruby_api_info_get, 2);
|
||||
rb_define_module_function (ruby_mWeechat, "infolist_get", &weechat_ruby_api_infolist_get, 3);
|
||||
rb_define_module_function (ruby_mWeechat, "infolist_next", &weechat_ruby_api_infolist_next, 1);
|
||||
rb_define_module_function (ruby_mWeechat, "infolist_prev", &weechat_ruby_api_infolist_prev, 1);
|
||||
|
||||
@@ -875,6 +875,84 @@ script_api_hook_modifier (struct t_weechat_plugin *weechat_plugin,
|
||||
return new_hook;
|
||||
}
|
||||
|
||||
/*
|
||||
* script_api_hook_info: hook an info
|
||||
* return new hook, NULL if error
|
||||
*/
|
||||
|
||||
struct t_hook *
|
||||
script_api_hook_info (struct t_weechat_plugin *weechat_plugin,
|
||||
struct t_plugin_script *script,
|
||||
const char *info_name,
|
||||
char *(*callback)(void *data,
|
||||
const char *info_name,
|
||||
const char *arguments),
|
||||
const char *function)
|
||||
{
|
||||
struct t_script_callback *new_script_callback;
|
||||
struct t_hook *new_hook;
|
||||
|
||||
new_script_callback = script_callback_alloc ();
|
||||
if (!new_script_callback)
|
||||
return NULL;
|
||||
|
||||
new_hook = weechat_hook_info (info_name, callback, new_script_callback);
|
||||
if (!new_hook)
|
||||
{
|
||||
script_callback_free_data (new_script_callback);
|
||||
free (new_script_callback);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
new_script_callback->script = script;
|
||||
new_script_callback->function = strdup (function);
|
||||
new_script_callback->hook = new_hook;
|
||||
|
||||
script_callback_add (script, new_script_callback);
|
||||
|
||||
return new_hook;
|
||||
}
|
||||
|
||||
/*
|
||||
* script_api_hook_infolist: hook an infolist
|
||||
* return new hook, NULL if error
|
||||
*/
|
||||
|
||||
struct t_hook *
|
||||
script_api_hook_infolist (struct t_weechat_plugin *weechat_plugin,
|
||||
struct t_plugin_script *script,
|
||||
const char *infolist_name,
|
||||
struct t_infolist *(*callback)(void *data,
|
||||
const char *infolist_name,
|
||||
void *pointer,
|
||||
const char *arguments),
|
||||
const char *function)
|
||||
{
|
||||
struct t_script_callback *new_script_callback;
|
||||
struct t_hook *new_hook;
|
||||
|
||||
new_script_callback = script_callback_alloc ();
|
||||
if (!new_script_callback)
|
||||
return NULL;
|
||||
|
||||
new_hook = weechat_hook_infolist (infolist_name,
|
||||
callback, new_script_callback);
|
||||
if (!new_hook)
|
||||
{
|
||||
script_callback_free_data (new_script_callback);
|
||||
free (new_script_callback);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
new_script_callback->script = script;
|
||||
new_script_callback->function = strdup (function);
|
||||
new_script_callback->hook = new_hook;
|
||||
|
||||
script_callback_add (script, new_script_callback);
|
||||
|
||||
return new_hook;
|
||||
}
|
||||
|
||||
/*
|
||||
* script_api_unhook: unhook something
|
||||
*/
|
||||
|
||||
@@ -150,6 +150,21 @@ extern struct t_hook *script_api_hook_modifier (struct t_weechat_plugin *weechat
|
||||
const char *modifier_data,
|
||||
const char *string),
|
||||
const char *function);
|
||||
extern struct t_hook *script_api_hook_info (struct t_weechat_plugin *weechat_plugin,
|
||||
struct t_plugin_script *script,
|
||||
const char *info_name,
|
||||
char *(*callback)(void *data,
|
||||
const char *info_name,
|
||||
const char *arguments),
|
||||
const char *function);
|
||||
extern struct t_hook *script_api_hook_infolist (struct t_weechat_plugin *weechat_plugin,
|
||||
struct t_plugin_script *script,
|
||||
const char *infolist_name,
|
||||
struct t_infolist *(*callback)(void *data,
|
||||
const char *infolist_name,
|
||||
void *pointer,
|
||||
const char *arguments),
|
||||
const char *function);
|
||||
extern void script_api_unhook (struct t_weechat_plugin *weechat_plugin,
|
||||
struct t_plugin_script *script,
|
||||
struct t_hook *hook);
|
||||
|
||||
@@ -214,7 +214,7 @@ script_auto_load (struct t_weechat_plugin *weechat_plugin,
|
||||
int dir_length;
|
||||
|
||||
/* build directory, adding WeeChat home */
|
||||
dir_home = weechat_info_get ("weechat_dir");
|
||||
dir_home = weechat_info_get ("weechat_dir", "");
|
||||
if (!dir_home)
|
||||
return;
|
||||
dir_length = strlen (dir_home) + strlen (weechat_plugin->name) + 16;
|
||||
@@ -277,7 +277,7 @@ script_search_full_name (struct t_weechat_plugin *weechat_plugin,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
dir_home = weechat_info_get ("weechat_dir");
|
||||
dir_home = weechat_info_get ("weechat_dir", "");
|
||||
if (dir_home)
|
||||
{
|
||||
/* try WeeChat user's autoload dir */
|
||||
@@ -321,7 +321,7 @@ script_search_full_name (struct t_weechat_plugin *weechat_plugin,
|
||||
}
|
||||
|
||||
/* try WeeChat system dir */
|
||||
dir_system = weechat_info_get ("weechat_sharedir");
|
||||
dir_system = weechat_info_get ("weechat_sharedir", "");
|
||||
if (dir_system)
|
||||
{
|
||||
length = strlen (dir_system) + strlen (weechat_plugin->name) +
|
||||
|
||||
Reference in New Issue
Block a user