mirror of
https://github.com/weechat/weechat.git
synced 2026-06-27 13:26:38 +02:00
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
This commit is contained in:
@@ -7224,6 +7224,41 @@ weechat_lua_api_hdata_get (lua_State *L)
|
||||
LUA_RETURN_STRING_FREE(result);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_lua_api_hdata_get_var_offset: get offset of variable in hdata
|
||||
*/
|
||||
|
||||
static int
|
||||
weechat_lua_api_hdata_get_var_offset (lua_State *L)
|
||||
{
|
||||
const char *hdata, *name;
|
||||
int n, value;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) L;
|
||||
|
||||
if (!lua_current_script || !lua_current_script->name)
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_NOT_INIT(LUA_CURRENT_SCRIPT_NAME, "hdata_get_var_offset");
|
||||
LUA_RETURN_INT(0);
|
||||
}
|
||||
|
||||
n = lua_gettop (lua_current_interpreter);
|
||||
|
||||
if (n < 2)
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_WRONG_ARGS(LUA_CURRENT_SCRIPT_NAME, "hdata_get_var_offset");
|
||||
LUA_RETURN_INT(0);
|
||||
}
|
||||
|
||||
hdata = lua_tostring (lua_current_interpreter, -2);
|
||||
name = lua_tostring (lua_current_interpreter, -1);
|
||||
|
||||
value = weechat_hdata_get_var_offset (script_str2ptr (hdata), name);
|
||||
|
||||
LUA_RETURN_INT(value);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_lua_api_hdata_get_var_type_string: get type of variable as string in
|
||||
* hdata
|
||||
@@ -7260,6 +7295,41 @@ weechat_lua_api_hdata_get_var_type_string (lua_State *L)
|
||||
LUA_RETURN_STRING(result);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_lua_api_hdata_get_var_hdata: get hdata for variable in hdata
|
||||
*/
|
||||
|
||||
static int
|
||||
weechat_lua_api_hdata_get_var_hdata (lua_State *L)
|
||||
{
|
||||
const char *hdata, *name, *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, "hdata_get_var_hdata");
|
||||
LUA_RETURN_EMPTY;
|
||||
}
|
||||
|
||||
n = lua_gettop (lua_current_interpreter);
|
||||
|
||||
if (n < 2)
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_WRONG_ARGS(LUA_CURRENT_SCRIPT_NAME, "hdata_get_var_hdata");
|
||||
LUA_RETURN_EMPTY;
|
||||
}
|
||||
|
||||
hdata = lua_tostring (lua_current_interpreter, -2);
|
||||
name = lua_tostring (lua_current_interpreter, -1);
|
||||
|
||||
result = weechat_hdata_get_var_hdata (script_str2ptr (hdata), name);
|
||||
|
||||
LUA_RETURN_STRING(result);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_lua_api_hdata_get_list: get list pointer in hdata
|
||||
*/
|
||||
@@ -8318,7 +8388,9 @@ const struct luaL_reg weechat_lua_api_funcs[] = {
|
||||
{ "infolist_time", &weechat_lua_api_infolist_time },
|
||||
{ "infolist_free", &weechat_lua_api_infolist_free },
|
||||
{ "hdata_get", &weechat_lua_api_hdata_get },
|
||||
{ "hdata_get_var_offset", &weechat_lua_api_hdata_get_var_offset },
|
||||
{ "hdata_get_var_type_string", &weechat_lua_api_hdata_get_var_type_string },
|
||||
{ "hdata_get_var_hdata", &weechat_lua_api_hdata_get_var_hdata },
|
||||
{ "hdata_get_list", &weechat_lua_api_hdata_get_list },
|
||||
{ "hdata_move", &weechat_lua_api_hdata_move },
|
||||
{ "hdata_integer", &weechat_lua_api_hdata_integer },
|
||||
|
||||
@@ -6535,6 +6535,39 @@ XS (XS_weechat_api_hdata_get)
|
||||
PERL_RETURN_STRING_FREE(result);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat::hdata_get_var_offset: get offset of variable in hdata
|
||||
*/
|
||||
|
||||
XS (XS_weechat_api_hdata_get_var_offset)
|
||||
{
|
||||
char *hdata, *name;
|
||||
int value;
|
||||
dXSARGS;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) cv;
|
||||
|
||||
if (!perl_current_script || !perl_current_script->name)
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_NOT_INIT(PERL_CURRENT_SCRIPT_NAME, "hdata_get_var_offset");
|
||||
PERL_RETURN_INT(0);
|
||||
}
|
||||
|
||||
if (items < 2)
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_WRONG_ARGS(PERL_CURRENT_SCRIPT_NAME, "hdata_get_var_offset");
|
||||
PERL_RETURN_INT(0);
|
||||
}
|
||||
|
||||
hdata = SvPV (ST (0), PL_na);
|
||||
name = SvPV (ST (1), PL_na);
|
||||
|
||||
value = weechat_hdata_get_var_offset (script_str2ptr (hdata), name);
|
||||
|
||||
PERL_RETURN_INT(value);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat::hdata_get_var_type_string: get type of variable as string in hdata
|
||||
*/
|
||||
@@ -6568,6 +6601,39 @@ XS (XS_weechat_api_hdata_get_var_type_string)
|
||||
PERL_RETURN_STRING(result);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat::hdata_get_var_hdata: get hdata for variable in hdata
|
||||
*/
|
||||
|
||||
XS (XS_weechat_api_hdata_get_var_hdata)
|
||||
{
|
||||
const char *result;
|
||||
char *hdata, *name;
|
||||
dXSARGS;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) cv;
|
||||
|
||||
if (!perl_current_script || !perl_current_script->name)
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_NOT_INIT(PERL_CURRENT_SCRIPT_NAME, "hdata_get_var_hdata");
|
||||
PERL_RETURN_EMPTY;
|
||||
}
|
||||
|
||||
if (items < 2)
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_WRONG_ARGS(PERL_CURRENT_SCRIPT_NAME, "hdata_get_var_hdata");
|
||||
PERL_RETURN_EMPTY;
|
||||
}
|
||||
|
||||
hdata = SvPV (ST (0), PL_na);
|
||||
name = SvPV (ST (1), PL_na);
|
||||
|
||||
result = weechat_hdata_get_var_hdata (script_str2ptr (hdata), name);
|
||||
|
||||
PERL_RETURN_STRING(result);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat::hdata_get_list: get list pointer in hdata
|
||||
*/
|
||||
@@ -7213,7 +7279,9 @@ weechat_perl_api_init (pTHX)
|
||||
newXS ("weechat::infolist_time", XS_weechat_api_infolist_time, "weechat");
|
||||
newXS ("weechat::infolist_free", XS_weechat_api_infolist_free, "weechat");
|
||||
newXS ("weechat::hdata_get", XS_weechat_api_hdata_get, "weechat");
|
||||
newXS ("weechat::hdata_get_var_offset", XS_weechat_api_hdata_get_var_offset, "weechat");
|
||||
newXS ("weechat::hdata_get_var_type_string", XS_weechat_api_hdata_get_var_type_string, "weechat");
|
||||
newXS ("weechat::hdata_get_var_hdata", XS_weechat_api_hdata_get_var_hdata, "weechat");
|
||||
newXS ("weechat::hdata_get_list", XS_weechat_api_hdata_get_list, "weechat");
|
||||
newXS ("weechat::hdata_move", XS_weechat_api_hdata_move, "weechat");
|
||||
newXS ("weechat::hdata_integer", XS_weechat_api_hdata_integer, "weechat");
|
||||
|
||||
@@ -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, "" },
|
||||
|
||||
@@ -7490,6 +7490,42 @@ weechat_ruby_api_hdata_get (VALUE class, VALUE name)
|
||||
RUBY_RETURN_STRING_FREE(result);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_ruby_api_hdata_get_var_offset: get offset of variable in hdata
|
||||
*/
|
||||
|
||||
static VALUE
|
||||
weechat_ruby_api_hdata_get_var_offset (VALUE class, VALUE hdata, VALUE name)
|
||||
{
|
||||
char *c_hdata, *c_name;
|
||||
int value;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) class;
|
||||
|
||||
if (!ruby_current_script || !ruby_current_script->name)
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_NOT_INIT(RUBY_CURRENT_SCRIPT_NAME, "hdata_get_var_offset");
|
||||
RUBY_RETURN_INT(0);
|
||||
}
|
||||
|
||||
if (NIL_P (hdata) || NIL_P (name))
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_WRONG_ARGS(RUBY_CURRENT_SCRIPT_NAME, "hdata_get_var_offset");
|
||||
RUBY_RETURN_INT(0);
|
||||
}
|
||||
|
||||
Check_Type (hdata, T_STRING);
|
||||
Check_Type (name, T_STRING);
|
||||
|
||||
c_hdata = StringValuePtr (hdata);
|
||||
c_name = StringValuePtr (name);
|
||||
|
||||
value = weechat_hdata_get_var_offset (script_str2ptr (c_hdata), c_name);
|
||||
|
||||
RUBY_RETURN_INT(value);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_ruby_api_hdata_get_var_type_string: get type of variable as string
|
||||
* in hdata
|
||||
@@ -7528,6 +7564,42 @@ weechat_ruby_api_hdata_get_var_type_string (VALUE class, VALUE hdata,
|
||||
RUBY_RETURN_STRING(result);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_ruby_api_hdata_get_var_hdata: get hdata for variable in hdata
|
||||
*/
|
||||
|
||||
static VALUE
|
||||
weechat_ruby_api_hdata_get_var_hdata (VALUE class, VALUE hdata, VALUE name)
|
||||
{
|
||||
char *c_hdata, *c_name;
|
||||
const char *result;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) class;
|
||||
|
||||
if (!ruby_current_script || !ruby_current_script->name)
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_NOT_INIT(RUBY_CURRENT_SCRIPT_NAME, "hdata_get_var_hdata");
|
||||
RUBY_RETURN_EMPTY;
|
||||
}
|
||||
|
||||
if (NIL_P (hdata) || NIL_P (name))
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_WRONG_ARGS(RUBY_CURRENT_SCRIPT_NAME, "hdata_get_var_hdata");
|
||||
RUBY_RETURN_EMPTY;
|
||||
}
|
||||
|
||||
Check_Type (hdata, T_STRING);
|
||||
Check_Type (name, T_STRING);
|
||||
|
||||
c_hdata = StringValuePtr (hdata);
|
||||
c_name = StringValuePtr (name);
|
||||
|
||||
result = weechat_hdata_get_var_hdata (script_str2ptr (c_hdata), c_name);
|
||||
|
||||
RUBY_RETURN_STRING(result);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_ruby_api_hdata_get_list: get list pointer in hdata
|
||||
*/
|
||||
@@ -8273,7 +8345,9 @@ weechat_ruby_api_init (VALUE ruby_mWeechat)
|
||||
rb_define_module_function (ruby_mWeechat, "infolist_time", &weechat_ruby_api_infolist_time, 2);
|
||||
rb_define_module_function (ruby_mWeechat, "infolist_free", &weechat_ruby_api_infolist_free, 1);
|
||||
rb_define_module_function (ruby_mWeechat, "hdata_get", &weechat_ruby_api_hdata_get, 1);
|
||||
rb_define_module_function (ruby_mWeechat, "hdata_get_var_offset", &weechat_ruby_api_hdata_get_var_offset, 2);
|
||||
rb_define_module_function (ruby_mWeechat, "hdata_get_var_type_string", &weechat_ruby_api_hdata_get_var_type_string, 2);
|
||||
rb_define_module_function (ruby_mWeechat, "hdata_get_var_hdata", &weechat_ruby_api_hdata_get_var_hdata, 2);
|
||||
rb_define_module_function (ruby_mWeechat, "hdata_get_list", &weechat_ruby_api_hdata_get_list, 2);
|
||||
rb_define_module_function (ruby_mWeechat, "hdata_move", &weechat_ruby_api_hdata_move, 3);
|
||||
rb_define_module_function (ruby_mWeechat, "hdata_integer", &weechat_ruby_api_hdata_integer, 3);
|
||||
|
||||
@@ -7283,6 +7283,41 @@ weechat_tcl_api_hdata_get (ClientData clientData, Tcl_Interp *interp,
|
||||
TCL_RETURN_STRING_FREE(result);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_tcl_api_hdata_get_var_offset: get offset of variable in hdata
|
||||
*/
|
||||
|
||||
static int
|
||||
weechat_tcl_api_hdata_get_var_offset (ClientData clientData, Tcl_Interp *interp,
|
||||
int objc, Tcl_Obj *CONST objv[])
|
||||
{
|
||||
Tcl_Obj *objp;
|
||||
char *hdata, *name;
|
||||
int result, i;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) clientData;
|
||||
|
||||
if (!tcl_current_script || !tcl_current_script->name)
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_NOT_INIT(TCL_CURRENT_SCRIPT_NAME, "hdata_get_var_offset");
|
||||
TCL_RETURN_INT(0);
|
||||
}
|
||||
|
||||
if (objc < 3)
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_WRONG_ARGS(TCL_CURRENT_SCRIPT_NAME, "hdata_get_var_offset");
|
||||
TCL_RETURN_INT(0);
|
||||
}
|
||||
|
||||
hdata = Tcl_GetStringFromObj (objv[1], &i);
|
||||
name = Tcl_GetStringFromObj (objv[2], &i);
|
||||
|
||||
result = weechat_hdata_get_var_offset (script_str2ptr (hdata), name);
|
||||
|
||||
TCL_RETURN_INT(result);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_tcl_api_hdata_get_var_type_string: get type of variable as string in
|
||||
* hdata
|
||||
@@ -7321,6 +7356,42 @@ weechat_tcl_api_hdata_get_var_type_string (ClientData clientData,
|
||||
TCL_RETURN_STRING(result);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_tcl_api_hdata_get_var_hdata: get hdata for variable in hdata
|
||||
*/
|
||||
|
||||
static int
|
||||
weechat_tcl_api_hdata_get_var_hdata (ClientData clientData, Tcl_Interp *interp,
|
||||
int objc, Tcl_Obj *CONST objv[])
|
||||
{
|
||||
Tcl_Obj *objp;
|
||||
char *hdata, *name;
|
||||
const char *result;
|
||||
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, "hdata_get_var_hdata");
|
||||
TCL_RETURN_EMPTY;
|
||||
}
|
||||
|
||||
if (objc < 3)
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_WRONG_ARGS(TCL_CURRENT_SCRIPT_NAME, "hdata_get_var_hdata");
|
||||
TCL_RETURN_EMPTY;
|
||||
}
|
||||
|
||||
hdata = Tcl_GetStringFromObj (objv[1], &i);
|
||||
name = Tcl_GetStringFromObj (objv[2], &i);
|
||||
|
||||
result = weechat_hdata_get_var_hdata (script_str2ptr (hdata), name);
|
||||
|
||||
TCL_RETURN_STRING(result);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_tcl_api_hdata_get_list: get list pointer in hdata
|
||||
*/
|
||||
@@ -8266,8 +8337,12 @@ void weechat_tcl_api_init (Tcl_Interp *interp)
|
||||
weechat_tcl_api_infolist_free, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
|
||||
Tcl_CreateObjCommand (interp, "weechat::hdata_get",
|
||||
weechat_tcl_api_hdata_get, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
|
||||
Tcl_CreateObjCommand (interp, "weechat::hdata_get_var_offset",
|
||||
weechat_tcl_api_hdata_get_var_offset, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
|
||||
Tcl_CreateObjCommand (interp, "weechat::hdata_get_var_type_string",
|
||||
weechat_tcl_api_hdata_get_var_type_string, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
|
||||
Tcl_CreateObjCommand (interp, "weechat::hdata_get_var_hdata",
|
||||
weechat_tcl_api_hdata_get_var_hdata, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
|
||||
Tcl_CreateObjCommand (interp, "weechat::hdata_get_list",
|
||||
weechat_tcl_api_hdata_get_list, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
|
||||
Tcl_CreateObjCommand (interp, "weechat::hdata_move",
|
||||
|
||||
Reference in New Issue
Block a user