1
0
mirror of https://github.com/weechat/weechat.git synced 2026-06-27 21:36:37 +02:00

core: add functions "key_bind" and "key_unbind" in plugin API

This commit is contained in:
Sebastien Helleu
2011-08-20 10:52:27 +02:00
parent 221fff960e
commit 44f2b7caf4
38 changed files with 1174 additions and 232 deletions
+77
View File
@@ -2988,6 +2988,81 @@ weechat_lua_api_config_unset_plugin (lua_State *L)
LUA_RETURN_INT(rc);
}
/*
* weechat_lua_api_key_bind: bind key(s)
*/
static int
weechat_lua_api_key_bind (lua_State *L)
{
const char *context;
struct t_hashtable *hashtable;
int n, num_keys;
/* make C compiler happy */
(void) L;
if (!lua_current_script || !lua_current_script->name)
{
WEECHAT_SCRIPT_MSG_NOT_INIT(LUA_CURRENT_SCRIPT_NAME, "key_bind");
LUA_RETURN_INT(0);
}
n = lua_gettop (lua_current_interpreter);
if (n < 2)
{
WEECHAT_SCRIPT_MSG_WRONG_ARGS(LUA_CURRENT_SCRIPT_NAME, "key_bind");
LUA_RETURN_INT(0);
}
context = lua_tostring (lua_current_interpreter, -2);
hashtable = weechat_lua_tohashtable (lua_current_interpreter, -1,
WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE);
num_keys = weechat_key_bind (context, hashtable);
if (hashtable)
weechat_hashtable_free (hashtable);
LUA_RETURN_INT(num_keys);
}
/*
* weechat_lua_api_key_unbind: unbind key(s)
*/
static int
weechat_lua_api_key_unbind (lua_State *L)
{
const char *context, *key;
int n, num_keys;
/* make C compiler happy */
(void) L;
if (!lua_current_script || !lua_current_script->name)
{
WEECHAT_SCRIPT_MSG_NOT_INIT(LUA_CURRENT_SCRIPT_NAME, "key_unbind");
LUA_RETURN_INT(0);
}
n = lua_gettop (lua_current_interpreter);
if (n < 2)
{
WEECHAT_SCRIPT_MSG_WRONG_ARGS(LUA_CURRENT_SCRIPT_NAME, "key_unbind");
LUA_RETURN_INT(0);
}
context = lua_tostring (lua_current_interpreter, -2);
key = lua_tostring (lua_current_interpreter, -1);
num_keys = weechat_key_unbind (context, key);
LUA_RETURN_INT(num_keys);
}
/*
* weechat_lua_api_prefix: get a prefix, used for display
*/
@@ -8367,6 +8442,8 @@ const struct luaL_reg weechat_lua_api_funcs[] = {
{ "config_set_plugin", &weechat_lua_api_config_set_plugin },
{ "config_set_desc_plugin", &weechat_lua_api_config_set_desc_plugin },
{ "config_unset_plugin", &weechat_lua_api_config_unset_plugin },
{ "key_bind", &weechat_lua_api_key_bind },
{ "key_unbind", &weechat_lua_api_key_unbind },
{ "prefix", &weechat_lua_api_prefix },
{ "color", &weechat_lua_api_color },
{ "print", &weechat_lua_api_print },
@@ -2682,6 +2682,77 @@ XS (XS_weechat_api_config_unset_plugin)
PERL_RETURN_INT(rc);
}
/*
* weechat::key_bind: bind key(s)
*/
XS (XS_weechat_api_key_bind)
{
char *context;
struct t_hashtable *hashtable;
int num_keys;
dXSARGS;
/* make C compiler happy */
(void) cv;
if (!perl_current_script || !perl_current_script->name)
{
WEECHAT_SCRIPT_MSG_NOT_INIT(PERL_CURRENT_SCRIPT_NAME, "key_bind");
PERL_RETURN_INT(0);
}
if (items < 2)
{
WEECHAT_SCRIPT_MSG_WRONG_ARGS(PERL_CURRENT_SCRIPT_NAME, "key_bind");
PERL_RETURN_INT(0);
}
context = SvPV_nolen (ST (0));
hashtable = weechat_perl_hash_to_hashtable (ST (1),
WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE);
num_keys = weechat_key_bind (context, hashtable);
if (hashtable)
weechat_hashtable_free (hashtable);
PERL_RETURN_INT(num_keys);
}
/*
* weechat::key_unbind: unbind key(s)
*/
XS (XS_weechat_api_key_unbind)
{
char *context, *key;
int num_keys;
dXSARGS;
/* make C compiler happy */
(void) cv;
if (!perl_current_script || !perl_current_script->name)
{
WEECHAT_SCRIPT_MSG_NOT_INIT(PERL_CURRENT_SCRIPT_NAME, "key_unbind");
PERL_RETURN_INT(0);
}
if (items < 2)
{
WEECHAT_SCRIPT_MSG_WRONG_ARGS(PERL_CURRENT_SCRIPT_NAME, "key_unbind");
PERL_RETURN_INT(0);
}
context = SvPV_nolen (ST (0));
key = SvPV_nolen (ST (1));
num_keys = weechat_key_unbind (context, key);
PERL_RETURN_INT(num_keys);
}
/*
* weechat::prefix: get a prefix, used for display
*/
@@ -7254,6 +7325,8 @@ weechat_perl_api_init (pTHX)
newXS ("weechat::config_set_plugin", XS_weechat_api_config_set_plugin, "weechat");
newXS ("weechat::config_set_desc_plugin", XS_weechat_api_config_set_desc_plugin, "weechat");
newXS ("weechat::config_unset_plugin", XS_weechat_api_config_unset_plugin, "weechat");
newXS ("weechat::key_bind", XS_weechat_api_key_bind, "weechat");
newXS ("weechat::key_unbind", XS_weechat_api_key_unbind, "weechat");
newXS ("weechat::prefix", XS_weechat_api_prefix, "weechat");
newXS ("weechat::color", XS_weechat_api_color, "weechat");
newXS ("weechat::print", XS_weechat_api_print, "weechat");
@@ -2830,6 +2830,79 @@ weechat_python_api_config_unset_plugin (PyObject *self, PyObject *args)
PYTHON_RETURN_INT(rc);
}
/*
* weechat_python_api_key_bind: bind key(s)
*/
static PyObject *
weechat_python_api_key_bind (PyObject *self, PyObject *args)
{
char *context;
struct t_hashtable *hashtable;
PyObject *dict;
int num_keys;
/* make C compiler happy */
(void) self;
if (!python_current_script || !python_current_script->name)
{
WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "key_bind");
PYTHON_RETURN_INT(0);
}
context = NULL;
if (!PyArg_ParseTuple (args, "sO", &context, &dict))
{
WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "key_bind");
PYTHON_RETURN_INT(0);
}
hashtable = weechat_python_dict_to_hashtable (dict,
WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE);
num_keys = weechat_key_bind (context, hashtable);
if (hashtable)
weechat_hashtable_free (hashtable);
PYTHON_RETURN_INT(num_keys);
}
/*
* weechat_python_api_key_unbind: unbind key(s)
*/
static PyObject *
weechat_python_api_key_unbind (PyObject *self, PyObject *args)
{
char *context, *key;
int num_keys;
/* make C compiler happy */
(void) self;
if (!python_current_script || !python_current_script->name)
{
WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "key_unbind");
PYTHON_RETURN_INT(0);
}
context = NULL;
key = NULL;
if (!PyArg_ParseTuple (args, "ss", &context, &key))
{
WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "key_unbind");
PYTHON_RETURN_INT(0);
}
num_keys = weechat_key_unbind (context, key);
PYTHON_RETURN_INT(num_keys);
}
/*
* weechat_python_api_prefix: get a prefix, used for display
*/
@@ -6316,6 +6389,7 @@ weechat_python_api_info_get (PyObject *self, PyObject *args)
}
info_name = NULL;
arguments = NULL;
if (!PyArg_ParseTuple (args, "ss", &info_name, &arguments))
{
@@ -7597,6 +7671,8 @@ PyMethodDef weechat_python_funcs[] =
{ "config_set_plugin", &weechat_python_api_config_set_plugin, METH_VARARGS, "" },
{ "config_set_desc_plugin", &weechat_python_api_config_set_desc_plugin, METH_VARARGS, "" },
{ "config_unset_plugin", &weechat_python_api_config_unset_plugin, METH_VARARGS, "" },
{ "key_bind", &weechat_python_api_key_bind, METH_VARARGS, "" },
{ "key_unbind", &weechat_python_api_key_unbind, METH_VARARGS, "" },
{ "prefix", &weechat_python_api_prefix, METH_VARARGS, "" },
{ "color", &weechat_python_api_color, METH_VARARGS, "" },
{ "prnt", &weechat_python_api_prnt, METH_VARARGS, "" },
@@ -3069,6 +3069,83 @@ weechat_ruby_api_config_unset_plugin (VALUE class, VALUE option)
RUBY_RETURN_INT(rc);
}
/*
* weechat_ruby_api_key_bind: bind key(s)
*/
static VALUE
weechat_ruby_api_key_bind (VALUE class, VALUE context, VALUE keys)
{
char *c_context;
struct t_hashtable *c_keys;
int num_keys;
/* make C compiler happy */
(void) class;
if (!ruby_current_script || !ruby_current_script->name)
{
WEECHAT_SCRIPT_MSG_NOT_INIT(RUBY_CURRENT_SCRIPT_NAME, "key_bind");
RUBY_RETURN_INT(0);
}
if (NIL_P (context) || NIL_P (keys))
{
WEECHAT_SCRIPT_MSG_WRONG_ARGS(RUBY_CURRENT_SCRIPT_NAME, "key_bind");
RUBY_RETURN_INT(0);
}
Check_Type (context, T_STRING);
Check_Type (keys, T_HASH);
c_context = StringValuePtr (context);
c_keys = weechat_ruby_hash_to_hashtable (keys,
WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE);
num_keys = weechat_key_bind (c_context, c_keys);
if (c_keys)
weechat_hashtable_free (c_keys);
RUBY_RETURN_INT(num_keys);
}
/*
* weechat_ruby_api_key_unbind: unbind key(s)
*/
static VALUE
weechat_ruby_api_key_unbind (VALUE class, VALUE context, VALUE key)
{
char *c_context, *c_key;
int num_keys;
/* make C compiler happy */
(void) class;
if (!ruby_current_script || !ruby_current_script->name)
{
WEECHAT_SCRIPT_MSG_NOT_INIT(RUBY_CURRENT_SCRIPT_NAME, "key_unbind");
RUBY_RETURN_INT(0);
}
if (NIL_P (context) || NIL_P (key))
{
WEECHAT_SCRIPT_MSG_WRONG_ARGS(RUBY_CURRENT_SCRIPT_NAME, "key_unbind");
RUBY_RETURN_INT(0);
}
Check_Type (context, T_STRING);
Check_Type (key, T_STRING);
c_context = StringValuePtr (context);
c_key = StringValuePtr (key);
num_keys = weechat_key_unbind (c_context, c_key);
RUBY_RETURN_INT(num_keys);
}
/*
* weechat_ruby_api_prefix: get a prefix, used for display
*/
@@ -8326,6 +8403,8 @@ weechat_ruby_api_init (VALUE ruby_mWeechat)
rb_define_module_function (ruby_mWeechat, "config_set_plugin", &weechat_ruby_api_config_set_plugin, 2);
rb_define_module_function (ruby_mWeechat, "config_set_desc_plugin", &weechat_ruby_api_config_set_desc_plugin, 2);
rb_define_module_function (ruby_mWeechat, "config_unset_plugin", &weechat_ruby_api_config_unset_plugin, 1);
rb_define_module_function (ruby_mWeechat, "key_bind", &weechat_ruby_api_key_bind, 2);
rb_define_module_function (ruby_mWeechat, "key_unbind", &weechat_ruby_api_key_unbind, 2);
rb_define_module_function (ruby_mWeechat, "prefix", &weechat_ruby_api_prefix, 1);
rb_define_module_function (ruby_mWeechat, "color", &weechat_ruby_api_color, 1);
rb_define_module_function (ruby_mWeechat, "print", &weechat_ruby_api_print, 2);
+79
View File
@@ -3073,6 +3073,81 @@ weechat_tcl_api_config_unset_plugin (ClientData clientData, Tcl_Interp *interp,
TCL_RETURN_INT(rc);
}
/*
* weechat_tcl_api_key_bind: bind key(s)
*/
static int
weechat_tcl_api_key_bind (ClientData clientData, Tcl_Interp *interp,
int objc, Tcl_Obj *CONST objv[])
{
Tcl_Obj *objp;
char *context;
struct t_hashtable *hashtable;
int i, num_keys;
/* make C compiler happy */
(void) clientData;
if (!tcl_current_script || !tcl_current_script->name)
{
WEECHAT_SCRIPT_MSG_NOT_INIT(TCL_CURRENT_SCRIPT_NAME, "key_bind");
TCL_RETURN_INT(0);
}
if (objc < 3)
{
WEECHAT_SCRIPT_MSG_WRONG_ARGS(TCL_CURRENT_SCRIPT_NAME, "key_bind");
TCL_RETURN_INT(0);
}
context = Tcl_GetStringFromObj (objv[1], &i);
hashtable = weechat_tcl_dict_to_hashtable (interp, objv[2],
WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE);
num_keys = weechat_key_bind (context, hashtable);
if (hashtable)
weechat_hashtable_free (hashtable);
TCL_RETURN_INT(num_keys);
}
/*
* weechat_tcl_api_key_unbind: unbind key(s)
*/
static int
weechat_tcl_api_key_unbind (ClientData clientData, Tcl_Interp *interp,
int objc, Tcl_Obj *CONST objv[])
{
Tcl_Obj *objp;
char *context, *key;
int i, num_keys;
/* make C compiler happy */
(void) clientData;
if (!tcl_current_script || !tcl_current_script->name)
{
WEECHAT_SCRIPT_MSG_NOT_INIT(TCL_CURRENT_SCRIPT_NAME, "key_unbind");
TCL_RETURN_INT(0);
}
if (objc < 3)
{
WEECHAT_SCRIPT_MSG_WRONG_ARGS(TCL_CURRENT_SCRIPT_NAME, "key_unbind");
TCL_RETURN_INT(0);
}
context = Tcl_GetStringFromObj (objv[1], &i);
key = Tcl_GetStringFromObj (objv[2], &i);
num_keys = weechat_key_unbind (context, key);
TCL_RETURN_INT(num_keys);
}
/*
* weechat_tcl_api_prefix: get a prefix, used for display
*/
@@ -8224,6 +8299,10 @@ void weechat_tcl_api_init (Tcl_Interp *interp)
weechat_tcl_api_config_set_desc_plugin, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
Tcl_CreateObjCommand (interp, "weechat::config_unset_plugin",
weechat_tcl_api_config_unset_plugin, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
Tcl_CreateObjCommand (interp, "weechat::key_bind",
weechat_tcl_api_key_bind, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
Tcl_CreateObjCommand (interp, "weechat::key_unbind",
weechat_tcl_api_key_unbind, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
Tcl_CreateObjCommand (interp, "weechat::prefix",
weechat_tcl_api_prefix, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
Tcl_CreateObjCommand (interp, "weechat::color",