diff options
author | Trygve Aaberge <trygveaa@gmail.com> | 2022-10-22 15:27:06 +0200 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2022-12-11 15:13:31 +0100 |
commit | ebc63d1b8303a479c9ed347c1152448984fffa67 (patch) | |
tree | 0f881dd620a7100d460f795f2644365f231b9b62 /doc/fr | |
parent | 1bfc8b9cf8771c1f979f20baffa20c1fe7671726 (diff) | |
download | weechat-ebc63d1b8303a479c9ed347c1152448984fffa67.zip |
scripts: Send null values to config section callbacks
The callback_read and callback_create_option functions in the scripting
APIs always get the value as a string, never as null. This means that if
the value is null, there is no way for the script to distinguish this
from an empty string for string options. This makes it impossible to
properly make options with fallback values, like the irc server and
server_default options, as far as I can see.
All the scripting languages except Tcl use that language's equivalent
for null. For JavaScript which has both null and undefined, null is
used. For Tcl, the magic null string defined in commit 197a7a01e is used
and the documentation is updated to describe that.
I tested this with these scripts:
https://gist.github.com/trygveaa/2d49c609addf9773d2ed16e15d1e3447
You can load all of those scripts and see the result with this command
(assuming you have the scripts in the current directory):
weechat -t -r "/filter add script * * script; /script load $(echo script_config.*)"
Diffstat (limited to 'doc/fr')
-rw-r--r-- | doc/fr/weechat_plugin_api.fr.adoc | 4 | ||||
-rw-r--r-- | doc/fr/weechat_scripting.fr.adoc | 22 |
2 files changed, 18 insertions, 8 deletions
diff --git a/doc/fr/weechat_plugin_api.fr.adoc b/doc/fr/weechat_plugin_api.fr.adoc index 41f6fdac4..0f8a4c7de 100644 --- a/doc/fr/weechat_plugin_api.fr.adoc +++ b/doc/fr/weechat_plugin_api.fr.adoc @@ -6554,7 +6554,7 @@ def config_new_section(config_file: str, name: str, callback_delete_option: str, callback_delete_option_data: str) -> str: ... # exemple -def my_section_read_cb(data: str, config_file: str, section: str, option_name: str, value: str) -> int: +def my_section_read_cb(data: str, config_file: str, section: str, option_name: str, value: str | None) -> int: # ... return weechat.WEECHAT_CONFIG_OPTION_SET_OK_CHANGED # return weechat.WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE @@ -6569,7 +6569,7 @@ def my_section_write_default_cb(data: str, config_file: str, section_name: str) # ... return weechat.WEECHAT_CONFIG_WRITE_OK -def my_section_create_option_cb(data: str, config_file: str, section: str, option_name: str, value: str) -> int: +def my_section_create_option_cb(data: str, config_file: str, section: str, option_name: str, value: str | None) -> int: # ... return weechat.WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE diff --git a/doc/fr/weechat_scripting.fr.adoc b/doc/fr/weechat_scripting.fr.adoc index f481640f7..de87cb8e4 100644 --- a/doc/fr/weechat_scripting.fr.adoc +++ b/doc/fr/weechat_scripting.fr.adoc @@ -201,12 +201,22 @@ Les fonctions sont appelées par `+weechat.xxx(arg1, arg2, ...)+`. Les fonctions sont appelées par `+weechat::xxx arg1 arg2 ...+`. -Étant donné que Tcl n'a que des types "string", il n'y a pas de type null à -donner comme paramètre quand une fonctionne accepte des valeurs nulles. -Pour surmonter cela vous pouvez utiliser la constante `$::weechat::WEECHAT_NULL` -qui agit comme la valeur nulle. Cette constante est définie avec la valeur -`\uFFFF\uFFFF\uFFFFWEECHAT_NULL\uFFFF\uFFFF\uFFFF`, il est donc très peu probable -qu'elle apparaisse de manière non intentionnelle. +// TRANSLATION MISSING +[[tcl_null]] +===== Null values + +Since Tcl only has string types, there's no null type to pass as an argument +when a function accepts null values or to get as an argument in a callback +function. To overcome this the WeeChat API defines the constant +`$::weechat::WEECHAT_NULL` which acts as a null value. This constant is defined +as `\uFFFF\uFFFF\uFFFFWEECHAT_NULL\uFFFF\uFFFF\uFFFF`, so it's very unlikely to +appear unintentionally. + +You can pass this constant when a function accepts null as an argument and you +will get it as the value of an argument in a callback function if the argument +value is null. To see which functions accept null values and passes null values +to callbacks, look at the Python prototypes in the +link:weechat_plugin_api.en.html[WeeChat plugin API reference ^↗^,window=_blank]. [[language_guile]] ==== Guile (Scheme) |