Last active
October 23, 2022 19:32
-
-
Save trygveaa/2d49c609addf9773d2ed16e15d1e3447 to your computer and use it in GitHub Desktop.
WeeChat scripts to test config section callback read with null value in all the scripting languages
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function my_section_read_cb(data, config_file, section, option_name, value) { | |
weechat.print("", "js: value: '" + value + "', is_null: " + (value === null) + ", is_undefined: " + (value === undefined)); | |
return weechat.WEECHAT_CONFIG_OPTION_SET_OK_CHANGED; | |
} | |
weechat.register("script_config_js", "trygveaa", "0.0.1", "MIT", "", "", "") | |
var config_file = weechat.config_new("script_config_js", "", "") | |
var config_section = weechat.config_new_section( | |
config_file, "section", 0, 0, "my_section_read_cb", "", "", "", "", "", "", "", "", "" | |
) | |
var option1 = weechat.config_new_option( | |
config_file, | |
config_section, | |
"option1", | |
"string", | |
"description", | |
"", | |
0, | |
0, | |
null, | |
null, | |
1, | |
"", | |
"", | |
"", | |
"", | |
"", | |
"" | |
) | |
weechat.config_read(config_file) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local weechat = weechat | |
function my_section_read_cb(data, config_file, section, option_name, value) | |
weechat.print("", string.format("lua: value: '%s', is_null: %s", value, value == nil)) | |
return weechat.WEECHAT_CONFIG_OPTION_SET_OK_CHANGED | |
end | |
if weechat.register("script_config_lua", "trygveaa", "0.0.1", "MIT", "", "", "") then | |
local config_file = weechat.config_new("script_config_lua", "", "") | |
local config_section = weechat.config_new_section( | |
config_file, "section", 0, 0, "my_section_read_cb", "", "", "", "", "", "", "", "", "" | |
) | |
local option1 = weechat.config_new_option( | |
config_file, | |
config_section, | |
"option1", | |
"string", | |
"description", | |
"", | |
0, | |
0, | |
nil, | |
nil, | |
1, | |
"", | |
"", | |
"", | |
"", | |
"", | |
"" | |
) | |
weechat.config_read(config_file) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$cb = function() { }; | |
$my_section_read_cb = function ($data, $config_file, $section, $option_name, $value) { | |
$value_is_null = is_null($value); | |
weechat_print("", "php: value: '$value', is_null: $value_is_null"); | |
return WEECHAT_CONFIG_OPTION_SET_OK_CHANGED; | |
}; | |
$my_section_write_cb = function ($data, $config_file, $section_name) { | |
global $option1; | |
weechat_config_write_line($config_file, $section_name, ""); | |
weechat_config_write_option($config_file, $option1); | |
return WEECHAT_CONFIG_WRITE_OK; | |
}; | |
weechat_register("script_config_php", "trygveaa", "0.0.1", "MIT", "", "", ""); | |
$config_file = weechat_config_new("script_config_php", $cb, ""); | |
$config_section = weechat_config_new_section( | |
$config_file, "section", 0, 0, $my_section_read_cb, "", $my_section_write_cb, "", $my_section_write_cb, "", $cb, "", $cb, "" | |
); | |
$option1 = weechat_config_new_option( | |
$config_file, | |
$config_section, | |
"option1", | |
"string", | |
"description", | |
"", | |
0, | |
0, | |
NULL, | |
NULL, | |
1, | |
$cb, | |
"", | |
$cb, | |
"", | |
$cb, | |
"" | |
); | |
weechat_config_read($config_file); | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sub my_section_read_cb { | |
my ($data, $config_file, $section, $option_name, $value) = @_; | |
my $value_is_null = !defined $value; | |
weechat::print("", "pl: value: '$value', is_null: $value_is_null"); | |
return weechat::WEECHAT_CONFIG_OPTION_SET_OK_CHANGED; | |
} | |
weechat::register("script_config_pl", "trygveaa", "0.0.1", "MIT", "", "", ""); | |
my $config_file = weechat::config_new("script_config_pl", "", ""); | |
my $config_section = weechat::config_new_section( | |
$config_file, "section", 0, 0, "my_section_read_cb", "", "", "", "", "", "", "", "", "" | |
); | |
my $option1 = weechat::config_new_option( | |
$config_file, | |
$config_section, | |
"option1", | |
"string", | |
"description", | |
"", | |
0, | |
0, | |
undef, | |
undef, | |
1, | |
"", | |
"", | |
"", | |
"", | |
"", | |
"", | |
); | |
weechat::config_read($config_file); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# pylint: disable=missing-module-docstring disable=missing-function-docstring | |
# pyright: strict, reportMissingModuleSource=false | |
import weechat # pylint: disable=import-error | |
def my_section_read_cb( | |
data: str, config_file: str, section: str, option_name: str, value: str | |
) -> int: | |
weechat.prnt("", f"py: value: '{value}', is_null: {value is None}") | |
return weechat.WEECHAT_CONFIG_OPTION_SET_OK_CHANGED | |
if weechat.register("script_config_py", "trygveaa", "0.0.1", "MIT", "", "", ""): | |
config_file = weechat.config_new("script_config_py", "", "") | |
config_section = weechat.config_new_section( | |
config_file, | |
"section", | |
0, | |
0, | |
"my_section_read_cb", | |
"", | |
"", | |
"", | |
"", | |
"", | |
"", | |
"", | |
"", | |
"", | |
) | |
option1 = weechat.config_new_option( | |
config_file, | |
config_section, | |
"option1", | |
"string", | |
"description", | |
"", | |
0, | |
0, | |
None, | |
None, | |
True, | |
"", | |
"", | |
"", | |
"", | |
"", | |
"", | |
) | |
weechat.config_read(config_file) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def my_section_read_cb(data, config_file, section, option_name, value) | |
Weechat.print("", "rb: value: '#{value}', is_null: #{value.nil?}"); | |
return Weechat::WEECHAT_CONFIG_OPTION_SET_OK_CHANGED | |
end | |
def weechat_init | |
Weechat.register("script_config_rb", "trygveaa", "0.0.1", "MIT", "", "", "") | |
config_file = Weechat.config_new("script_config_rb", "", "") | |
config_section = Weechat.config_new_section( | |
config_file, "section", 0, 0, "my_section_read_cb", "", "", "", "", "", "", "", "", "" | |
) | |
option1 = Weechat.config_new_option( | |
config_file, | |
config_section, | |
"option1", | |
"string", | |
"description", | |
"", | |
0, | |
0, | |
nil, | |
nil, | |
1, | |
["", | |
"", | |
"", | |
"", | |
"", | |
""] | |
) | |
Weechat.config_read(config_file) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(define (my_section_read_cb data config_file section option_name value) | |
(weechat:print "" (format #f "scm: value: '~s', is_null: ~s" value (nil? value))) | |
weechat:WEECHAT_CONFIG_OPTION_SET_OK_CHANGED | |
) | |
(weechat:register "script_config_scm" "trygveaa" "0.0.1" "MIT" "" "" "") | |
(define config_file (weechat:config_new "script_config_scm" "" "")) | |
(define config_section (weechat:config_new_section | |
(list config_file "section" 0 0 "my_section_read_cb" "" "" "" "" "" "" "" "" "") | |
)) | |
(define option1 (weechat:config_new_option | |
(list config_file | |
config_section | |
"option1" | |
"string" | |
"description" | |
"" | |
0 | |
0 | |
#nil | |
#nil | |
1 | |
"" | |
"" | |
"" | |
"" | |
"" | |
"") | |
)) | |
(weechat:config_read config_file) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
proc my_section_read_cb { data config_file section option_name value } { | |
set value_is_null [expr [string compare $value $::weechat::WEECHAT_NULL] == 0] | |
weechat::print {} "tcl: value: '$value', is_null: $value_is_null" | |
return $::weechat::WEECHAT_CONFIG_OPTION_SET_OK_CHANGED | |
} | |
weechat::register "script_config_tcl" "trygveaa" "0.0.1" "MIT" "" "" "" | |
set config_file [weechat::config_new "script_config_tcl" "" ""] | |
set config_section [weechat::config_new_section \ | |
$config_file "section" 0 0 "my_section_read_cb" "" "" "" "" "" "" "" "" ""] | |
set option1 [weechat::config_new_option \ | |
$config_file \ | |
$config_section \ | |
"option1" \ | |
"string" \ | |
"description" \ | |
"" \ | |
0 \ | |
0 \ | |
$::weechat::WEECHAT_NULL \ | |
$::weechat::WEECHAT_NULL \ | |
1 \ | |
"" \ | |
"" \ | |
"" \ | |
"" \ | |
"" \ | |
""] | |
weechat::config_read $config_file |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment