From 19bc95b96189de5a645adbe7b3487d5de1b835e7 Mon Sep 17 00:00:00 2001 From: Sebastien Helleu Date: Sun, 26 Jun 2011 18:15:42 +0200 Subject: core: many improvements on hdata New features: - add optional hdata name for variables in hdata - add plugin API functions: hdata_get_var_hdata - use hashtable to store hdata (created by WeeChat and plugins) - free hdata and infolists created by plugin on plugin unload - free all hdata on exit - add "free" option to command /debug hdata - remove hdata for hooks --- src/plugins/scripts/python/weechat-python-api.c | 68 +++++++++++++++++++++++++ 1 file changed, 68 insertions(+) (limited to 'src/plugins/scripts/python') diff --git a/src/plugins/scripts/python/weechat-python-api.c b/src/plugins/scripts/python/weechat-python-api.c index 8a9ccfcab..05df01e70 100644 --- a/src/plugins/scripts/python/weechat-python-api.c +++ b/src/plugins/scripts/python/weechat-python-api.c @@ -6875,6 +6875,39 @@ weechat_python_api_hdata_get (PyObject *self, PyObject *args) PYTHON_RETURN_STRING_FREE(result); } +/* + * weechat_python_api_hdata_get_var_offset: get offset of variable in hdata + */ + +static PyObject * +weechat_python_api_hdata_get_var_offset (PyObject *self, PyObject *args) +{ + char *hdata, *name; + int value; + + /* make C compiler happy */ + (void) self; + + if (!python_current_script || !python_current_script->name) + { + WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "hdata_get_var_offset"); + PYTHON_RETURN_INT(0); + } + + hdata = NULL; + name = NULL; + + if (!PyArg_ParseTuple (args, "ss", &hdata, &name)) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "hdata_get_var_offset"); + PYTHON_RETURN_INT(0); + } + + value = weechat_hdata_get_var_offset (script_str2ptr (hdata), name); + + PYTHON_RETURN_INT(value); +} + /* * weechat_python_api_hdata_get_var_type_string: get type of variable as string * in hdata @@ -6909,6 +6942,39 @@ weechat_python_api_hdata_get_var_type_string (PyObject *self, PyObject *args) PYTHON_RETURN_STRING(result); } +/* + * weechat_python_api_hdata_get_var_hdata: get hdata for variable in hdata + */ + +static PyObject * +weechat_python_api_hdata_get_var_hdata (PyObject *self, PyObject *args) +{ + char *hdata, *name; + const char *result; + + /* make C compiler happy */ + (void) self; + + if (!python_current_script || !python_current_script->name) + { + WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "hdata_get_var_hdata"); + PYTHON_RETURN_EMPTY; + } + + hdata = NULL; + name = NULL; + + if (!PyArg_ParseTuple (args, "ss", &hdata, &name)) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "hdata_get_var_hdata"); + PYTHON_RETURN_EMPTY; + } + + result = weechat_hdata_get_var_hdata (script_str2ptr (hdata), name); + + PYTHON_RETURN_STRING(result); +} + /* * weechat_python_api_hdata_get_list: get list pointer in hdata */ @@ -7555,7 +7621,9 @@ PyMethodDef weechat_python_funcs[] = { "infolist_time", &weechat_python_api_infolist_time, METH_VARARGS, "" }, { "infolist_free", &weechat_python_api_infolist_free, METH_VARARGS, "" }, { "hdata_get", &weechat_python_api_hdata_get, METH_VARARGS, "" }, + { "hdata_get_var_offset", &weechat_python_api_hdata_get_var_offset, METH_VARARGS, "" }, { "hdata_get_var_type_string", &weechat_python_api_hdata_get_var_type_string, METH_VARARGS, "" }, + { "hdata_get_var_hdata", &weechat_python_api_hdata_get_var_hdata, METH_VARARGS, "" }, { "hdata_get_list", &weechat_python_api_hdata_get_list, METH_VARARGS, "" }, { "hdata_move", &weechat_python_api_hdata_move, METH_VARARGS, "" }, { "hdata_integer", &weechat_python_api_hdata_integer, METH_VARARGS, "" }, -- cgit v1.2.3