diff options
author | Sebastien Helleu <flashcode@flashtux.org> | 2008-09-29 18:30:15 +0200 |
---|---|---|
committer | Sebastien Helleu <flashcode@flashtux.org> | 2008-09-29 18:30:15 +0200 |
commit | 813e40632bc748447091ea8c693d31b378c2d520 (patch) | |
tree | a9f3778ab19408540f87dbfbeec249f698adbe96 /src/plugins | |
parent | 966541d4162d1ee9c30bbdf3143e3514bb52f728 (diff) | |
download | weechat-813e40632bc748447091ea8c693d31b378c2d520.zip |
Fix bug with arguments of function "config_new_option" in scripts API
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/scripts/lua/weechat-lua-api.c | 115 | ||||
-rw-r--r-- | src/plugins/scripts/perl/weechat-perl-api.c | 93 | ||||
-rw-r--r-- | src/plugins/scripts/python/weechat-python-api.c | 96 | ||||
-rw-r--r-- | src/plugins/scripts/ruby/weechat-ruby-api.c | 108 | ||||
-rw-r--r-- | src/plugins/scripts/script-api.c | 4 | ||||
-rw-r--r-- | src/plugins/scripts/script-api.h | 15 |
6 files changed, 382 insertions, 49 deletions
diff --git a/src/plugins/scripts/lua/weechat-lua-api.c b/src/plugins/scripts/lua/weechat-lua-api.c index eb005bb8c..2bde584c2 100644 --- a/src/plugins/scripts/lua/weechat-lua-api.c +++ b/src/plugins/scripts/lua/weechat-lua-api.c @@ -1224,27 +1224,99 @@ weechat_lua_api_config_search_section (lua_State *L) } /* + * weechat_lua_api_config_option_check_value_cb: callback for checking new + * value for option + */ + +void +weechat_lua_api_config_option_check_value_cb (void *data, + struct t_config_option *option, + const char *value) +{ + struct t_script_callback *script_callback; + char *lua_argv[3]; + int *rc; + + script_callback = (struct t_script_callback *)data; + + if (script_callback->function && script_callback->function[0]) + { + lua_argv[0] = script_ptr2str (option); + lua_argv[1] = (char *)value; + lua_argv[2] = NULL; + + rc = (int *) weechat_lua_exec (script_callback->script, + WEECHAT_SCRIPT_EXEC_INT, + script_callback->function, + lua_argv); + + if (lua_argv[0]) + free (lua_argv[0]); + + if (rc) + free (rc); + } +} + +/* * weechat_lua_api_config_option_change_cb: callback for option changed */ void -weechat_lua_api_config_option_change_cb (void *data) +weechat_lua_api_config_option_change_cb (void *data, + struct t_config_option *option) { struct t_script_callback *script_callback; - char *lua_argv[1]; + char *lua_argv[2]; + int *rc; + + script_callback = (struct t_script_callback *)data; + + if (script_callback->function && script_callback->function[0]) + { + lua_argv[0] = script_ptr2str (option); + lua_argv[1] = NULL; + + rc = (int *) weechat_lua_exec (script_callback->script, + WEECHAT_SCRIPT_EXEC_INT, + script_callback->function, + lua_argv); + + if (lua_argv[0]) + free (lua_argv[0]); + + if (rc) + free (rc); + } +} + +/* + * weechat_lua_api_config_option_delete_cb: callback when option is deleted + */ + +void +weechat_lua_api_config_option_delete_cb (void *data, + struct t_config_option *option) +{ + struct t_script_callback *script_callback; + char *lua_argv[2]; int *rc; script_callback = (struct t_script_callback *)data; if (script_callback->function && script_callback->function[0]) { - lua_argv[0] = NULL; + lua_argv[0] = script_ptr2str (option); + lua_argv[1] = NULL; rc = (int *) weechat_lua_exec (script_callback->script, WEECHAT_SCRIPT_EXEC_INT, script_callback->function, lua_argv); + if (lua_argv[0]) + free (lua_argv[0]); + if (rc) free (rc); } @@ -1258,7 +1330,8 @@ static int weechat_lua_api_config_new_option (lua_State *L) { const char *config_file, *section, *name, *type, *description; - const char *string_values, *default_value, *function; + const char *string_values, *default_value; + const char *function_check_value, *function_change, *function_delete; char *result; int n, min, max; @@ -1280,26 +1353,30 @@ weechat_lua_api_config_new_option (lua_State *L) min = 0; max = 0; default_value = NULL; - function = NULL; + function_check_value = NULL; + function_change = NULL; + function_delete = NULL; n = lua_gettop (lua_current_interpreter); - if (n < 10) + if (n < 12) { WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_new_option"); LUA_RETURN_EMPTY; } - config_file = lua_tostring (lua_current_interpreter, -10); - section = lua_tostring (lua_current_interpreter, -9); - name = lua_tostring (lua_current_interpreter, -8); - type = lua_tostring (lua_current_interpreter, -7); - description = lua_tostring (lua_current_interpreter, -6); - string_values = lua_tostring (lua_current_interpreter, -5); - min = lua_tonumber (lua_current_interpreter, -4); - max = lua_tonumber (lua_current_interpreter, -3); - default_value = lua_tostring (lua_current_interpreter, -2); - function = lua_tostring (lua_current_interpreter, -1); + config_file = lua_tostring (lua_current_interpreter, -12); + section = lua_tostring (lua_current_interpreter, -11); + name = lua_tostring (lua_current_interpreter, -10); + type = lua_tostring (lua_current_interpreter, -9); + description = lua_tostring (lua_current_interpreter, -8); + string_values = lua_tostring (lua_current_interpreter, -7); + min = lua_tonumber (lua_current_interpreter, -6); + max = lua_tonumber (lua_current_interpreter, -5); + default_value = lua_tostring (lua_current_interpreter, -4); + function_check_value = lua_tostring (lua_current_interpreter, -3); + function_change = lua_tostring (lua_current_interpreter, -2); + function_delete = lua_tostring (lua_current_interpreter, -1); result = script_ptr2str (script_api_config_new_option (weechat_lua_plugin, lua_current_script, @@ -1312,8 +1389,12 @@ weechat_lua_api_config_new_option (lua_State *L) min, max, default_value, + &weechat_lua_api_config_option_check_value_cb, + function_check_value, &weechat_lua_api_config_option_change_cb, - function)); + function_change, + &weechat_lua_api_config_option_delete_cb, + function_delete)); LUA_RETURN_STRING_FREE(result); } diff --git a/src/plugins/scripts/perl/weechat-perl-api.c b/src/plugins/scripts/perl/weechat-perl-api.c index b75c00290..c9fb1bd44 100644 --- a/src/plugins/scripts/perl/weechat-perl-api.c +++ b/src/plugins/scripts/perl/weechat-perl-api.c @@ -1028,27 +1028,99 @@ static XS (XS_weechat_config_search_section) } /* + * weechat_perl_api_config_option_check_value_cb: callback for checking new + * value for option + */ + +void +weechat_perl_api_config_option_check_value_cb (void *data, + struct t_config_option *option, + const char *value) +{ + struct t_script_callback *script_callback; + char *perl_argv[3]; + int *rc; + + script_callback = (struct t_script_callback *)data; + + if (script_callback->function && script_callback->function[0]) + { + perl_argv[0] = script_ptr2str (option); + perl_argv[1] = (char *)value; + perl_argv[2] = NULL; + + rc = (int *) weechat_perl_exec (script_callback->script, + WEECHAT_SCRIPT_EXEC_INT, + script_callback->function, + perl_argv); + + if (perl_argv[0]) + free (perl_argv[0]); + + if (rc) + free (rc); + } +} + +/* * weechat_perl_api_config_option_change_cb: callback for option changed */ void -weechat_perl_api_config_option_change_cb (void *data) +weechat_perl_api_config_option_change_cb (void *data, + struct t_config_option *option) { struct t_script_callback *script_callback; - char *perl_argv[1]; + char *perl_argv[2]; + int *rc; + + script_callback = (struct t_script_callback *)data; + + if (script_callback->function && script_callback->function[0]) + { + perl_argv[0] = script_ptr2str (option); + perl_argv[1] = NULL; + + rc = (int *) weechat_perl_exec (script_callback->script, + WEECHAT_SCRIPT_EXEC_INT, + script_callback->function, + perl_argv); + + if (perl_argv[0]) + free (perl_argv[0]); + + if (rc) + free (rc); + } +} + +/* + * weechat_perl_api_config_option_delete_cb: callback when option is deleted + */ + +void +weechat_perl_api_config_option_delete_cb (void *data, + struct t_config_option *option) +{ + struct t_script_callback *script_callback; + char *perl_argv[2]; int *rc; script_callback = (struct t_script_callback *)data; if (script_callback->function && script_callback->function[0]) { - perl_argv[0] = NULL; + perl_argv[0] = script_ptr2str (option); + perl_argv[1] = NULL; rc = (int *) weechat_perl_exec (script_callback->script, WEECHAT_SCRIPT_EXEC_INT, script_callback->function, perl_argv); + if (perl_argv[0]) + free (perl_argv[0]); + if (rc) free (rc); } @@ -1061,7 +1133,8 @@ weechat_perl_api_config_option_change_cb (void *data) static XS (XS_weechat_config_new_option) { char *result, *config_file, *section, *name, *type; - char *description, *string_values, *default_value, *function; + char *description, *string_values, *default_value; + char *function_check_value, *function_change, *function_delete; dXSARGS; /* make C compiler happy */ @@ -1073,7 +1146,7 @@ static XS (XS_weechat_config_new_option) PERL_RETURN_EMPTY; } - if (items < 10) + if (items < 12) { WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_new_option"); PERL_RETURN_EMPTY; @@ -1086,7 +1159,9 @@ static XS (XS_weechat_config_new_option) description = SvPV (ST (4), PL_na); string_values = SvPV (ST (5), PL_na); default_value = SvPV (ST (8), PL_na); - function = SvPV (ST (9), PL_na); + function_check_value = SvPV (ST (9), PL_na); + function_change = SvPV (ST (10), PL_na); + function_delete = SvPV (ST (12), PL_na); result = script_ptr2str (script_api_config_new_option (weechat_perl_plugin, perl_current_script, script_str2ptr (config_file), @@ -1098,8 +1173,12 @@ static XS (XS_weechat_config_new_option) SvIV (ST (6)), /* min */ SvIV (ST (7)), /* max */ default_value, + &weechat_perl_api_config_option_check_value_cb, + function_check_value, &weechat_perl_api_config_option_change_cb, - function)); /* perl function */ + function_change, + &weechat_perl_api_config_option_delete_cb, + function_delete)); PERL_RETURN_STRING_FREE(result); } diff --git a/src/plugins/scripts/python/weechat-python-api.c b/src/plugins/scripts/python/weechat-python-api.c index 6184a472d..4ca9bd331 100644 --- a/src/plugins/scripts/python/weechat-python-api.c +++ b/src/plugins/scripts/python/weechat-python-api.c @@ -1083,27 +1083,99 @@ weechat_python_api_config_search_section (PyObject *self, PyObject *args) } /* + * weechat_python_api_config_option_check_cb: callback for checking new value + * for option + */ + +void +weechat_python_api_config_option_check_value_cb (void *data, + struct t_config_option *option, + const char *value) +{ + struct t_script_callback *script_callback; + char *python_argv[3]; + int *rc; + + script_callback = (struct t_script_callback *)data; + + if (script_callback->function && script_callback->function[0]) + { + python_argv[0] = script_ptr2str (option); + python_argv[1] = (char *)value; + python_argv[2] = NULL; + + rc = (int *) weechat_python_exec (script_callback->script, + WEECHAT_SCRIPT_EXEC_INT, + script_callback->function, + python_argv); + + if (python_argv[0]) + free (python_argv[0]); + + if (rc) + free (rc); + } +} + +/* * weechat_python_api_config_option_change_cb: callback for option changed */ void -weechat_python_api_config_option_change_cb (void *data) +weechat_python_api_config_option_change_cb (void *data, + struct t_config_option *option) { struct t_script_callback *script_callback; - char *python_argv[1]; + char *python_argv[2]; int *rc; script_callback = (struct t_script_callback *)data; if (script_callback->function && script_callback->function[0]) { - python_argv[0] = NULL; + python_argv[0] = script_ptr2str (option); + python_argv[1] = NULL; rc = (int *) weechat_python_exec (script_callback->script, WEECHAT_SCRIPT_EXEC_INT, script_callback->function, python_argv); + if (python_argv[0]) + free (python_argv[0]); + + if (rc) + free (rc); + } +} + +/* + * weechat_python_api_config_option_delete_cb: callback when option is deleted + */ + +void +weechat_python_api_config_option_delete_cb (void *data, + struct t_config_option *option) +{ + struct t_script_callback *script_callback; + char *python_argv[2]; + int *rc; + + script_callback = (struct t_script_callback *)data; + + if (script_callback->function && script_callback->function[0]) + { + python_argv[0] = script_ptr2str (option); + python_argv[1] = NULL; + + rc = (int *) weechat_python_exec (script_callback->script, + WEECHAT_SCRIPT_EXEC_INT, + script_callback->function, + python_argv); + + if (python_argv[0]) + free (python_argv[0]); + if (rc) free (rc); } @@ -1117,7 +1189,8 @@ static PyObject * weechat_python_api_config_new_option (PyObject *self, PyObject *args) { char *config_file, *section, *name, *type, *description, *string_values; - char *default_value, *function, *result; + char *default_value, *result; + char *function_check_value, *function_change, *function_delete; int min, max; PyObject *object; @@ -1137,11 +1210,14 @@ weechat_python_api_config_new_option (PyObject *self, PyObject *args) description = NULL; string_values = NULL; default_value = NULL; - function = NULL; + function_check_value = NULL; + function_change = NULL; + function_delete = NULL; - if (!PyArg_ParseTuple (args, "ssssssiiss", &config_file, §ion, &name, + if (!PyArg_ParseTuple (args, "ssssssiissss", &config_file, §ion, &name, &type, &description, &string_values, &min, &max, - &default_value, &function)) + &default_value, &function_check_value, + &function_change, &function_delete)) { WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_new_option"); PYTHON_RETURN_EMPTY; @@ -1158,8 +1234,12 @@ weechat_python_api_config_new_option (PyObject *self, PyObject *args) min, max, default_value, + &weechat_python_api_config_option_check_value_cb, + function_check_value, &weechat_python_api_config_option_change_cb, - function)); + function_change, + &weechat_python_api_config_option_delete_cb, + function_delete)); PYTHON_RETURN_STRING_FREE(result); } diff --git a/src/plugins/scripts/ruby/weechat-ruby-api.c b/src/plugins/scripts/ruby/weechat-ruby-api.c index 8906b9cc6..d5cdf93fd 100644 --- a/src/plugins/scripts/ruby/weechat-ruby-api.c +++ b/src/plugins/scripts/ruby/weechat-ruby-api.c @@ -1233,27 +1233,99 @@ weechat_ruby_api_config_search_section (VALUE class, VALUE config_file, } /* + * weechat_ruby_api_config_option_check_value_cb: callback for checking new + * value for option + */ + +void +weechat_ruby_api_config_option_check_value_cb (void *data, + struct t_config_option *option, + const char *value) +{ + struct t_script_callback *script_callback; + char *ruby_argv[3]; + int *rc; + + script_callback = (struct t_script_callback *)data; + + if (script_callback->function && script_callback->function[0]) + { + ruby_argv[0] = script_ptr2str (option); + ruby_argv[1] = (char *)value; + ruby_argv[2] = NULL; + + rc = (int *) weechat_ruby_exec (script_callback->script, + WEECHAT_SCRIPT_EXEC_INT, + script_callback->function, + ruby_argv); + + if (ruby_argv[0]) + free (ruby_argv[0]); + + if (rc) + free (rc); + } +} + +/* * weechat_ruby_api_config_option_change_cb: callback for option changed */ void -weechat_ruby_api_config_option_change_cb (void *data) +weechat_ruby_api_config_option_change_cb (void *data, + struct t_config_option *option) { struct t_script_callback *script_callback; - char *ruby_argv[1]; + char *ruby_argv[2]; int *rc; script_callback = (struct t_script_callback *)data; if (script_callback->function && script_callback->function[0]) { - ruby_argv[0] = NULL; + ruby_argv[0] = script_ptr2str (option); + ruby_argv[1] = NULL; rc = (int *) weechat_ruby_exec (script_callback->script, WEECHAT_SCRIPT_EXEC_INT, script_callback->function, ruby_argv); + if (ruby_argv[0]) + free (ruby_argv[0]); + + if (rc) + free (rc); + } +} + +/* + * weechat_ruby_api_config_option_delete_cb: callback when option is deleted + */ + +void +weechat_ruby_api_config_option_delete_cb (void *data, + struct t_config_option *option) +{ + struct t_script_callback *script_callback; + char *ruby_argv[2]; + int *rc; + + script_callback = (struct t_script_callback *)data; + + if (script_callback->function && script_callback->function[0]) + { + ruby_argv[0] = script_ptr2str (option); + ruby_argv[1] = NULL; + + rc = (int *) weechat_ruby_exec (script_callback->script, + WEECHAT_SCRIPT_EXEC_INT, + script_callback->function, + ruby_argv); + + if (ruby_argv[0]) + free (ruby_argv[0]); + if (rc) free (rc); } @@ -1268,10 +1340,13 @@ weechat_ruby_api_config_new_option (VALUE class, VALUE config_file, VALUE section, VALUE name, VALUE type, VALUE description, VALUE string_values, VALUE min, VALUE max, VALUE default_value, - VALUE function) + VALUE function_check_value, + VALUE function_change, + VALUE function_delete) { char *c_config_file, *c_section, *c_name, *c_type, *c_description; - char *c_string_values, *c_default_value, *c_function, *result; + char *c_string_values, *c_default_value, *result; + char *c_function_check_value, *c_function_change, *c_function_delete; int c_min, c_max; VALUE return_value; @@ -1293,11 +1368,14 @@ weechat_ruby_api_config_new_option (VALUE class, VALUE config_file, c_min = 0; c_max = 0; c_default_value = NULL; - c_function = NULL; + c_function_check_value = NULL; + c_function_change = NULL; + c_function_delete = NULL; if (NIL_P (config_file) || NIL_P (section) || NIL_P (name) || NIL_P (type) || NIL_P (description) || NIL_P (string_values) - || NIL_P (default_value) || NIL_P (function)) + || NIL_P (default_value) || NIL_P (function_check_value) + || NIL_P (function_change) || NIL_P (function_delete)) { WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_new_option"); RUBY_RETURN_EMPTY; @@ -1312,7 +1390,9 @@ weechat_ruby_api_config_new_option (VALUE class, VALUE config_file, Check_Type (min, T_FIXNUM); Check_Type (max, T_FIXNUM); Check_Type (default_value, T_STRING); - Check_Type (function, T_STRING); + Check_Type (function_check_value, T_STRING); + Check_Type (function_change, T_STRING); + Check_Type (function_delete, T_STRING); c_config_file = STR2CSTR (config_file); c_section = STR2CSTR (section); @@ -1323,7 +1403,9 @@ weechat_ruby_api_config_new_option (VALUE class, VALUE config_file, c_min = FIX2INT (min); c_max = FIX2INT (max); c_default_value = STR2CSTR (default_value); - c_function = STR2CSTR (function); + c_function_check_value = STR2CSTR (function_check_value); + c_function_change = STR2CSTR (function_change); + c_function_delete = STR2CSTR (function_delete); result = script_ptr2str (script_api_config_new_option (weechat_ruby_plugin, ruby_current_script, @@ -1336,8 +1418,12 @@ weechat_ruby_api_config_new_option (VALUE class, VALUE config_file, c_min, c_max, c_default_value, + &weechat_ruby_api_config_option_check_value_cb, + c_function_check_value, &weechat_ruby_api_config_option_change_cb, - c_function)); + c_function_change, + &weechat_ruby_api_config_option_delete_cb, + c_function_delete)); RUBY_RETURN_STRING_FREE(result); } @@ -5230,7 +5316,7 @@ weechat_ruby_api_init (VALUE ruby_mWeechat) rb_define_module_function (ruby_mWeechat, "config_new", &weechat_ruby_api_config_new, 2); rb_define_module_function (ruby_mWeechat, "config_new_section", &weechat_ruby_api_config_new_section, 8); rb_define_module_function (ruby_mWeechat, "config_search_section", &weechat_ruby_api_config_search_section, 2); - rb_define_module_function (ruby_mWeechat, "config_new_option", &weechat_ruby_api_config_new_option, 10); + rb_define_module_function (ruby_mWeechat, "config_new_option", &weechat_ruby_api_config_new_option, 12); rb_define_module_function (ruby_mWeechat, "config_search_option", &weechat_ruby_api_config_search_option, 3); rb_define_module_function (ruby_mWeechat, "config_string_to_boolean", &weechat_ruby_api_config_string_to_boolean, 1); rb_define_module_function (ruby_mWeechat, "config_option_reset", &weechat_ruby_api_config_option_reset, 2); diff --git a/src/plugins/scripts/script-api.c b/src/plugins/scripts/script-api.c index 10aea1147..e2b4c604c 100644 --- a/src/plugins/scripts/script-api.c +++ b/src/plugins/scripts/script-api.c @@ -396,7 +396,7 @@ script_api_config_new_option (struct t_weechat_plugin *weechat_plugin, if (new_script_callback2) { new_script_callback2->script = script; - new_script_callback2->function = strdup (function_check_value); + new_script_callback2->function = strdup (function_change); new_script_callback2->config_file = config_file; new_script_callback2->config_section = section; new_script_callback2->config_option = new_option; @@ -406,7 +406,7 @@ script_api_config_new_option (struct t_weechat_plugin *weechat_plugin, if (new_script_callback3) { new_script_callback3->script = script; - new_script_callback3->function = strdup (function_check_value); + new_script_callback3->function = strdup (function_delete); new_script_callback3->config_file = config_file; new_script_callback3->config_section = section; new_script_callback3->config_option = new_option; diff --git a/src/plugins/scripts/script-api.h b/src/plugins/scripts/script-api.h index 2a7f9809a..17a4717a9 100644 --- a/src/plugins/scripts/script-api.h +++ b/src/plugins/scripts/script-api.h @@ -60,10 +60,17 @@ extern struct t_config_option *script_api_config_new_option (struct t_weechat_pl const char *type, const char *description, const char *string_values, - int min, int max, - const char *default_value, - void (*callback_change)(void *data), - const char *function); + int min, int max, const char *default_value, + void (*callback_check_value)(void *data, + struct t_config_option *option, + const char *value), + const char *function_check_value, + void (*callback_change)(void *data, + struct t_config_option *option), + const char *function_change, + void (*callback_delete)(void *data, + struct t_config_option *option), + const char *function_delete); extern void script_api_config_free (struct t_weechat_plugin *weechat_plugin, struct t_plugin_script *script, struct t_config_file *config_file); |