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

scripts: allow null values in config_new_option

The plugin API function config_new_option accepts null as the
default_value and/or value however the scripting APIs (except for lua)
didn't allow sending null as a parameter value, so it was impossible to
use it this way. This allows sending a null value for these parameters.

Lua already supported sending in nil for these parameters and it works
as expected, so nothing is changed for this plugin.

For Guile you can now send in #nil, for JavaScript null or undefined,
for Perl undef, for PHP NULL, for Python None, for Ruby nil and for Tcl
$::weechat::WEECHAT_NULL.

In all of these languages except Tcl this is the special value
indicating a missing value. However Tcl only has one type, string, so it
doesn't have a null value. Therefore I created a constant with the value
`\uFFFF\uFFFF\uFFFFWEECHAT_NULL\uFFFF\uFFFF\uFFFF` which is used
instead. This is very unlikely to appear unintentionally. Using the
unicode code point \uFFFF was suggested on
https://wiki.tcl-lang.org/page/null.

I tested this with these scripts:
https://gist.github.com/trygveaa/f91977dde5d2876d502bf55fbf9b50cc
This commit is contained in:
Trygve Aaberge
2022-03-02 20:45:04 +01:00
committed by Sébastien Helleu
parent 47e71a1bbd
commit 197a7a01e4
10 changed files with 60 additions and 20 deletions
+19 -5
View File
@@ -73,6 +73,8 @@ extern "C"
for (num = 0; num < js_args_len; num++) \
{ \
if (((js_args[num] == 's') && (!args[num]->IsString())) \
|| ((js_args[num] == 'S') && (!(args[num]->IsString() \
|| args[num]->IsNull() || args[num]->IsUndefined()))) \
|| ((js_args[num] == 'i') && (!args[num]->IsInt32())) \
|| ((js_args[num] == 'n') && (!args[num]->IsNumber())) \
|| ((js_args[num] == 'h') && (!args[num]->IsObject()))) \
@@ -1188,9 +1190,10 @@ weechat_js_api_config_option_delete_cb (const void *pointer, void *data,
API_FUNC(config_new_option)
{
int min, max, null_value_allowed;
char *default_value, *value;
const char *result;
API_INIT_FUNC(1, "config_new_option", "ssssssiississssss", API_RETURN_EMPTY);
API_INIT_FUNC(1, "config_new_option", "ssssssiiSSissssss", API_RETURN_EMPTY);
v8::String::Utf8Value config_file(args[0]);
v8::String::Utf8Value section(args[1]);
@@ -1200,8 +1203,19 @@ API_FUNC(config_new_option)
v8::String::Utf8Value string_values(args[5]);
min = args[6]->IntegerValue();
max = args[7]->IntegerValue();
v8::String::Utf8Value default_value(args[8]);
v8::String::Utf8Value value(args[9]);
v8::String::Utf8Value v8_default_value(args[8]);
if (args[8]->IsNull() || args[8]->IsUndefined())
default_value = NULL;
else
default_value = *v8_default_value;
v8::String::Utf8Value v8_value(args[9]);
if (args[8]->IsNull() || args[8]->IsUndefined())
value = NULL;
else
value = *v8_value;
null_value_allowed = args[10]->IntegerValue();
v8::String::Utf8Value function_check_value(args[11]);
v8::String::Utf8Value data_check_value(args[12]);
@@ -1222,8 +1236,8 @@ API_FUNC(config_new_option)
*string_values,
min,
max,
*default_value,
*value,
default_value,
value,
null_value_allowed,
&weechat_js_api_config_option_check_value_cb,
*function_check_value,