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/lua | |
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/lua')
-rw-r--r-- | src/plugins/scripts/lua/weechat-lua-api.c | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/src/plugins/scripts/lua/weechat-lua-api.c b/src/plugins/scripts/lua/weechat-lua-api.c index 9bb680dc6..ccdba77ad 100644 --- a/src/plugins/scripts/lua/weechat-lua-api.c +++ b/src/plugins/scripts/lua/weechat-lua-api.c @@ -7225,6 +7225,41 @@ weechat_lua_api_hdata_get (lua_State *L) } /* + * 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 */ @@ -7261,6 +7296,41 @@ weechat_lua_api_hdata_get_var_type_string (lua_State *L) } /* + * 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 }, |