1
0
mirror of https://github.com/weechat/weechat.git synced 2026-06-25 20:36:38 +02:00

Add new functions in plugin API: hook_hsignal and hook_hsignal_send

This commit is contained in:
Sebastien Helleu
2010-10-23 08:58:18 +02:00
parent 6e126937bc
commit 0cf04dca7c
15 changed files with 1179 additions and 9 deletions
+131
View File
@@ -4121,6 +4121,135 @@ weechat_lua_api_hook_signal_send (lua_State *L)
LUA_RETURN_ERROR;
}
/*
* weechat_lua_api_hook_hsignal_cb: callback for hsignal hooked
*/
int
weechat_lua_api_hook_hsignal_cb (void *data, const char *signal,
struct t_hashtable *hashtable)
{
struct t_script_callback *script_callback;
void *lua_argv[3];
char empty_arg[1] = { '\0' };
int *rc, ret;
script_callback = (struct t_script_callback *)data;
if (script_callback && script_callback->function && script_callback->function[0])
{
lua_argv[0] = (script_callback->data) ? script_callback->data : empty_arg;
lua_argv[1] = (signal) ? (char *)signal : empty_arg;
lua_argv[2] = hashtable;
rc = (int *) weechat_lua_exec (script_callback->script,
WEECHAT_SCRIPT_EXEC_INT,
script_callback->function,
"ssh", lua_argv);
if (!rc)
ret = WEECHAT_RC_ERROR;
else
{
ret = *rc;
free (rc);
}
return ret;
}
return WEECHAT_RC_ERROR;
}
/*
* weechat_lua_api_hook_hsignal: hook a hsignal
*/
static int
weechat_lua_api_hook_hsignal (lua_State *L)
{
const char *signal, *function, *data;
char *result;
int n;
/* make C compiler happy */
(void) L;
if (!lua_current_script || !lua_current_script->name)
{
WEECHAT_SCRIPT_MSG_NOT_INIT(LUA_CURRENT_SCRIPT_NAME, "hook_hsignal");
LUA_RETURN_EMPTY;
}
signal = NULL;
function = NULL;
data = NULL;
n = lua_gettop (lua_current_interpreter);
if (n < 3)
{
WEECHAT_SCRIPT_MSG_WRONG_ARGS(LUA_CURRENT_SCRIPT_NAME, "hook_hsignal");
LUA_RETURN_EMPTY;
}
signal = lua_tostring (lua_current_interpreter, -3);
function = lua_tostring (lua_current_interpreter, -2);
data = lua_tostring (lua_current_interpreter, -1);
result = script_ptr2str (script_api_hook_hsignal (weechat_lua_plugin,
lua_current_script,
signal,
&weechat_lua_api_hook_hsignal_cb,
function,
data));
LUA_RETURN_STRING_FREE(result);
}
/*
* weechat_lua_api_hook_hsignal_send: send a hsignal
*/
static int
weechat_lua_api_hook_hsignal_send (lua_State *L)
{
const char *signal;
struct t_hashtable *hashtable;
int n;
/* make C compiler happy */
(void) L;
if (!lua_current_script || !lua_current_script->name)
{
WEECHAT_SCRIPT_MSG_NOT_INIT(LUA_CURRENT_SCRIPT_NAME, "hook_hsignal_send");
LUA_RETURN_ERROR;
}
signal = NULL;
hashtable = NULL;
n = lua_gettop (lua_current_interpreter);
if (n < 2)
{
WEECHAT_SCRIPT_MSG_WRONG_ARGS(LUA_CURRENT_SCRIPT_NAME, "hook_hsignal_send");
LUA_RETURN_ERROR;
}
signal = lua_tostring (lua_current_interpreter, -2);
hashtable = weechat_lua_tohashtable (lua_current_interpreter, -1,
WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE);
weechat_hook_hsignal_send (signal, hashtable);
if (hashtable)
weechat_hashtable_free (hashtable);
LUA_RETURN_OK;
}
/*
* weechat_lua_api_hook_config_cb: callback for config option hooked
*/
@@ -7683,6 +7812,8 @@ const struct luaL_reg weechat_lua_api_funcs[] = {
{ "hook_print", &weechat_lua_api_hook_print },
{ "hook_signal", &weechat_lua_api_hook_signal },
{ "hook_signal_send", &weechat_lua_api_hook_signal_send },
{ "hook_hsignal", &weechat_lua_api_hook_hsignal },
{ "hook_hsignal_send", &weechat_lua_api_hook_hsignal_send },
{ "hook_config", &weechat_lua_api_hook_config },
{ "hook_completion", &weechat_lua_api_hook_completion },
{ "hook_completion_list_add", &weechat_lua_api_hook_completion_list_add },
+117
View File
@@ -3486,6 +3486,121 @@ XS (XS_weechat_api_hook_signal_send)
PERL_RETURN_ERROR;
}
/*
* weechat_perl_api_hook_hsignal_cb: callback for hsignal hooked
*/
int
weechat_perl_api_hook_hsignal_cb (void *data, const char *signal,
struct t_hashtable *hashtable)
{
struct t_script_callback *script_callback;
void *perl_argv[3];
char empty_arg[1] = { '\0' };
int *rc, ret;
script_callback = (struct t_script_callback *)data;
if (script_callback && script_callback->function && script_callback->function[0])
{
perl_argv[0] = (script_callback->data) ? script_callback->data : empty_arg;
perl_argv[1] = (signal) ? (char *)signal : empty_arg;
perl_argv[2] = hashtable;
rc = (int *) weechat_perl_exec (script_callback->script,
WEECHAT_SCRIPT_EXEC_INT,
script_callback->function,
"ssh", perl_argv);
if (!rc)
ret = WEECHAT_RC_ERROR;
else
{
ret = *rc;
free (rc);
}
return ret;
}
return WEECHAT_RC_ERROR;
}
/*
* weechat::hook_hsignal: hook a hsignal
*/
XS (XS_weechat_api_hook_hsignal)
{
char *result, *signal, *function, *data;
dXSARGS;
/* make C compiler happy */
(void) cv;
if (!perl_current_script || !perl_current_script->name)
{
WEECHAT_SCRIPT_MSG_NOT_INIT(PERL_CURRENT_SCRIPT_NAME, "hook_hsignal");
PERL_RETURN_EMPTY;
}
if (items < 3)
{
WEECHAT_SCRIPT_MSG_WRONG_ARGS(PERL_CURRENT_SCRIPT_NAME, "hook_hsignal");
PERL_RETURN_EMPTY;
}
signal = SvPV (ST (0), PL_na);
function = SvPV (ST (1), PL_na);
data = SvPV (ST (2), PL_na);
result = script_ptr2str (script_api_hook_hsignal (weechat_perl_plugin,
perl_current_script,
signal,
&weechat_perl_api_hook_hsignal_cb,
function,
data));
PERL_RETURN_STRING_FREE(result);
}
/*
* weechat::hook_hsignal_send: send a hsignal
*/
XS (XS_weechat_api_hook_hsignal_send)
{
char *signal;
struct t_hashtable *hashtable;
dXSARGS;
/* make C compiler happy */
(void) cv;
if (!perl_current_script || !perl_current_script->name)
{
WEECHAT_SCRIPT_MSG_NOT_INIT(PERL_CURRENT_SCRIPT_NAME, "hook_hsignal_send");
PERL_RETURN_ERROR;
}
if (items < 2)
{
WEECHAT_SCRIPT_MSG_WRONG_ARGS(PERL_CURRENT_SCRIPT_NAME, "hook_hsignal_send");
PERL_RETURN_ERROR;
}
signal = SvPV (ST (0), PL_na);
hashtable = weechat_perl_hash_to_hashtable (ST (1),
WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE);
weechat_hook_hsignal_send (signal, hashtable);
if (hashtable)
weechat_hashtable_free (hashtable);
PERL_RETURN_OK;
}
/*
* weechat_perl_api_hook_config_cb: callback for config option hooked
*/
@@ -6176,6 +6291,8 @@ weechat_perl_api_init (pTHX)
newXS ("weechat::hook_print", XS_weechat_api_hook_print, "weechat");
newXS ("weechat::hook_signal", XS_weechat_api_hook_signal, "weechat");
newXS ("weechat::hook_signal_send", XS_weechat_api_hook_signal_send, "weechat");
newXS ("weechat::hook_hsignal", XS_weechat_api_hook_hsignal, "weechat");
newXS ("weechat::hook_hsignal_send", XS_weechat_api_hook_hsignal_send, "weechat");
newXS ("weechat::hook_config", XS_weechat_api_hook_config, "weechat");
newXS ("weechat::hook_completion", XS_weechat_api_hook_completion, "weechat");
newXS ("weechat::hook_completion_list_add", XS_weechat_api_hook_completion_list_add, "weechat");
@@ -3680,6 +3680,128 @@ weechat_python_api_hook_signal_send (PyObject *self, PyObject *args)
PYTHON_RETURN_ERROR;
}
/*
* weechat_python_api_hook_hsignal_cb: callback for hsignal hooked
*/
int
weechat_python_api_hook_hsignal_cb (void *data, const char *signal,
struct t_hashtable *hashtable)
{
struct t_script_callback *script_callback;
void *python_argv[3];
char empty_arg[1] = { '\0' };
int *rc, ret;
script_callback = (struct t_script_callback *)data;
if (script_callback && script_callback->function && script_callback->function[0])
{
python_argv[0] = (script_callback->data) ? script_callback->data : empty_arg;
python_argv[1] = (signal) ? (char *)signal : empty_arg;
python_argv[2] = weechat_python_hashtable_to_dict (hashtable);
rc = (int *) weechat_python_exec (script_callback->script,
WEECHAT_SCRIPT_EXEC_INT,
script_callback->function,
"ssO", python_argv);
if (!rc)
ret = WEECHAT_RC_ERROR;
else
{
ret = *rc;
free (rc);
}
if (python_argv[2])
{
Py_XDECREF((PyObject *)python_argv[2]);
}
return ret;
}
return WEECHAT_RC_ERROR;
}
/*
* weechat_python_api_hook_hsignal: hook a hsignal
*/
static PyObject *
weechat_python_api_hook_hsignal (PyObject *self, PyObject *args)
{
char *signal, *function, *data, *result;
PyObject *object;
/* make C compiler happy */
(void) self;
if (!python_current_script || !python_current_script->name)
{
WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "hook_hsignal");
PYTHON_RETURN_EMPTY;
}
signal = NULL;
function = NULL;
data = NULL;
if (!PyArg_ParseTuple (args, "sss", &signal, &function, &data))
{
WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "hook_hsignal");
PYTHON_RETURN_EMPTY;
}
result = script_ptr2str (script_api_hook_hsignal (weechat_python_plugin,
python_current_script,
signal,
&weechat_python_api_hook_hsignal_cb,
function,
data));
PYTHON_RETURN_STRING_FREE(result);
}
/*
* weechat_python_api_hook_hsignal_send: send a hsignal
*/
static PyObject *
weechat_python_api_hook_hsignal_send (PyObject *self, PyObject *args)
{
char *signal;
struct t_hashtable *hashtable;
PyObject *dict;
/* make C compiler happy */
(void) self;
if (!python_current_script || !python_current_script->name)
{
WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "hook_hsignal_send");
PYTHON_RETURN_ERROR;
}
signal = NULL;
if (!PyArg_ParseTuple (args, "sO", &signal, &dict))
{
WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "hook_hsignal_send");
PYTHON_RETURN_ERROR;
}
hashtable = weechat_python_dict_to_hashtable (dict,
WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE);
weechat_hook_hsignal_send (signal, hashtable);
if (hashtable)
weechat_hashtable_free (hashtable);
PYTHON_RETURN_OK;
}
/*
* weechat_python_api_hook_config_cb: callback for config option hooked
*/
@@ -6496,6 +6618,8 @@ PyMethodDef weechat_python_funcs[] =
{ "hook_print", &weechat_python_api_hook_print, METH_VARARGS, "" },
{ "hook_signal", &weechat_python_api_hook_signal, METH_VARARGS, "" },
{ "hook_signal_send", &weechat_python_api_hook_signal_send, METH_VARARGS, "" },
{ "hook_hsignal", &weechat_python_api_hook_hsignal, METH_VARARGS, "" },
{ "hook_hsignal_send", &weechat_python_api_hook_hsignal_send, METH_VARARGS, "" },
{ "hook_config", &weechat_python_api_hook_config, METH_VARARGS, "" },
{ "hook_completion", &weechat_python_api_hook_completion, METH_VARARGS, "" },
{ "hook_completion_list_add", &weechat_python_api_hook_completion_list_add, METH_VARARGS, "" },
+132
View File
@@ -4248,6 +4248,136 @@ weechat_ruby_api_hook_signal_send (VALUE class, VALUE signal, VALUE type_data,
RUBY_RETURN_ERROR;
}
/*
* weechat_ruby_api_hook_hsignal_cb: callback for hsignal hooked
*/
int
weechat_ruby_api_hook_hsignal_cb (void *data, const char *signal,
struct t_hashtable *hashtable)
{
struct t_script_callback *script_callback;
void *ruby_argv[3];
char empty_arg[1] = { '\0' };
int *rc, ret;
script_callback = (struct t_script_callback *)data;
if (script_callback && script_callback->function && script_callback->function[0])
{
ruby_argv[0] = (script_callback->data) ? script_callback->data : empty_arg;
ruby_argv[1] = (signal) ? (char *)signal : empty_arg;
ruby_argv[2] = (void *)weechat_ruby_hashtable_to_hash (hashtable);
rc = (int *) weechat_ruby_exec (script_callback->script,
WEECHAT_SCRIPT_EXEC_INT,
script_callback->function,
"ssh", ruby_argv);
if (!rc)
ret = WEECHAT_RC_ERROR;
else
{
ret = *rc;
free (rc);
}
return ret;
}
return WEECHAT_RC_ERROR;
}
/*
* weechat_ruby_api_hook_hsignal: hook a hsignal
*/
static VALUE
weechat_ruby_api_hook_hsignal (VALUE class, VALUE signal, VALUE function,
VALUE data)
{
char *c_signal, *c_function, *c_data, *result;
VALUE return_value;
/* make C compiler happy */
(void) class;
if (!ruby_current_script || !ruby_current_script->name)
{
WEECHAT_SCRIPT_MSG_NOT_INIT(RUBY_CURRENT_SCRIPT_NAME, "hook_hsignal");
RUBY_RETURN_EMPTY;
}
c_signal = NULL;
c_function = NULL;
c_data = NULL;
if (NIL_P (signal) || NIL_P (function) || NIL_P (data))
{
WEECHAT_SCRIPT_MSG_WRONG_ARGS(RUBY_CURRENT_SCRIPT_NAME, "hook_hsignal");
RUBY_RETURN_EMPTY;
}
Check_Type (signal, T_STRING);
Check_Type (function, T_STRING);
Check_Type (data, T_STRING);
c_signal = StringValuePtr (signal);
c_function = StringValuePtr (function);
c_data = StringValuePtr (data);
result = script_ptr2str (script_api_hook_hsignal (weechat_ruby_plugin,
ruby_current_script,
c_signal,
&weechat_ruby_api_hook_hsignal_cb,
c_function,
c_data));
RUBY_RETURN_STRING_FREE(result);
}
/*
* weechat_ruby_api_hook_hsignal_send: send a hsignal
*/
static VALUE
weechat_ruby_api_hook_hsignal_send (VALUE class, VALUE signal, VALUE hashtable)
{
char *c_signal;
struct t_hashtable *c_hashtable;
/* make C compiler happy */
(void) class;
if (!ruby_current_script || !ruby_current_script->name)
{
WEECHAT_SCRIPT_MSG_NOT_INIT(RUBY_CURRENT_SCRIPT_NAME, "hook_hsignal_send");
RUBY_RETURN_ERROR;
}
c_signal = NULL;
if (NIL_P (signal) || NIL_P (hashtable))
{
WEECHAT_SCRIPT_MSG_WRONG_ARGS(RUBY_CURRENT_SCRIPT_NAME, "hook_hsignal_send");
RUBY_RETURN_ERROR;
}
Check_Type (signal, T_STRING);
Check_Type (hashtable, T_HASH);
c_signal = StringValuePtr (signal);
c_hashtable = weechat_ruby_hash_to_hashtable (hashtable,
WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE);
weechat_hook_hsignal_send (c_signal, c_hashtable);
if (c_hashtable)
weechat_hashtable_free (c_hashtable);
RUBY_RETURN_OK;
}
/*
* weechat_ruby_api_hook_config_cb: callback for config option hooked
*/
@@ -7482,6 +7612,8 @@ weechat_ruby_api_init (VALUE ruby_mWeechat)
rb_define_module_function (ruby_mWeechat, "hook_print", &weechat_ruby_api_hook_print, 6);
rb_define_module_function (ruby_mWeechat, "hook_signal", &weechat_ruby_api_hook_signal, 3);
rb_define_module_function (ruby_mWeechat, "hook_signal_send", &weechat_ruby_api_hook_signal_send, 3);
rb_define_module_function (ruby_mWeechat, "hook_hsignal", &weechat_ruby_api_hook_hsignal, 3);
rb_define_module_function (ruby_mWeechat, "hook_hsignal_send", &weechat_ruby_api_hook_hsignal_send, 2);
rb_define_module_function (ruby_mWeechat, "hook_config", &weechat_ruby_api_hook_config, 3);
rb_define_module_function (ruby_mWeechat, "hook_completion", &weechat_ruby_api_hook_completion, 4);
rb_define_module_function (ruby_mWeechat, "hook_completion_list_add", &weechat_ruby_api_hook_completion_list_add, 4);
+37
View File
@@ -1045,6 +1045,43 @@ script_api_hook_signal (struct t_weechat_plugin *weechat_plugin,
return new_hook;
}
/*
* script_api_hook_hsignal: hook a hsignal
* return new hook, NULL if error
*/
struct t_hook *
script_api_hook_hsignal (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script,
const char *signal,
int (*callback)(void *data, const char *signal,
struct t_hashtable *hashtable),
const char *function,
const char *data)
{
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_hsignal (signal, callback, new_script_callback);
if (!new_hook)
{
script_callback_free_data (new_script_callback);
free (new_script_callback);
return NULL;
}
script_callback_init (new_script_callback, script, function, data);
new_script_callback->hook = new_hook;
script_callback_add (script, new_script_callback);
return new_hook;
}
/*
* script_api_hook_config: hook a config option
* return new hook, NULL if error
+8
View File
@@ -206,6 +206,14 @@ extern struct t_hook *script_api_hook_signal (struct t_weechat_plugin *weechat_p
void *signal_data),
const char *function,
const char *data);
extern struct t_hook *script_api_hook_hsignal (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script,
const char *signal,
int (*callback)(void *data,
const char *signal,
struct t_hashtable *hashtable),
const char *function,
const char *data);
extern struct t_hook *script_api_hook_config (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script,
const char *option,
+125
View File
@@ -3949,6 +3949,127 @@ weechat_tcl_api_hook_signal_send (ClientData clientData, Tcl_Interp *interp,
TCL_RETURN_ERROR;
}
/*
* weechat_tcl_api_hook_hsignal_cb: callback for hsignal hooked
*/
int
weechat_tcl_api_hook_hsignal_cb (void *data, const char *signal,
struct t_hashtable *hashtable)
{
struct t_script_callback *script_callback;
void *tcl_argv[3];
char empty_arg[1] = { '\0' };
int *rc, ret;
script_callback = (struct t_script_callback *)data;
if (script_callback && script_callback->function && script_callback->function[0])
{
tcl_argv[0] = (script_callback->data) ? script_callback->data : empty_arg;
tcl_argv[1] = (signal) ? (char *)signal : empty_arg;
tcl_argv[2] = hashtable;
rc = (int *) weechat_tcl_exec (script_callback->script,
WEECHAT_SCRIPT_EXEC_INT,
script_callback->function,
"ssh", tcl_argv);
if (!rc)
ret = WEECHAT_RC_ERROR;
else
{
ret = *rc;
free (rc);
}
return ret;
}
return WEECHAT_RC_ERROR;
}
/*
* weechat_tcl_api_hook_hsignal: hook a hsignal
*/
static int
weechat_tcl_api_hook_hsignal (ClientData clientData, Tcl_Interp *interp,
int objc, Tcl_Obj *CONST objv[])
{
Tcl_Obj *objp;
char *result, *signal, *function, *data;
int i;
/* make C compiler happy */
(void) clientData;
if (!tcl_current_script || !tcl_current_script->name)
{
WEECHAT_SCRIPT_MSG_NOT_INIT(TCL_CURRENT_SCRIPT_NAME, "hook_hsignal");
TCL_RETURN_EMPTY;
}
if (objc < 4)
{
WEECHAT_SCRIPT_MSG_WRONG_ARGS(TCL_CURRENT_SCRIPT_NAME, "hook_hsignal");
TCL_RETURN_EMPTY;
}
signal = Tcl_GetStringFromObj (objv[1], &i);
function = Tcl_GetStringFromObj (objv[2], &i);
data = Tcl_GetStringFromObj (objv[3], &i);
result = script_ptr2str (script_api_hook_hsignal (weechat_tcl_plugin,
tcl_current_script,
signal,
&weechat_tcl_api_hook_hsignal_cb,
function,
data));
TCL_RETURN_STRING_FREE(result);
}
/*
* weechat_tcl_api_hook_hsignal_send: send a hsignal
*/
static int
weechat_tcl_api_hook_hsignal_send (ClientData clientData, Tcl_Interp *interp,
int objc, Tcl_Obj *CONST objv[])
{
Tcl_Obj *objp;
char *signal;
struct t_hashtable *hashtable;
int i;
/* make C compiler happy */
(void) clientData;
if (!tcl_current_script || !tcl_current_script->name)
{
WEECHAT_SCRIPT_MSG_NOT_INIT(TCL_CURRENT_SCRIPT_NAME, "hook_hsignal_send");
TCL_RETURN_ERROR;
}
if (objc < 3)
{
WEECHAT_SCRIPT_MSG_WRONG_ARGS(TCL_CURRENT_SCRIPT_NAME, "hook_hsignal_send");
TCL_RETURN_ERROR;
}
signal = Tcl_GetStringFromObj (objv[1], &i);
hashtable = weechat_tcl_dict_to_hashtable (interp, objv[2],
WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE);
weechat_hook_hsignal_send (signal, hashtable);
if (hashtable)
weechat_hashtable_free (hashtable);
TCL_RETURN_OK;
}
/*
* weechat_tcl_api_hook_config_cb: callback for config option hooked
*/
@@ -7044,6 +7165,10 @@ void weechat_tcl_api_init (Tcl_Interp *interp)
weechat_tcl_api_hook_signal, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
Tcl_CreateObjCommand (interp, "weechat::hook_signal_send",
weechat_tcl_api_hook_signal_send, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
Tcl_CreateObjCommand (interp, "weechat::hook_hsignal",
weechat_tcl_api_hook_hsignal, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
Tcl_CreateObjCommand (interp, "weechat::hook_hsignal_send",
weechat_tcl_api_hook_hsignal_send, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
Tcl_CreateObjCommand (interp, "weechat::hook_config",
weechat_tcl_api_hook_config, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
Tcl_CreateObjCommand (interp, "weechat::hook_completion",