diff options
author | Sebastien Helleu <flashcode@flashtux.org> | 2011-06-26 18:15:42 +0200 |
---|---|---|
committer | Sebastien Helleu <flashcode@flashtux.org> | 2011-06-26 18:15:42 +0200 |
commit | 19bc95b96189de5a645adbe7b3487d5de1b835e7 (patch) | |
tree | b68d3d98d3d643bc02fba218db7f7ed6cd07ea2c /src/plugins/scripts/tcl | |
parent | 2a630031fd3c868733e3038c3e19ad4b53a8d8ce (diff) | |
download | weechat-19bc95b96189de5a645adbe7b3487d5de1b835e7.zip |
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
Diffstat (limited to 'src/plugins/scripts/tcl')
-rw-r--r-- | src/plugins/scripts/tcl/weechat-tcl-api.c | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/src/plugins/scripts/tcl/weechat-tcl-api.c b/src/plugins/scripts/tcl/weechat-tcl-api.c index e0e3705c8..5bc243bab 100644 --- a/src/plugins/scripts/tcl/weechat-tcl-api.c +++ b/src/plugins/scripts/tcl/weechat-tcl-api.c @@ -7284,6 +7284,41 @@ weechat_tcl_api_hdata_get (ClientData clientData, Tcl_Interp *interp, } /* + * 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 */ @@ -7322,6 +7357,42 @@ weechat_tcl_api_hdata_get_var_type_string (ClientData clientData, } /* + * 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", |