1
0
mirror of https://github.com/weechat/weechat.git synced 2026-06-12 14:14:48 +02:00

scripts: add functions config_enum and config_enum_default in scripting API (issue #1973)

This commit is contained in:
Sébastien Helleu
2023-09-09 08:54:33 +02:00
parent 9fada89f96
commit d9555cc567
14 changed files with 280 additions and 2 deletions
+30
View File
@@ -1659,6 +1659,34 @@ weechat_guile_api_config_color_default (SCM option)
API_RETURN_STRING(result);
}
SCM
weechat_guile_api_config_enum (SCM option)
{
int value;
API_INIT_FUNC(1, "config_enum", API_RETURN_INT(0));
if (!scm_is_string (option))
API_WRONG_ARGS(API_RETURN_INT(0));
value = weechat_config_enum (API_STR2PTR(API_SCM_TO_STRING(option)));
API_RETURN_INT(value);
}
SCM
weechat_guile_api_config_enum_default (SCM option)
{
int value;
API_INIT_FUNC(1, "config_enum_default", API_RETURN_INT(0));
if (!scm_is_string (option))
API_WRONG_ARGS(API_RETURN_INT(0));
value = weechat_config_enum_default (API_STR2PTR(API_SCM_TO_STRING(option)));
API_RETURN_INT(value);
}
SCM
weechat_guile_api_config_write_option (SCM config_file, SCM option)
{
@@ -5227,6 +5255,8 @@ weechat_guile_api_module_init (void *data)
API_DEF_FUNC(config_string_default, 1);
API_DEF_FUNC(config_color, 1);
API_DEF_FUNC(config_color_default, 1);
API_DEF_FUNC(config_enum, 1);
API_DEF_FUNC(config_enum_default, 1);
API_DEF_FUNC(config_write_option, 2);
API_DEF_FUNC(config_write_line, 3);
API_DEF_FUNC(config_write, 1);
+30
View File
@@ -1565,6 +1565,34 @@ API_FUNC(config_color_default)
API_RETURN_STRING(result);
}
API_FUNC(config_enum)
{
int value;
API_INIT_FUNC(1, "config_enum", "s", API_RETURN_INT(0));
v8::String::Utf8Value option(args[0]);
value = weechat_config_enum (
(struct t_config_option *)API_STR2PTR(*option));
API_RETURN_INT(value);
}
API_FUNC(config_enum_default)
{
int value;
API_INIT_FUNC(1, "config_enum_default", "s", API_RETURN_INT(0));
v8::String::Utf8Value option(args[0]);
value = weechat_config_enum_default (
(struct t_config_option *)API_STR2PTR(*option));
API_RETURN_INT(value);
}
API_FUNC(config_write_option)
{
API_INIT_FUNC(1, "config_write_option", "ss", API_RETURN_ERROR);
@@ -5170,6 +5198,8 @@ WeechatJsV8::loadLibs()
API_DEF_FUNC(config_string_default);
API_DEF_FUNC(config_color);
API_DEF_FUNC(config_color_default);
API_DEF_FUNC(config_enum);
API_DEF_FUNC(config_enum_default);
API_DEF_FUNC(config_write_option);
API_DEF_FUNC(config_write_line);
API_DEF_FUNC(config_write);
+34
View File
@@ -1708,6 +1708,38 @@ API_FUNC(config_color_default)
API_RETURN_STRING(result);
}
API_FUNC(config_enum)
{
const char *option;
int value;
API_INIT_FUNC(1, "config_enum", API_RETURN_INT(0));
if (lua_gettop (L) < 1)
API_WRONG_ARGS(API_RETURN_INT(0));
option = lua_tostring (L, -1);
value = weechat_config_enum (API_STR2PTR(option));
API_RETURN_INT(value);
}
API_FUNC(config_enum_default)
{
const char *option;
int value;
API_INIT_FUNC(1, "config_enum_default", API_RETURN_INT(0));
if (lua_gettop (L) < 1)
API_WRONG_ARGS(API_RETURN_INT(0));
option = lua_tostring (L, -1);
value = weechat_config_enum_default (API_STR2PTR(option));
API_RETURN_INT(value);
}
API_FUNC(config_write_option)
{
const char *config_file, *option;
@@ -5531,6 +5563,8 @@ const struct luaL_Reg weechat_lua_api_funcs[] = {
API_DEF_FUNC(config_string_default),
API_DEF_FUNC(config_color),
API_DEF_FUNC(config_color_default),
API_DEF_FUNC(config_enum),
API_DEF_FUNC(config_enum_default),
API_DEF_FUNC(config_write_option),
API_DEF_FUNC(config_write_line),
API_DEF_FUNC(config_write),
+30
View File
@@ -1631,6 +1631,34 @@ API_FUNC(config_color_default)
API_RETURN_STRING(result);
}
API_FUNC(config_enum)
{
int value;
dXSARGS;
API_INIT_FUNC(1, "config_enum", API_RETURN_INT(0));
if (items < 1)
API_WRONG_ARGS(API_RETURN_INT(0));
value = weechat_config_enum (API_STR2PTR(SvPV_nolen (ST (0)))); /* option */
API_RETURN_INT(value);
}
API_FUNC(config_enum_default)
{
int value;
dXSARGS;
API_INIT_FUNC(1, "config_enum_default", API_RETURN_INT(0));
if (items < 1)
API_WRONG_ARGS(API_RETURN_INT(0));
value = weechat_config_enum_default (API_STR2PTR(SvPV_nolen (ST (0)))); /* option */
API_RETURN_INT(value);
}
API_FUNC(config_write_option)
{
char *config_file, *option;
@@ -5480,6 +5508,8 @@ weechat_perl_api_init (pTHX)
API_DEF_FUNC(config_string_default);
API_DEF_FUNC(config_color);
API_DEF_FUNC(config_color_default);
API_DEF_FUNC(config_enum);
API_DEF_FUNC(config_enum_default);
API_DEF_FUNC(config_write_option);
API_DEF_FUNC(config_write_line);
API_DEF_FUNC(config_write);
+34
View File
@@ -1740,6 +1740,40 @@ API_FUNC(config_color_default)
API_RETURN_STRING(result);
}
API_FUNC(config_enum)
{
zend_string *z_option;
struct t_config_option *option;
int result;
API_INIT_FUNC(1, "config_enum", API_RETURN_INT(0));
if (zend_parse_parameters (ZEND_NUM_ARGS(), "S", &z_option) == FAILURE)
API_WRONG_ARGS(API_RETURN_INT(0));
option = (struct t_config_option *)API_STR2PTR(ZSTR_VAL(z_option));
result = weechat_config_enum (option);
API_RETURN_INT(result);
}
API_FUNC(config_enum_default)
{
zend_string *z_option;
struct t_config_option *option;
int result;
API_INIT_FUNC(1, "config_enum_default", API_RETURN_INT(0));
if (zend_parse_parameters (ZEND_NUM_ARGS(), "S", &z_option) == FAILURE)
API_WRONG_ARGS(API_RETURN_INT(0));
option = (struct t_config_option *)API_STR2PTR(ZSTR_VAL(z_option));
result = weechat_config_enum_default (option);
API_RETURN_INT(result);
}
API_FUNC(config_write_option)
{
zend_string *z_config_file, *z_option;
+2
View File
@@ -106,6 +106,8 @@ PHP_FUNCTION(weechat_config_string);
PHP_FUNCTION(weechat_config_string_default);
PHP_FUNCTION(weechat_config_color);
PHP_FUNCTION(weechat_config_color_default);
PHP_FUNCTION(weechat_config_enum);
PHP_FUNCTION(weechat_config_enum_default);
PHP_FUNCTION(weechat_config_write_option);
PHP_FUNCTION(weechat_config_write_line);
PHP_FUNCTION(weechat_config_write);
+2
View File
@@ -164,6 +164,8 @@ const zend_function_entry weechat_functions[] = {
PHP_FE(weechat_config_string_default, arginfo_weechat_config_string_default)
PHP_FE(weechat_config_color, arginfo_weechat_config_color)
PHP_FE(weechat_config_color_default, arginfo_weechat_config_color_default)
PHP_FE(weechat_config_enum, arginfo_weechat_config_enum)
PHP_FE(weechat_config_enum_default, arginfo_weechat_config_enum_default)
PHP_FE(weechat_config_write_option, arginfo_weechat_config_write_option)
PHP_FE(weechat_config_write_line, arginfo_weechat_config_write_line)
PHP_FE(weechat_config_write, arginfo_weechat_config_write)
+2
View File
@@ -72,6 +72,8 @@ function weechat_config_string(string $p0): string {}
function weechat_config_string_default(string $p0): string {}
function weechat_config_color(string $p0): string {}
function weechat_config_color_default(string $p0): string {}
function weechat_config_enum(string $p0): int {}
function weechat_config_enum_default(string $p0): int {}
function weechat_config_write_option(string $p0, string $p1): int {}
function weechat_config_write_line(string $p0, string $p1, string $p2): int {}
function weechat_config_write(string $p0): int {}
+5 -1
View File
@@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: 5c460494eac0e2ed6729ab210df6679f990070d6 */
* Stub hash: d9a98a051023d3904f6e6f94b776386b3b67a5f6 */
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_weechat_register, 0, 7, IS_LONG, 0)
ZEND_ARG_TYPE_INFO(0, p0, IS_STRING, 0)
@@ -181,6 +181,10 @@ ZEND_END_ARG_INFO()
#define arginfo_weechat_config_color_default arginfo_weechat_plugin_get_name
#define arginfo_weechat_config_enum arginfo_weechat_charset_set
#define arginfo_weechat_config_enum_default arginfo_weechat_charset_set
#define arginfo_weechat_config_write_option arginfo_weechat_string_has_highlight
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_weechat_config_write_line, 0, 3, IS_LONG, 0)
+5 -1
View File
@@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: 5c460494eac0e2ed6729ab210df6679f990070d6 */
* Stub hash: d9a98a051023d3904f6e6f94b776386b3b67a5f6 */
ZEND_BEGIN_ARG_INFO_EX(arginfo_weechat_register, 0, 0, 7)
ZEND_ARG_INFO(0, p0)
@@ -146,6 +146,10 @@ ZEND_END_ARG_INFO()
#define arginfo_weechat_config_color_default arginfo_weechat_plugin_get_name
#define arginfo_weechat_config_enum arginfo_weechat_plugin_get_name
#define arginfo_weechat_config_enum_default arginfo_weechat_plugin_get_name
#define arginfo_weechat_config_write_option arginfo_weechat_iconv_to_internal
#define arginfo_weechat_config_write_line arginfo_weechat_ngettext
+32
View File
@@ -1630,6 +1630,36 @@ API_FUNC(config_color_default)
API_RETURN_STRING(result);
}
API_FUNC(config_enum)
{
char *option;
int value;
API_INIT_FUNC(1, "config_enum", API_RETURN_INT(0));
option = NULL;
if (!PyArg_ParseTuple (args, "s", &option))
API_WRONG_ARGS(API_RETURN_INT(0));
value = weechat_config_enum (API_STR2PTR(option));
API_RETURN_INT(value);
}
API_FUNC(config_enum_default)
{
char *option;
int value;
API_INIT_FUNC(1, "config_enum_default", API_RETURN_INT(0));
option = NULL;
if (!PyArg_ParseTuple (args, "s", &option))
API_WRONG_ARGS(API_RETURN_INT(0));
value = weechat_config_enum_default (API_STR2PTR(option));
API_RETURN_INT(value);
}
API_FUNC(config_write_option)
{
char *config_file, *option;
@@ -5396,6 +5426,8 @@ PyMethodDef weechat_python_funcs[] =
API_DEF_FUNC(config_string_default),
API_DEF_FUNC(config_color),
API_DEF_FUNC(config_color_default),
API_DEF_FUNC(config_enum),
API_DEF_FUNC(config_enum_default),
API_DEF_FUNC(config_write_option),
API_DEF_FUNC(config_write_line),
API_DEF_FUNC(config_write),
+40
View File
@@ -2000,6 +2000,44 @@ weechat_ruby_api_config_color_default (VALUE class, VALUE option)
API_RETURN_STRING(result);
}
static VALUE
weechat_ruby_api_config_enum (VALUE class, VALUE option)
{
char *c_option;
int value;
API_INIT_FUNC(1, "config_enum", API_RETURN_INT(0));
if (NIL_P (option))
API_WRONG_ARGS(API_RETURN_INT(0));
Check_Type (option, T_STRING);
c_option = StringValuePtr (option);
value = weechat_config_enum (API_STR2PTR(c_option));
API_RETURN_INT(value);
}
static VALUE
weechat_ruby_api_config_enum_default (VALUE class, VALUE option)
{
char *c_option;
int value;
API_INIT_FUNC(1, "config_enum_default", API_RETURN_INT(0));
if (NIL_P (option))
API_WRONG_ARGS(API_RETURN_INT(0));
Check_Type (option, T_STRING);
c_option = StringValuePtr (option);
value = weechat_config_enum_default (API_STR2PTR(c_option));
API_RETURN_INT(value);
}
static VALUE
weechat_ruby_api_config_write_option (VALUE class, VALUE config_file,
VALUE option)
@@ -6691,6 +6729,8 @@ weechat_ruby_api_init (VALUE ruby_mWeechat)
API_DEF_FUNC(config_string_default, 1);
API_DEF_FUNC(config_color, 1);
API_DEF_FUNC(config_color_default, 1);
API_DEF_FUNC(config_enum, 1);
API_DEF_FUNC(config_enum_default, 1);
API_DEF_FUNC(config_write_option, 2);
API_DEF_FUNC(config_write_line, 3);
API_DEF_FUNC(config_write, 1);
+30
View File
@@ -1871,6 +1871,34 @@ API_FUNC(config_color_default)
API_RETURN_STRING(result);
}
API_FUNC(config_enum)
{
Tcl_Obj *objp;
int result, i;
API_INIT_FUNC(1, "config_enum", API_RETURN_INT(0));
if (objc < 2)
API_WRONG_ARGS(API_RETURN_INT(0));
result = weechat_config_enum (API_STR2PTR(Tcl_GetStringFromObj (objv[1], &i))); /* option */
API_RETURN_INT(result);
}
API_FUNC(config_enum_default)
{
Tcl_Obj *objp;
int result, i;
API_INIT_FUNC(1, "config_enum_default", API_RETURN_INT(0));
if (objc < 2)
API_WRONG_ARGS(API_RETURN_INT(0));
result = weechat_config_enum_default (API_STR2PTR(Tcl_GetStringFromObj (objv[1], &i))); /* option */
API_RETURN_INT(result);
}
API_FUNC(config_write_option)
{
Tcl_Obj *objp;
@@ -5988,6 +6016,8 @@ void weechat_tcl_api_init (Tcl_Interp *interp)
API_DEF_FUNC(config_string_default);
API_DEF_FUNC(config_color);
API_DEF_FUNC(config_color_default);
API_DEF_FUNC(config_enum);
API_DEF_FUNC(config_enum_default);
API_DEF_FUNC(config_write_option);
API_DEF_FUNC(config_write_line);
API_DEF_FUNC(config_write);
+4
View File
@@ -327,16 +327,20 @@ def test_config():
'option_delete_cb', '',
)
check(ptr_opt_enum != '')
check(weechat.config_enum(ptr_opt_enum) == 1)
check(weechat.config_integer(ptr_opt_enum) == 1)
check(weechat.config_string(ptr_opt_enum) == 'val2')
check(weechat.config_option_set(ptr_opt_enum, 'val1', 1) == 2) # SET_OK_CHANGED
check(weechat.config_option_set(ptr_opt_enum, 'val1', 1) == 1) # SET_OK_SAME_VALUE
check(weechat.config_enum(ptr_opt_enum) == 0)
check(weechat.config_integer(ptr_opt_enum) == 0)
check(weechat.config_string(ptr_opt_enum) == 'val1')
check(weechat.config_enum_default(ptr_opt_enum) == 1)
check(weechat.config_integer_default(ptr_opt_enum) == 1)
check(weechat.config_string_default(ptr_opt_enum) == 'val2')
check(weechat.config_option_reset(ptr_opt_enum, 1) == 2) # SET_OK_CHANGED
check(weechat.config_option_reset(ptr_opt_enum, 1) == 1) # SET_OK_SAME_VALUE
check(weechat.config_enum(ptr_opt_enum) == 1)
check(weechat.config_integer(ptr_opt_enum) == 1)
check(weechat.config_string(ptr_opt_enum) == 'val2')
# search option