1
0
mirror of https://github.com/weechat/weechat.git synced 2026-06-30 06:46:38 +02:00

Fix bug with arguments of function "config_new_option" in scripts API

This commit is contained in:
Sebastien Helleu
2008-09-29 18:30:15 +02:00
parent 966541d416
commit 813e40632b
6 changed files with 386 additions and 53 deletions
+99 -18
View File
@@ -1224,27 +1224,99 @@ weechat_lua_api_config_search_section (lua_State *L)
}
/*
* weechat_lua_api_config_option_change_cb: callback for option changed
* weechat_lua_api_config_option_check_value_cb: callback for checking new
* value for option
*/
void
weechat_lua_api_config_option_change_cb (void *data)
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[1];
char *lua_argv[3];
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] = (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,
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] = 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] = 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);
}
+87 -8
View File
@@ -1028,27 +1028,99 @@ static XS (XS_weechat_config_search_section)
}
/*
* weechat_perl_api_config_option_change_cb: callback for option changed
* weechat_perl_api_config_option_check_value_cb: callback for checking new
* value for option
*/
void
weechat_perl_api_config_option_change_cb (void *data)
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[1];
char *perl_argv[3];
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] = (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,
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] = 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] = 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);
}
@@ -1083,27 +1083,99 @@ weechat_python_api_config_search_section (PyObject *self, PyObject *args)
}
/*
* weechat_python_api_config_option_change_cb: callback for option changed
* weechat_python_api_config_option_check_cb: callback for checking new value
* for option
*/
void
weechat_python_api_config_option_change_cb (void *data)
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[1];
char *python_argv[3];
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] = (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,
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);
}
}
/*
* 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, &section, &name,
if (!PyArg_ParseTuple (args, "ssssssiissss", &config_file, &section, &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);
}
+98 -12
View File
@@ -1233,27 +1233,99 @@ weechat_ruby_api_config_search_section (VALUE class, VALUE config_file,
}
/*
* weechat_ruby_api_config_option_change_cb: callback for option changed
* weechat_ruby_api_config_option_check_value_cb: callback for checking new
* value for option
*/
void
weechat_ruby_api_config_option_change_cb (void *data)
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[1];
char *ruby_argv[3];
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] = (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,
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);
}
}
/*
* 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);
+2 -2
View File
@@ -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;
+11 -4
View File
@@ -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);