diff options
author | Sébastien Helleu <flashcode@flashtux.org> | 2016-11-27 17:34:15 +0100 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2016-11-27 17:34:15 +0100 |
commit | 64f05204f933dfa7f342639cf50b952ae29c9a23 (patch) | |
tree | b65f4234a4da0710105e37a5da1c33a9dfc6f7eb /src/plugins | |
parent | 6e82e6618c7eba39f404df759ad34bd0499eeb27 (diff) | |
download | weechat-64f05204f933dfa7f342639cf50b952ae29c9a23.zip |
api: move functions hook_completion* after hook_command
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/guile/weechat-guile-api.c | 208 | ||||
-rw-r--r-- | src/plugins/javascript/weechat-js-api.cpp | 216 | ||||
-rw-r--r-- | src/plugins/lua/weechat-lua-api.c | 224 | ||||
-rw-r--r-- | src/plugins/perl/weechat-perl-api.c | 226 | ||||
-rw-r--r-- | src/plugins/python/weechat-python-api.c | 224 | ||||
-rw-r--r-- | src/plugins/ruby/weechat-ruby-api.c | 272 | ||||
-rw-r--r-- | src/plugins/tcl/weechat-tcl-api.c | 238 |
7 files changed, 804 insertions, 804 deletions
diff --git a/src/plugins/guile/weechat-guile-api.c b/src/plugins/guile/weechat-guile-api.c index acf0f8080..0199ec4fc 100644 --- a/src/plugins/guile/weechat-guile-api.c +++ b/src/plugins/guile/weechat-guile-api.c @@ -1974,6 +1974,107 @@ weechat_guile_api_hook_command (SCM command, SCM description, SCM args, } int +weechat_guile_api_hook_completion_cb (const void *pointer, void *data, + const char *completion_item, + struct t_gui_buffer *buffer, + struct t_gui_completion *completion) +{ + struct t_plugin_script *script; + void *func_argv[4]; + char empty_arg[1] = { '\0' }; + const char *ptr_function, *ptr_data; + int *rc, ret; + + script = (struct t_plugin_script *)pointer; + plugin_script_get_function_and_data (data, &ptr_function, &ptr_data); + + if (ptr_function && ptr_function[0]) + { + func_argv[0] = (ptr_data) ? (char *)ptr_data : empty_arg; + func_argv[1] = (completion_item) ? (char *)completion_item : empty_arg; + func_argv[2] = API_PTR2STR(buffer); + func_argv[3] = API_PTR2STR(completion); + + rc = (int *) weechat_guile_exec (script, + WEECHAT_SCRIPT_EXEC_INT, + ptr_function, + "ssss", func_argv); + + if (!rc) + ret = WEECHAT_RC_ERROR; + else + { + ret = *rc; + free (rc); + } + if (func_argv[2]) + free (func_argv[2]); + if (func_argv[3]) + free (func_argv[3]); + + return ret; + } + + return WEECHAT_RC_ERROR; +} + +SCM +weechat_guile_api_hook_completion (SCM completion, SCM description, + SCM function, SCM data) +{ + char *result; + SCM return_value; + + API_INIT_FUNC(1, "hook_completion", API_RETURN_EMPTY); + if (!scm_is_string (completion) || !scm_is_string (description) + || !scm_is_string (function) || !scm_is_string (data)) + API_WRONG_ARGS(API_RETURN_EMPTY); + + result = API_PTR2STR(plugin_script_api_hook_completion (weechat_guile_plugin, + guile_current_script, + API_SCM_TO_STRING(completion), + API_SCM_TO_STRING(description), + &weechat_guile_api_hook_completion_cb, + API_SCM_TO_STRING(function), + API_SCM_TO_STRING(data))); + + API_RETURN_STRING_FREE(result); +} + +SCM +weechat_guile_api_hook_completion_get_string (SCM completion, SCM property) +{ + const char *result; + + API_INIT_FUNC(1, "hook_completion_get_string", API_RETURN_EMPTY); + if (!scm_is_string (completion) || !scm_is_string (property)) + API_WRONG_ARGS(API_RETURN_EMPTY); + + result = weechat_hook_completion_get_string ( + API_STR2PTR(API_SCM_TO_STRING(completion)), + API_SCM_TO_STRING(property)); + + API_RETURN_STRING(result); +} + +SCM +weechat_guile_api_hook_completion_list_add (SCM completion, SCM word, + SCM nick_completion, SCM where) +{ + API_INIT_FUNC(1, "hook_completion_list_add", API_RETURN_ERROR); + if (!scm_is_string (completion) || !scm_is_string (word) + || !scm_is_integer (nick_completion) || !scm_is_string (where)) + API_WRONG_ARGS(API_RETURN_ERROR); + + weechat_hook_completion_list_add (API_STR2PTR(API_SCM_TO_STRING(completion)), + API_SCM_TO_STRING(word), + scm_to_int (nick_completion), + API_SCM_TO_STRING(where)); + + API_RETURN_OK; +} + +int weechat_guile_api_hook_command_run_cb (const void *pointer, void *data, struct t_gui_buffer *buffer, const char *command) @@ -2715,107 +2816,6 @@ weechat_guile_api_hook_config (SCM option, SCM function, SCM data) API_RETURN_STRING_FREE(result); } -int -weechat_guile_api_hook_completion_cb (const void *pointer, void *data, - const char *completion_item, - struct t_gui_buffer *buffer, - struct t_gui_completion *completion) -{ - struct t_plugin_script *script; - void *func_argv[4]; - char empty_arg[1] = { '\0' }; - const char *ptr_function, *ptr_data; - int *rc, ret; - - script = (struct t_plugin_script *)pointer; - plugin_script_get_function_and_data (data, &ptr_function, &ptr_data); - - if (ptr_function && ptr_function[0]) - { - func_argv[0] = (ptr_data) ? (char *)ptr_data : empty_arg; - func_argv[1] = (completion_item) ? (char *)completion_item : empty_arg; - func_argv[2] = API_PTR2STR(buffer); - func_argv[3] = API_PTR2STR(completion); - - rc = (int *) weechat_guile_exec (script, - WEECHAT_SCRIPT_EXEC_INT, - ptr_function, - "ssss", func_argv); - - if (!rc) - ret = WEECHAT_RC_ERROR; - else - { - ret = *rc; - free (rc); - } - if (func_argv[2]) - free (func_argv[2]); - if (func_argv[3]) - free (func_argv[3]); - - return ret; - } - - return WEECHAT_RC_ERROR; -} - -SCM -weechat_guile_api_hook_completion (SCM completion, SCM description, - SCM function, SCM data) -{ - char *result; - SCM return_value; - - API_INIT_FUNC(1, "hook_completion", API_RETURN_EMPTY); - if (!scm_is_string (completion) || !scm_is_string (description) - || !scm_is_string (function) || !scm_is_string (data)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = API_PTR2STR(plugin_script_api_hook_completion (weechat_guile_plugin, - guile_current_script, - API_SCM_TO_STRING(completion), - API_SCM_TO_STRING(description), - &weechat_guile_api_hook_completion_cb, - API_SCM_TO_STRING(function), - API_SCM_TO_STRING(data))); - - API_RETURN_STRING_FREE(result); -} - -SCM -weechat_guile_api_hook_completion_get_string (SCM completion, SCM property) -{ - const char *result; - - API_INIT_FUNC(1, "hook_completion_get_string", API_RETURN_EMPTY); - if (!scm_is_string (completion) || !scm_is_string (property)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = weechat_hook_completion_get_string ( - API_STR2PTR(API_SCM_TO_STRING(completion)), - API_SCM_TO_STRING(property)); - - API_RETURN_STRING(result); -} - -SCM -weechat_guile_api_hook_completion_list_add (SCM completion, SCM word, - SCM nick_completion, SCM where) -{ - API_INIT_FUNC(1, "hook_completion_list_add", API_RETURN_ERROR); - if (!scm_is_string (completion) || !scm_is_string (word) - || !scm_is_integer (nick_completion) || !scm_is_string (where)) - API_WRONG_ARGS(API_RETURN_ERROR); - - weechat_hook_completion_list_add (API_STR2PTR(API_SCM_TO_STRING(completion)), - API_SCM_TO_STRING(word), - scm_to_int (nick_completion), - API_SCM_TO_STRING(where)); - - API_RETURN_OK; -} - char * weechat_guile_api_hook_modifier_cb (const void *pointer, void *data, const char *modifier, @@ -4886,6 +4886,9 @@ weechat_guile_api_module_init (void *data) API_DEF_FUNC(print_y, 3); API_DEF_FUNC(log_print, 1); API_DEF_FUNC(hook_command, 7); + API_DEF_FUNC(hook_completion, 4); + API_DEF_FUNC(hook_completion_get_string, 2); + API_DEF_FUNC(hook_completion_list_add, 4); API_DEF_FUNC(hook_command_run, 3); API_DEF_FUNC(hook_timer, 5); API_DEF_FUNC(hook_fd, 6); @@ -4898,9 +4901,6 @@ weechat_guile_api_module_init (void *data) API_DEF_FUNC(hook_hsignal, 3); API_DEF_FUNC(hook_hsignal_send, 2); API_DEF_FUNC(hook_config, 3); - API_DEF_FUNC(hook_completion, 4); - API_DEF_FUNC(hook_completion_get_string, 2); - API_DEF_FUNC(hook_completion_list_add, 4); API_DEF_FUNC(hook_modifier, 3); API_DEF_FUNC(hook_modifier_exec, 3); API_DEF_FUNC(hook_info, 5); diff --git a/src/plugins/javascript/weechat-js-api.cpp b/src/plugins/javascript/weechat-js-api.cpp index 4a09b130b..7199dee8b 100644 --- a/src/plugins/javascript/weechat-js-api.cpp +++ b/src/plugins/javascript/weechat-js-api.cpp @@ -1882,6 +1882,111 @@ API_FUNC(hook_command) } int +weechat_js_api_hook_completion_cb (const void *pointer, void *data, + const char *completion_item, + struct t_gui_buffer *buffer, + struct t_gui_completion *completion) +{ + struct t_plugin_script *script; + void *func_argv[4]; + char empty_arg[1] = { '\0' }; + const char *ptr_function, *ptr_data; + int *rc, ret; + + script = (struct t_plugin_script *)pointer; + plugin_script_get_function_and_data (data, &ptr_function, &ptr_data); + + if (ptr_function && ptr_function[0]) + { + func_argv[0] = (ptr_data) ? (char *)ptr_data : empty_arg; + func_argv[1] = (completion_item) ? (char *)completion_item : empty_arg; + func_argv[2] = API_PTR2STR(buffer); + func_argv[3] = API_PTR2STR(completion); + + rc = (int *)weechat_js_exec (script, + WEECHAT_SCRIPT_EXEC_INT, + ptr_function, + "ssss", func_argv); + + if (!rc) + ret = WEECHAT_RC_ERROR; + else + { + ret = *rc; + free (rc); + } + if (func_argv[2]) + free (func_argv[2]); + if (func_argv[3]) + free (func_argv[3]); + + return ret; + } + + return WEECHAT_RC_ERROR; +} + +API_FUNC(hook_completion) +{ + char *result; + + API_INIT_FUNC(1, "hook_completion", "ssss", API_RETURN_EMPTY); + + v8::String::Utf8Value completion(args[0]); + v8::String::Utf8Value description(args[1]); + v8::String::Utf8Value function(args[2]); + v8::String::Utf8Value data(args[3]); + + result = API_PTR2STR( + plugin_script_api_hook_completion ( + weechat_js_plugin, + js_current_script, + *completion, + *description, + &weechat_js_api_hook_completion_cb, + *function, + *data)); + + API_RETURN_STRING_FREE(result); +} + +API_FUNC(hook_completion_get_string) +{ + const char *result; + + API_INIT_FUNC(1, "hook_completion_get_string", "ss", API_RETURN_EMPTY); + + v8::String::Utf8Value completion(args[0]); + v8::String::Utf8Value property(args[1]); + + result = weechat_hook_completion_get_string ( + (struct t_gui_completion *)API_STR2PTR(*completion), + *property); + + API_RETURN_STRING(result); +} + +API_FUNC(hook_completion_list_add) +{ + int nick_completion; + + API_INIT_FUNC(1, "hook_completion_list_add", "ssis", API_RETURN_ERROR); + + v8::String::Utf8Value completion(args[0]); + v8::String::Utf8Value word(args[1]); + nick_completion = args[2]->IntegerValue(); + v8::String::Utf8Value where(args[3]); + + weechat_hook_completion_list_add ( + (struct t_gui_completion *)API_STR2PTR(*completion), + *word, + nick_completion, + *where); + + API_RETURN_OK; +} + +int weechat_js_api_hook_command_run_cb (const void *pointer, void *data, struct t_gui_buffer *buffer, const char *command) @@ -2635,111 +2740,6 @@ API_FUNC(hook_config) API_RETURN_STRING_FREE(result); } -int -weechat_js_api_hook_completion_cb (const void *pointer, void *data, - const char *completion_item, - struct t_gui_buffer *buffer, - struct t_gui_completion *completion) -{ - struct t_plugin_script *script; - void *func_argv[4]; - char empty_arg[1] = { '\0' }; - const char *ptr_function, *ptr_data; - int *rc, ret; - - script = (struct t_plugin_script *)pointer; - plugin_script_get_function_and_data (data, &ptr_function, &ptr_data); - - if (ptr_function && ptr_function[0]) - { - func_argv[0] = (ptr_data) ? (char *)ptr_data : empty_arg; - func_argv[1] = (completion_item) ? (char *)completion_item : empty_arg; - func_argv[2] = API_PTR2STR(buffer); - func_argv[3] = API_PTR2STR(completion); - - rc = (int *)weechat_js_exec (script, - WEECHAT_SCRIPT_EXEC_INT, - ptr_function, - "ssss", func_argv); - - if (!rc) - ret = WEECHAT_RC_ERROR; - else - { - ret = *rc; - free (rc); - } - if (func_argv[2]) - free (func_argv[2]); - if (func_argv[3]) - free (func_argv[3]); - - return ret; - } - - return WEECHAT_RC_ERROR; -} - -API_FUNC(hook_completion) -{ - char *result; - - API_INIT_FUNC(1, "hook_completion", "ssss", API_RETURN_EMPTY); - - v8::String::Utf8Value completion(args[0]); - v8::String::Utf8Value description(args[1]); - v8::String::Utf8Value function(args[2]); - v8::String::Utf8Value data(args[3]); - - result = API_PTR2STR( - plugin_script_api_hook_completion ( - weechat_js_plugin, - js_current_script, - *completion, - *description, - &weechat_js_api_hook_completion_cb, - *function, - *data)); - - API_RETURN_STRING_FREE(result); -} - -API_FUNC(hook_completion_get_string) -{ - const char *result; - - API_INIT_FUNC(1, "hook_completion_get_string", "ss", API_RETURN_EMPTY); - - v8::String::Utf8Value completion(args[0]); - v8::String::Utf8Value property(args[1]); - - result = weechat_hook_completion_get_string ( - (struct t_gui_completion *)API_STR2PTR(*completion), - *property); - - API_RETURN_STRING(result); -} - -API_FUNC(hook_completion_list_add) -{ - int nick_completion; - - API_INIT_FUNC(1, "hook_completion_list_add", "ssis", API_RETURN_ERROR); - - v8::String::Utf8Value completion(args[0]); - v8::String::Utf8Value word(args[1]); - nick_completion = args[2]->IntegerValue(); - v8::String::Utf8Value where(args[3]); - - weechat_hook_completion_list_add ( - (struct t_gui_completion *)API_STR2PTR(*completion), - *word, - nick_completion, - *where); - - API_RETURN_OK; -} - char * weechat_js_api_hook_modifier_cb (const void *pointer, void *data, const char *modifier, @@ -4861,6 +4861,9 @@ WeechatJsV8::loadLibs() API_DEF_FUNC(print_y); API_DEF_FUNC(log_print); API_DEF_FUNC(hook_command); + API_DEF_FUNC(hook_completion); + API_DEF_FUNC(hook_completion_get_string); + API_DEF_FUNC(hook_completion_list_add); API_DEF_FUNC(hook_command_run); API_DEF_FUNC(hook_timer); API_DEF_FUNC(hook_fd); @@ -4873,9 +4876,6 @@ WeechatJsV8::loadLibs() API_DEF_FUNC(hook_hsignal); API_DEF_FUNC(hook_hsignal_send); API_DEF_FUNC(hook_config); - API_DEF_FUNC(hook_completion); - API_DEF_FUNC(hook_completion_get_string); - API_DEF_FUNC(hook_completion_list_add); API_DEF_FUNC(hook_modifier); API_DEF_FUNC(hook_modifier_exec); API_DEF_FUNC(hook_info); diff --git a/src/plugins/lua/weechat-lua-api.c b/src/plugins/lua/weechat-lua-api.c index ab3dcc163..8f0addf14 100644 --- a/src/plugins/lua/weechat-lua-api.c +++ b/src/plugins/lua/weechat-lua-api.c @@ -2071,6 +2071,115 @@ API_FUNC(hook_command) } int +weechat_lua_api_hook_completion_cb (const void *pointer, void *data, + const char *completion_item, + struct t_gui_buffer *buffer, + struct t_gui_completion *completion) +{ + struct t_plugin_script *script; + void *func_argv[4]; + char empty_arg[1] = { '\0' }; + const char *ptr_function, *ptr_data; + int *rc, ret; + + script = (struct t_plugin_script *)pointer; + plugin_script_get_function_and_data (data, &ptr_function, &ptr_data); + + if (ptr_function && ptr_function[0]) + { + func_argv[0] = (ptr_data) ? (char *)ptr_data : empty_arg; + func_argv[1] = (completion_item) ? (char *)completion_item : empty_arg; + func_argv[2] = API_PTR2STR(buffer); + func_argv[3] = API_PTR2STR(completion); + + rc = (int *) weechat_lua_exec (script, + WEECHAT_SCRIPT_EXEC_INT, + ptr_function, + "ssss", func_argv); + + if (!rc) + ret = WEECHAT_RC_ERROR; + else + { + ret = *rc; + free (rc); + } + if (func_argv[2]) + free (func_argv[2]); + if (func_argv[3]) + free (func_argv[3]); + + return ret; + } + + return WEECHAT_RC_ERROR; +} + +API_FUNC(hook_completion) +{ + const char *completion, *description, *function, *data; + char *result; + + API_INIT_FUNC(1, "hook_completion", API_RETURN_EMPTY); + if (lua_gettop (L) < 4) + API_WRONG_ARGS(API_RETURN_EMPTY); + + completion = lua_tostring (L, -4); + description = lua_tostring (L, -3); + function = lua_tostring (L, -2); + data = lua_tostring (L, -1); + + result = API_PTR2STR(plugin_script_api_hook_completion (weechat_lua_plugin, + lua_current_script, + completion, + description, + &weechat_lua_api_hook_completion_cb, + function, + data)); + + API_RETURN_STRING_FREE(result); +} + +API_FUNC(hook_completion_get_string) +{ + const char *completion, *property, *result; + + API_INIT_FUNC(1, "hook_completion_get_string", API_RETURN_EMPTY); + if (lua_gettop (L) < 2) + API_WRONG_ARGS(API_RETURN_EMPTY); + + completion = lua_tostring (L, -2); + property = lua_tostring (L, -1); + + result = weechat_hook_completion_get_string (API_STR2PTR(completion), + property); + + API_RETURN_STRING(result); +} + +API_FUNC(hook_completion_list_add) +{ + const char *completion, *word, *where; + int nick_completion; + + API_INIT_FUNC(1, "hook_completion_list_add", API_RETURN_ERROR); + if (lua_gettop (L) < 4) + API_WRONG_ARGS(API_RETURN_ERROR); + + completion = lua_tostring (L, -4); + word = lua_tostring (L, -3); + nick_completion = lua_tonumber (L, -2); + where = lua_tostring (L, -1); + + weechat_hook_completion_list_add (API_STR2PTR(completion), + word, + nick_completion, + where); + + API_RETURN_OK; +} + +int weechat_lua_api_hook_command_run_cb (const void *pointer, void *data, struct t_gui_buffer *buffer, const char *command) @@ -2836,115 +2945,6 @@ API_FUNC(hook_config) API_RETURN_STRING_FREE(result); } -int -weechat_lua_api_hook_completion_cb (const void *pointer, void *data, - const char *completion_item, - struct t_gui_buffer *buffer, - struct t_gui_completion *completion) -{ - struct t_plugin_script *script; - void *func_argv[4]; - char empty_arg[1] = { '\0' }; - const char *ptr_function, *ptr_data; - int *rc, ret; - - script = (struct t_plugin_script *)pointer; - plugin_script_get_function_and_data (data, &ptr_function, &ptr_data); - - if (ptr_function && ptr_function[0]) - { - func_argv[0] = (ptr_data) ? (char *)ptr_data : empty_arg; - func_argv[1] = (completion_item) ? (char *)completion_item : empty_arg; - func_argv[2] = API_PTR2STR(buffer); - func_argv[3] = API_PTR2STR(completion); - - rc = (int *) weechat_lua_exec (script, - WEECHAT_SCRIPT_EXEC_INT, - ptr_function, - "ssss", func_argv); - - if (!rc) - ret = WEECHAT_RC_ERROR; - else - { - ret = *rc; - free (rc); - } - if (func_argv[2]) - free (func_argv[2]); - if (func_argv[3]) - free (func_argv[3]); - - return ret; - } - - return WEECHAT_RC_ERROR; -} - -API_FUNC(hook_completion) -{ - const char *completion, *description, *function, *data; - char *result; - - API_INIT_FUNC(1, "hook_completion", API_RETURN_EMPTY); - if (lua_gettop (L) < 4) - API_WRONG_ARGS(API_RETURN_EMPTY); - - completion = lua_tostring (L, -4); - description = lua_tostring (L, -3); - function = lua_tostring (L, -2); - data = lua_tostring (L, -1); - - result = API_PTR2STR(plugin_script_api_hook_completion (weechat_lua_plugin, - lua_current_script, - completion, - description, - &weechat_lua_api_hook_completion_cb, - function, - data)); - - API_RETURN_STRING_FREE(result); -} - -API_FUNC(hook_completion_get_string) -{ - const char *completion, *property, *result; - - API_INIT_FUNC(1, "hook_completion_get_string", API_RETURN_EMPTY); - if (lua_gettop (L) < 2) - API_WRONG_ARGS(API_RETURN_EMPTY); - - completion = lua_tostring (L, -2); - property = lua_tostring (L, -1); - - result = weechat_hook_completion_get_string (API_STR2PTR(completion), - property); - - API_RETURN_STRING(result); -} - -API_FUNC(hook_completion_list_add) -{ - const char *completion, *word, *where; - int nick_completion; - - API_INIT_FUNC(1, "hook_completion_list_add", API_RETURN_ERROR); - if (lua_gettop (L) < 4) - API_WRONG_ARGS(API_RETURN_ERROR); - - completion = lua_tostring (L, -4); - word = lua_tostring (L, -3); - nick_completion = lua_tonumber (L, -2); - where = lua_tostring (L, -1); - - weechat_hook_completion_list_add (API_STR2PTR(completion), - word, - nick_completion, - where); - - API_RETURN_OK; -} - char * weechat_lua_api_hook_modifier_cb (const void *pointer, void *data, const char *modifier, @@ -5184,6 +5184,9 @@ const struct luaL_Reg weechat_lua_api_funcs[] = { API_DEF_FUNC(print_y), API_DEF_FUNC(log_print), API_DEF_FUNC(hook_command), + API_DEF_FUNC(hook_completion), + API_DEF_FUNC(hook_completion_get_string), + API_DEF_FUNC(hook_completion_list_add), API_DEF_FUNC(hook_command_run), API_DEF_FUNC(hook_timer), API_DEF_FUNC(hook_fd), @@ -5196,9 +5199,6 @@ const struct luaL_Reg weechat_lua_api_funcs[] = { API_DEF_FUNC(hook_hsignal), API_DEF_FUNC(hook_hsignal_send), API_DEF_FUNC(hook_config), - API_DEF_FUNC(hook_completion), - API_DEF_FUNC(hook_completion_get_string), - API_DEF_FUNC(hook_completion_list_add), API_DEF_FUNC(hook_modifier), API_DEF_FUNC(hook_modifier_exec), API_DEF_FUNC(hook_info), diff --git a/src/plugins/perl/weechat-perl-api.c b/src/plugins/perl/weechat-perl-api.c index 4233f70c6..1de7fad67 100644 --- a/src/plugins/perl/weechat-perl-api.c +++ b/src/plugins/perl/weechat-perl-api.c @@ -2007,6 +2007,116 @@ API_FUNC(hook_command) } int +weechat_perl_api_hook_completion_cb (const void *pointer, void *data, + const char *completion_item, + struct t_gui_buffer *buffer, + struct t_gui_completion *completion) +{ + struct t_plugin_script *script; + void *func_argv[4]; + char empty_arg[1] = { '\0' }; + const char *ptr_function, *ptr_data; + int *rc, ret; + + script = (struct t_plugin_script *)pointer; + plugin_script_get_function_and_data (data, &ptr_function, &ptr_data); + + if (ptr_function && ptr_function[0]) + { + func_argv[0] = (ptr_data) ? (char *)ptr_data : empty_arg; + func_argv[1] = (completion_item) ? (char *)completion_item : empty_arg; + func_argv[2] = API_PTR2STR(buffer); + func_argv[3] = API_PTR2STR(completion); + + rc = (int *) weechat_perl_exec (script, + WEECHAT_SCRIPT_EXEC_INT, + ptr_function, + "ssss", func_argv); + + if (!rc) + ret = WEECHAT_RC_ERROR; + else + { + ret = *rc; + free (rc); + } + if (func_argv[2]) + free (func_argv[2]); + if (func_argv[3]) + free (func_argv[3]); + + return ret; + } + + return WEECHAT_RC_ERROR; +} + +API_FUNC(hook_completion) +{ + char *result, *completion, *description, *function, *data; + dXSARGS; + + API_INIT_FUNC(1, "hook_completion", API_RETURN_EMPTY); + if (items < 4) + API_WRONG_ARGS(API_RETURN_EMPTY); + + completion = SvPV_nolen (ST (0)); + description = SvPV_nolen (ST (1)); + function = SvPV_nolen (ST (2)); + data = SvPV_nolen (ST (3)); + + result = API_PTR2STR(plugin_script_api_hook_completion (weechat_perl_plugin, + perl_current_script, + completion, + description, + &weechat_perl_api_hook_completion_cb, + function, + data)); + + API_RETURN_STRING_FREE(result); +} + +API_FUNC(hook_completion_get_string) +{ + char *completion, *property; + const char *result; + dXSARGS; + + API_INIT_FUNC(1, "hook_completion_get_string", API_RETURN_EMPTY); + if (items < 2) + API_WRONG_ARGS(API_RETURN_EMPTY); + + completion = SvPV_nolen (ST (0)); + property = SvPV_nolen (ST (1)); + + result = weechat_hook_completion_get_string (API_STR2PTR(completion), + property); + + API_RETURN_STRING(result); +} + +API_FUNC(hook_completion_list_add) +{ + char *completion, *word, *where; + dXSARGS; + + API_INIT_FUNC(1, "hook_completion_list_add", API_RETURN_ERROR); + if (items < 4) + API_WRONG_ARGS(API_RETURN_ERROR); + + completion = SvPV_nolen (ST (0)); + word = SvPV_nolen (ST (1)); + where = SvPV_nolen (ST (3)); + + weechat_hook_completion_list_add (API_STR2PTR(completion), + word, + SvIV (ST (2)), /* nick_completion */ + where); + + API_RETURN_OK; +} + +int weechat_perl_api_hook_command_run_cb (const void *pointer, void *data, struct t_gui_buffer *buffer, const char *command) @@ -2749,116 +2859,6 @@ API_FUNC(hook_config) API_RETURN_STRING_FREE(result); } -int -weechat_perl_api_hook_completion_cb (const void *pointer, void *data, - const char *completion_item, - struct t_gui_buffer *buffer, - struct t_gui_completion *completion) -{ - struct t_plugin_script *script; - void *func_argv[4]; - char empty_arg[1] = { '\0' }; - const char *ptr_function, *ptr_data; - int *rc, ret; - - script = (struct t_plugin_script *)pointer; - plugin_script_get_function_and_data (data, &ptr_function, &ptr_data); - - if (ptr_function && ptr_function[0]) - { - func_argv[0] = (ptr_data) ? (char *)ptr_data : empty_arg; - func_argv[1] = (completion_item) ? (char *)completion_item : empty_arg; - func_argv[2] = API_PTR2STR(buffer); - func_argv[3] = API_PTR2STR(completion); - - rc = (int *) weechat_perl_exec (script, - WEECHAT_SCRIPT_EXEC_INT, - ptr_function, - "ssss", func_argv); - - if (!rc) - ret = WEECHAT_RC_ERROR; - else - { - ret = *rc; - free (rc); - } - if (func_argv[2]) - free (func_argv[2]); - if (func_argv[3]) - free (func_argv[3]); - - return ret; - } - - return WEECHAT_RC_ERROR; -} - -API_FUNC(hook_completion) -{ - char *result, *completion, *description, *function, *data; - dXSARGS; - - API_INIT_FUNC(1, "hook_completion", API_RETURN_EMPTY); - if (items < 4) - API_WRONG_ARGS(API_RETURN_EMPTY); - - completion = SvPV_nolen (ST (0)); - description = SvPV_nolen (ST (1)); - function = SvPV_nolen (ST (2)); - data = SvPV_nolen (ST (3)); - - result = API_PTR2STR(plugin_script_api_hook_completion (weechat_perl_plugin, - perl_current_script, - completion, - description, - &weechat_perl_api_hook_completion_cb, - function, - data)); - - API_RETURN_STRING_FREE(result); -} - -API_FUNC(hook_completion_get_string) -{ - char *completion, *property; - const char *result; - dXSARGS; - - API_INIT_FUNC(1, "hook_completion_get_string", API_RETURN_EMPTY); - if (items < 2) - API_WRONG_ARGS(API_RETURN_EMPTY); - - completion = SvPV_nolen (ST (0)); - property = SvPV_nolen (ST (1)); - - result = weechat_hook_completion_get_string (API_STR2PTR(completion), - property); - - API_RETURN_STRING(result); -} - -API_FUNC(hook_completion_list_add) -{ - char *completion, *word, *where; - dXSARGS; - - API_INIT_FUNC(1, "hook_completion_list_add", API_RETURN_ERROR); - if (items < 4) - API_WRONG_ARGS(API_RETURN_ERROR); - - completion = SvPV_nolen (ST (0)); - word = SvPV_nolen (ST (1)); - where = SvPV_nolen (ST (3)); - - weechat_hook_completion_list_add (API_STR2PTR(completion), - word, - SvIV (ST (2)), /* nick_completion */ - where); - - API_RETURN_OK; -} - char * weechat_perl_api_hook_modifier_cb (const void *pointer, void *data, const char *modifier, @@ -5124,6 +5124,9 @@ weechat_perl_api_init (pTHX) API_DEF_FUNC(print_y); API_DEF_FUNC(log_print); API_DEF_FUNC(hook_command); + API_DEF_FUNC(hook_completion); + API_DEF_FUNC(hook_completion_get_string); + API_DEF_FUNC(hook_completion_list_add); API_DEF_FUNC(hook_command_run); API_DEF_FUNC(hook_timer); API_DEF_FUNC(hook_fd); @@ -5136,9 +5139,6 @@ weechat_perl_api_init (pTHX) API_DEF_FUNC(hook_hsignal); API_DEF_FUNC(hook_hsignal_send); API_DEF_FUNC(hook_config); - API_DEF_FUNC(hook_completion); - API_DEF_FUNC(hook_completion_get_string); - API_DEF_FUNC(hook_completion_list_add); API_DEF_FUNC(hook_modifier); API_DEF_FUNC(hook_modifier_exec); API_DEF_FUNC(hook_info); diff --git a/src/plugins/python/weechat-python-api.c b/src/plugins/python/weechat-python-api.c index 23acaba0b..d9cd74862 100644 --- a/src/plugins/python/weechat-python-api.c +++ b/src/plugins/python/weechat-python-api.c @@ -2003,6 +2003,115 @@ API_FUNC(hook_command) } int +weechat_python_api_hook_completion_cb (const void *pointer, void *data, + const char *completion_item, + struct t_gui_buffer *buffer, + struct t_gui_completion *completion) +{ + struct t_plugin_script *script; + void *func_argv[4]; + char empty_arg[1] = { '\0' }; + const char *ptr_function, *ptr_data; + int *rc, ret; + + script = (struct t_plugin_script *)pointer; + plugin_script_get_function_and_data (data, &ptr_function, &ptr_data); + + if (ptr_function && ptr_function[0]) + { + func_argv[0] = (ptr_data) ? (char *)ptr_data : empty_arg; + func_argv[1] = (completion_item) ? (char *)completion_item : empty_arg; + func_argv[2] = API_PTR2STR(buffer); + func_argv[3] = API_PTR2STR(completion); + + rc = (int *) weechat_python_exec (script, + WEECHAT_SCRIPT_EXEC_INT, + ptr_function, + "ssss", func_argv); + + if (!rc) + ret = WEECHAT_RC_ERROR; + else + { + ret = *rc; + free (rc); + } + if (func_argv[2]) + free (func_argv[2]); + if (func_argv[3]) + free (func_argv[3]); + + return ret; + } + + return WEECHAT_RC_ERROR; +} + +API_FUNC(hook_completion) +{ + char *completion, *description, *function, *data, *result; + PyObject *return_value; + + API_INIT_FUNC(1, "hook_completion", API_RETURN_EMPTY); + completion = NULL; + description = NULL; + function = NULL; + data = NULL; + if (!PyArg_ParseTuple (args, "ssss", &completion, &description, &function, + &data)) + API_WRONG_ARGS(API_RETURN_EMPTY); + + result = API_PTR2STR(plugin_script_api_hook_completion (weechat_python_plugin, + python_current_script, + completion, + description, + &weechat_python_api_hook_completion_cb, + function, + data)); + + API_RETURN_STRING_FREE(result); +} + +API_FUNC(hook_completion_get_string) +{ + char *completion, *property; + const char *result; + + API_INIT_FUNC(1, "hook_completion_get_string", API_RETURN_EMPTY); + completion = NULL; + property = NULL; + if (!PyArg_ParseTuple (args, "ss", &completion, &property)) + API_WRONG_ARGS(API_RETURN_EMPTY); + + result = weechat_hook_completion_get_string (API_STR2PTR(completion), + property); + + API_RETURN_STRING(result); +} + +API_FUNC(hook_completion_list_add) +{ + char *completion, *word, *where; + int nick_completion; + + API_INIT_FUNC(1, "hook_completion_list_add", API_RETURN_ERROR); + completion = NULL; + word = NULL; + nick_completion = 0; + where = NULL; + if (!PyArg_ParseTuple (args, "ssis", &completion, &word, &nick_completion, + &where)) + API_WRONG_ARGS(API_RETURN_ERROR); + + weechat_hook_completion_list_add (API_STR2PTR(completion), + word, + nick_completion, + where); + + API_RETURN_OK; +} + +int weechat_python_api_hook_command_run_cb (const void *pointer, void *data, struct t_gui_buffer *buffer, const char *command) @@ -2782,115 +2891,6 @@ API_FUNC(hook_config) API_RETURN_STRING_FREE(result); } -int -weechat_python_api_hook_completion_cb (const void *pointer, void *data, - const char *completion_item, - struct t_gui_buffer *buffer, - struct t_gui_completion *completion) -{ - struct t_plugin_script *script; - void *func_argv[4]; - char empty_arg[1] = { '\0' }; - const char *ptr_function, *ptr_data; - int *rc, ret; - - script = (struct t_plugin_script *)pointer; - plugin_script_get_function_and_data (data, &ptr_function, &ptr_data); - - if (ptr_function && ptr_function[0]) - { - func_argv[0] = (ptr_data) ? (char *)ptr_data : empty_arg; - func_argv[1] = (completion_item) ? (char *)completion_item : empty_arg; - func_argv[2] = API_PTR2STR(buffer); - func_argv[3] = API_PTR2STR(completion); - - rc = (int *) weechat_python_exec (script, - WEECHAT_SCRIPT_EXEC_INT, - ptr_function, - "ssss", func_argv); - - if (!rc) - ret = WEECHAT_RC_ERROR; - else - { - ret = *rc; - free (rc); - } - if (func_argv[2]) - free (func_argv[2]); - if (func_argv[3]) - free (func_argv[3]); - - return ret; - } - - return WEECHAT_RC_ERROR; -} - -API_FUNC(hook_completion) -{ - char *completion, *description, *function, *data, *result; - PyObject *return_value; - - API_INIT_FUNC(1, "hook_completion", API_RETURN_EMPTY); - completion = NULL; - description = NULL; - function = NULL; - data = NULL; - if (!PyArg_ParseTuple (args, "ssss", &completion, &description, &function, - &data)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = API_PTR2STR(plugin_script_api_hook_completion (weechat_python_plugin, - python_current_script, - completion, - description, - &weechat_python_api_hook_completion_cb, - function, - data)); - - API_RETURN_STRING_FREE(result); -} - -API_FUNC(hook_completion_get_string) -{ - char *completion, *property; - const char *result; - - API_INIT_FUNC(1, "hook_completion_get_string", API_RETURN_EMPTY); - completion = NULL; - property = NULL; - if (!PyArg_ParseTuple (args, "ss", &completion, &property)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = weechat_hook_completion_get_string (API_STR2PTR(completion), - property); - - API_RETURN_STRING(result); -} - -API_FUNC(hook_completion_list_add) -{ - char *completion, *word, *where; - int nick_completion; - - API_INIT_FUNC(1, "hook_completion_list_add", API_RETURN_ERROR); - completion = NULL; - word = NULL; - nick_completion = 0; - where = NULL; - if (!PyArg_ParseTuple (args, "ssis", &completion, &word, &nick_completion, - &where)) - API_WRONG_ARGS(API_RETURN_ERROR); - - weechat_hook_completion_list_add (API_STR2PTR(completion), - word, - nick_completion, - where); - - API_RETURN_OK; -} - char * weechat_python_api_hook_modifier_cb (const void *pointer, void *data, const char *modifier, @@ -5100,6 +5100,9 @@ PyMethodDef weechat_python_funcs[] = API_DEF_FUNC(prnt_y), API_DEF_FUNC(log_print), API_DEF_FUNC(hook_command), + API_DEF_FUNC(hook_completion), + API_DEF_FUNC(hook_completion_get_string), + API_DEF_FUNC(hook_completion_list_add), API_DEF_FUNC(hook_command_run), API_DEF_FUNC(hook_timer), API_DEF_FUNC(hook_fd), @@ -5112,9 +5115,6 @@ PyMethodDef weechat_python_funcs[] = API_DEF_FUNC(hook_hsignal), API_DEF_FUNC(hook_hsignal_send), API_DEF_FUNC(hook_config), - API_DEF_FUNC(hook_completion), - API_DEF_FUNC(hook_completion_get_string), - API_DEF_FUNC(hook_completion_list_add), API_DEF_FUNC(hook_modifier), API_DEF_FUNC(hook_modifier_exec), API_DEF_FUNC(hook_info), diff --git a/src/plugins/ruby/weechat-ruby-api.c b/src/plugins/ruby/weechat-ruby-api.c index 9b705afba..38324aa68 100644 --- a/src/plugins/ruby/weechat-ruby-api.c +++ b/src/plugins/ruby/weechat-ruby-api.c @@ -2451,6 +2451,139 @@ weechat_ruby_api_hook_command (VALUE class, VALUE command, VALUE description, } int +weechat_ruby_api_hook_completion_cb (const void *pointer, void *data, + const char *completion_item, + struct t_gui_buffer *buffer, + struct t_gui_completion *completion) +{ + struct t_plugin_script *script; + void *func_argv[4]; + char empty_arg[1] = { '\0' }; + const char *ptr_function, *ptr_data; + int *rc, ret; + + script = (struct t_plugin_script *)pointer; + plugin_script_get_function_and_data (data, &ptr_function, &ptr_data); + + if (ptr_function && ptr_function[0]) + { + func_argv[0] = (ptr_data) ? (char *)ptr_data : empty_arg; + func_argv[1] = (completion_item) ? (char *)completion_item : empty_arg; + func_argv[2] = API_PTR2STR(buffer); + func_argv[3] = API_PTR2STR(completion); + + rc = (int *) weechat_ruby_exec (script, + WEECHAT_SCRIPT_EXEC_INT, + ptr_function, + "ssss", func_argv); + + if (!rc) + ret = WEECHAT_RC_ERROR; + else + { + ret = *rc; + free (rc); + } + if (func_argv[2]) + free (func_argv[2]); + if (func_argv[3]) + free (func_argv[3]); + + return ret; + } + + return WEECHAT_RC_ERROR; +} + +static VALUE +weechat_ruby_api_hook_completion (VALUE class, VALUE completion, + VALUE description, VALUE function, + VALUE data) +{ + char *c_completion, *c_description, *c_function, *c_data, *result; + VALUE return_value; + + API_INIT_FUNC(1, "hook_completion", API_RETURN_EMPTY); + if (NIL_P (completion) || NIL_P (description) || NIL_P (function) + || NIL_P (data)) + API_WRONG_ARGS(API_RETURN_EMPTY); + + Check_Type (completion, T_STRING); + Check_Type (description, T_STRING); + Check_Type (function, T_STRING); + Check_Type (data, T_STRING); + + c_completion = StringValuePtr (completion); + c_description = StringValuePtr (description); + c_function = StringValuePtr (function); + c_data = StringValuePtr (data); + + result = API_PTR2STR(plugin_script_api_hook_completion (weechat_ruby_plugin, + ruby_current_script, + c_completion, + c_description, + &weechat_ruby_api_hook_completion_cb, + c_function, + c_data)); + + API_RETURN_STRING_FREE(result); +} + +static VALUE +weechat_ruby_api_hook_completion_get_string (VALUE class, VALUE completion, + VALUE property) +{ + char *c_completion, *c_property; + const char *result; + + API_INIT_FUNC(1, "hook_completion_get_string", API_RETURN_EMPTY); + if (NIL_P (completion) || NIL_P (property)) + API_WRONG_ARGS(API_RETURN_EMPTY); + + Check_Type (completion, T_STRING); + Check_Type (property, T_STRING); + + c_completion = StringValuePtr (completion); + c_property = StringValuePtr (property); + + result = weechat_hook_completion_get_string (API_STR2PTR(c_completion), + c_property); + + API_RETURN_STRING(result); +} + +static VALUE +weechat_ruby_api_hook_completion_list_add (VALUE class, VALUE completion, + VALUE word, VALUE nick_completion, + VALUE where) +{ + char *c_completion, *c_word, *c_where; + int c_nick_completion; + + API_INIT_FUNC(1, "hook_completion_list_add", API_RETURN_ERROR); + if (NIL_P (completion) || NIL_P (word) || NIL_P (nick_completion) + || NIL_P (where)) + API_WRONG_ARGS(API_RETURN_ERROR); + + Check_Type (completion, T_STRING); + Check_Type (word, T_STRING); + Check_Type (nick_completion, T_FIXNUM); + Check_Type (where, T_STRING); + + c_completion = StringValuePtr (completion); + c_word = StringValuePtr (word); + c_nick_completion = FIX2INT (nick_completion); + c_where = StringValuePtr (where); + + weechat_hook_completion_list_add (API_STR2PTR(c_completion), + c_word, + c_nick_completion, + c_where); + + API_RETURN_OK; +} + +int weechat_ruby_api_hook_command_run_cb (const void *pointer, void *data, struct t_gui_buffer *buffer, const char *command) @@ -3312,139 +3445,6 @@ weechat_ruby_api_hook_config (VALUE class, VALUE option, VALUE function, API_RETURN_STRING_FREE(result); } -int -weechat_ruby_api_hook_completion_cb (const void *pointer, void *data, - const char *completion_item, - struct t_gui_buffer *buffer, - struct t_gui_completion *completion) -{ - struct t_plugin_script *script; - void *func_argv[4]; - char empty_arg[1] = { '\0' }; - const char *ptr_function, *ptr_data; - int *rc, ret; - - script = (struct t_plugin_script *)pointer; - plugin_script_get_function_and_data (data, &ptr_function, &ptr_data); - - if (ptr_function && ptr_function[0]) - { - func_argv[0] = (ptr_data) ? (char *)ptr_data : empty_arg; - func_argv[1] = (completion_item) ? (char *)completion_item : empty_arg; - func_argv[2] = API_PTR2STR(buffer); - func_argv[3] = API_PTR2STR(completion); - - rc = (int *) weechat_ruby_exec (script, - WEECHAT_SCRIPT_EXEC_INT, - ptr_function, - "ssss", func_argv); - - if (!rc) - ret = WEECHAT_RC_ERROR; - else - { - ret = *rc; - free (rc); - } - if (func_argv[2]) - free (func_argv[2]); - if (func_argv[3]) - free (func_argv[3]); - - return ret; - } - - return WEECHAT_RC_ERROR; -} - -static VALUE -weechat_ruby_api_hook_completion (VALUE class, VALUE completion, - VALUE description, VALUE function, - VALUE data) -{ - char *c_completion, *c_description, *c_function, *c_data, *result; - VALUE return_value; - - API_INIT_FUNC(1, "hook_completion", API_RETURN_EMPTY); - if (NIL_P (completion) || NIL_P (description) || NIL_P (function) - || NIL_P (data)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - Check_Type (completion, T_STRING); - Check_Type (description, T_STRING); - Check_Type (function, T_STRING); - Check_Type (data, T_STRING); - - c_completion = StringValuePtr (completion); - c_description = StringValuePtr (description); - c_function = StringValuePtr (function); - c_data = StringValuePtr (data); - - result = API_PTR2STR(plugin_script_api_hook_completion (weechat_ruby_plugin, - ruby_current_script, - c_completion, - c_description, - &weechat_ruby_api_hook_completion_cb, - c_function, - c_data)); - - API_RETURN_STRING_FREE(result); -} - -static VALUE -weechat_ruby_api_hook_completion_get_string (VALUE class, VALUE completion, - VALUE property) -{ - char *c_completion, *c_property; - const char *result; - - API_INIT_FUNC(1, "hook_completion_get_string", API_RETURN_EMPTY); - if (NIL_P (completion) || NIL_P (property)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - Check_Type (completion, T_STRING); - Check_Type (property, T_STRING); - - c_completion = StringValuePtr (completion); - c_property = StringValuePtr (property); - - result = weechat_hook_completion_get_string (API_STR2PTR(c_completion), - c_property); - - API_RETURN_STRING(result); -} - -static VALUE -weechat_ruby_api_hook_completion_list_add (VALUE class, VALUE completion, - VALUE word, VALUE nick_completion, - VALUE where) -{ - char *c_completion, *c_word, *c_where; - int c_nick_completion; - - API_INIT_FUNC(1, "hook_completion_list_add", API_RETURN_ERROR); - if (NIL_P (completion) || NIL_P (word) || NIL_P (nick_completion) - || NIL_P (where)) - API_WRONG_ARGS(API_RETURN_ERROR); - - Check_Type (completion, T_STRING); - Check_Type (word, T_STRING); - Check_Type (nick_completion, T_FIXNUM); - Check_Type (where, T_STRING); - - c_completion = StringValuePtr (completion); - c_word = StringValuePtr (word); - c_nick_completion = FIX2INT (nick_completion); - c_where = StringValuePtr (where); - - weechat_hook_completion_list_add (API_STR2PTR(c_completion), - c_word, - c_nick_completion, - c_where); - - API_RETURN_OK; -} - char * weechat_ruby_api_hook_modifier_cb (const void *pointer, void *data, const char *modifier, @@ -6246,6 +6246,9 @@ weechat_ruby_api_init (VALUE ruby_mWeechat) API_DEF_FUNC(print_y, 3); API_DEF_FUNC(log_print, 1); API_DEF_FUNC(hook_command, 7); + API_DEF_FUNC(hook_completion, 4); + API_DEF_FUNC(hook_completion_get_string, 2); + API_DEF_FUNC(hook_completion_list_add, 4); API_DEF_FUNC(hook_command_run, 3); API_DEF_FUNC(hook_timer, 5); API_DEF_FUNC(hook_fd, 6); @@ -6258,9 +6261,6 @@ weechat_ruby_api_init (VALUE ruby_mWeechat) API_DEF_FUNC(hook_hsignal, 3); API_DEF_FUNC(hook_hsignal_send, 2); API_DEF_FUNC(hook_config, 3); - API_DEF_FUNC(hook_completion, 4); - API_DEF_FUNC(hook_completion_get_string, 2); - API_DEF_FUNC(hook_completion_list_add, 4); API_DEF_FUNC(hook_modifier, 3); API_DEF_FUNC(hook_modifier_exec, 3); API_DEF_FUNC(hook_info, 5); diff --git a/src/plugins/tcl/weechat-tcl-api.c b/src/plugins/tcl/weechat-tcl-api.c index 75db35ab3..f9b23cc5f 100644 --- a/src/plugins/tcl/weechat-tcl-api.c +++ b/src/plugins/tcl/weechat-tcl-api.c @@ -2244,6 +2244,122 @@ API_FUNC(hook_command) } int +weechat_tcl_api_hook_completion_cb (const void *pointer, void *data, + const char *completion_item, + struct t_gui_buffer *buffer, + struct t_gui_completion *completion) +{ + struct t_plugin_script *script; + void *func_argv[4]; + char empty_arg[1] = { '\0' }; + const char *ptr_function, *ptr_data; + int *rc, ret; + + script = (struct t_plugin_script *)pointer; + plugin_script_get_function_and_data (data, &ptr_function, &ptr_data); + + if (ptr_function && ptr_function[0]) + { + func_argv[0] = (ptr_data) ? (char *)ptr_data : empty_arg; + func_argv[1] = (completion_item) ? (char *)completion_item : empty_arg; + func_argv[2] = API_PTR2STR(buffer); + func_argv[3] = API_PTR2STR(completion); + + rc = (int *) weechat_tcl_exec (script, + WEECHAT_SCRIPT_EXEC_INT, + ptr_function, + "ssss", func_argv); + + if (!rc) + ret = WEECHAT_RC_ERROR; + else + { + ret = *rc; + free (rc); + } + if (func_argv[2]) + free (func_argv[2]); + if (func_argv[3]) + free (func_argv[3]); + + return ret; + } + + return WEECHAT_RC_ERROR; +} + +API_FUNC(hook_completion) +{ + Tcl_Obj *objp; + char *result, *completion, *description, *function, *data; + int i; + + API_INIT_FUNC(1, "hook_completion", API_RETURN_EMPTY); + if (objc < 5) + API_WRONG_ARGS(API_RETURN_EMPTY); + + completion = Tcl_GetStringFromObj (objv[1], &i); + description = Tcl_GetStringFromObj (objv[2], &i); + function = Tcl_GetStringFromObj (objv[3], &i); + data = Tcl_GetStringFromObj (objv[4], &i); + + result = API_PTR2STR(plugin_script_api_hook_completion (weechat_tcl_plugin, + tcl_current_script, + completion, + description, + &weechat_tcl_api_hook_completion_cb, + function, + data)); + + API_RETURN_STRING_FREE(result); +} + +API_FUNC(hook_completion_get_string) +{ + Tcl_Obj *objp; + char *completion, *property; + const char *result; + int i; + + API_INIT_FUNC(1, "hook_completion_get_string", API_RETURN_EMPTY); + if (objc < 3) + API_WRONG_ARGS(API_RETURN_EMPTY); + + completion = Tcl_GetStringFromObj (objv[1], &i); + property = Tcl_GetStringFromObj (objv[2], &i); + + result = weechat_hook_completion_get_string (API_STR2PTR(completion), + property); + + API_RETURN_STRING(result); +} + +API_FUNC(hook_completion_list_add) +{ + Tcl_Obj *objp; + char *completion, *word, *where; + int i, nick_completion; + + API_INIT_FUNC(1, "hook_completion_list_add", API_RETURN_ERROR); + if (objc < 5) + API_WRONG_ARGS(API_RETURN_ERROR); + + if (Tcl_GetIntFromObj (interp, objv[3], &nick_completion) != TCL_OK) + API_WRONG_ARGS(API_RETURN_ERROR); + + completion = Tcl_GetStringFromObj (objv[1], &i); + word = Tcl_GetStringFromObj (objv[2], &i); + where = Tcl_GetStringFromObj (objv[4], &i); + + weechat_hook_completion_list_add (API_STR2PTR(completion), + word, + nick_completion, /* nick_completion */ + where); + + API_RETURN_OK; +} + +int weechat_tcl_api_hook_command_run_cb (const void *pointer, void *data, struct t_gui_buffer *buffer, const char *command) @@ -3025,122 +3141,6 @@ API_FUNC(hook_config) API_RETURN_STRING_FREE(result); } -int -weechat_tcl_api_hook_completion_cb (const void *pointer, void *data, - const char *completion_item, - struct t_gui_buffer *buffer, - struct t_gui_completion *completion) -{ - struct t_plugin_script *script; - void *func_argv[4]; - char empty_arg[1] = { '\0' }; - const char *ptr_function, *ptr_data; - int *rc, ret; - - script = (struct t_plugin_script *)pointer; - plugin_script_get_function_and_data (data, &ptr_function, &ptr_data); - - if (ptr_function && ptr_function[0]) - { - func_argv[0] = (ptr_data) ? (char *)ptr_data : empty_arg; - func_argv[1] = (completion_item) ? (char *)completion_item : empty_arg; - func_argv[2] = API_PTR2STR(buffer); - func_argv[3] = API_PTR2STR(completion); - - rc = (int *) weechat_tcl_exec (script, - WEECHAT_SCRIPT_EXEC_INT, - ptr_function, - "ssss", func_argv); - - if (!rc) - ret = WEECHAT_RC_ERROR; - else - { - ret = *rc; - free (rc); - } - if (func_argv[2]) - free (func_argv[2]); - if (func_argv[3]) - free (func_argv[3]); - - return ret; - } - - return WEECHAT_RC_ERROR; -} - -API_FUNC(hook_completion) -{ - Tcl_Obj *objp; - char *result, *completion, *description, *function, *data; - int i; - - API_INIT_FUNC(1, "hook_completion", API_RETURN_EMPTY); - if (objc < 5) - API_WRONG_ARGS(API_RETURN_EMPTY); - - completion = Tcl_GetStringFromObj (objv[1], &i); - description = Tcl_GetStringFromObj (objv[2], &i); - function = Tcl_GetStringFromObj (objv[3], &i); - data = Tcl_GetStringFromObj (objv[4], &i); - - result = API_PTR2STR(plugin_script_api_hook_completion (weechat_tcl_plugin, - tcl_current_script, - completion, - description, - &weechat_tcl_api_hook_completion_cb, - function, - data)); - - API_RETURN_STRING_FREE(result); -} - -API_FUNC(hook_completion_get_string) -{ - Tcl_Obj *objp; - char *completion, *property; - const char *result; - int i; - - API_INIT_FUNC(1, "hook_completion_get_string", API_RETURN_EMPTY); - if (objc < 3) - API_WRONG_ARGS(API_RETURN_EMPTY); - - completion = Tcl_GetStringFromObj (objv[1], &i); - property = Tcl_GetStringFromObj (objv[2], &i); - - result = weechat_hook_completion_get_string (API_STR2PTR(completion), - property); - - API_RETURN_STRING(result); -} - -API_FUNC(hook_completion_list_add) -{ - Tcl_Obj *objp; - char *completion, *word, *where; - int i, nick_completion; - - API_INIT_FUNC(1, "hook_completion_list_add", API_RETURN_ERROR); - if (objc < 5) - API_WRONG_ARGS(API_RETURN_ERROR); - - if (Tcl_GetIntFromObj (interp, objv[3], &nick_completion) != TCL_OK) - API_WRONG_ARGS(API_RETURN_ERROR); - - completion = Tcl_GetStringFromObj (objv[1], &i); - word = Tcl_GetStringFromObj (objv[2], &i); - where = Tcl_GetStringFromObj (objv[4], &i); - - weechat_hook_completion_list_add (API_STR2PTR(completion), - word, - nick_completion, /* nick_completion */ - where); - - API_RETURN_OK; -} - char * weechat_tcl_api_hook_modifier_cb (const void *pointer, void *data, const char *modifier, @@ -5587,6 +5587,9 @@ void weechat_tcl_api_init (Tcl_Interp *interp) API_DEF_FUNC(print_y); API_DEF_FUNC(log_print); API_DEF_FUNC(hook_command); + API_DEF_FUNC(hook_completion); + API_DEF_FUNC(hook_completion_get_string); + API_DEF_FUNC(hook_completion_list_add); API_DEF_FUNC(hook_command_run); API_DEF_FUNC(hook_timer); API_DEF_FUNC(hook_fd); @@ -5599,9 +5602,6 @@ void weechat_tcl_api_init (Tcl_Interp *interp) API_DEF_FUNC(hook_hsignal); API_DEF_FUNC(hook_hsignal_send); API_DEF_FUNC(hook_config); - API_DEF_FUNC(hook_completion); - API_DEF_FUNC(hook_completion_get_string); - API_DEF_FUNC(hook_completion_list_add); API_DEF_FUNC(hook_modifier); API_DEF_FUNC(hook_modifier_exec); API_DEF_FUNC(hook_info); |