1
0
mirror of https://github.com/weechat/weechat.git synced 2026-07-04 00:33:13 +02:00

core: allow /eval to get hashtable properties

This commit is contained in:
Andrew Potter
2023-03-10 20:19:03 +01:00
committed by Sébastien Helleu
parent dd65e91a75
commit e3f588679c
3 changed files with 30 additions and 4 deletions
+6
View File
@@ -8013,6 +8013,12 @@ command_init ()
"with this pointer (can be used in triggers)\n"
" ${buffer[my_pointer].full_name}: full name of the buffer "
"with this pointer name (can be used in triggers)\n"
" hdata[pointer].var1.keys_values(): When var1 is a hashtable, "
"methods \"keys(),values(),keys_sorted(),keys_values(),"
"keys_values_sorted()\" may be called. Alternatively, a key can "
"be looked up directly. For example:\n"
" ${buffer[gui_buffers].local_variables.keys_values()}: plugin:core,name:weechat\n"
" ${buffer[gui_buffers].local_variables.plugin}: core\n"
"For name of hdata and variables, please look at \"Plugin API "
"reference\", function \"weechat_hdata_get\".\n"
"\n"
+17 -4
View File
@@ -1167,8 +1167,8 @@ char *
eval_hdata_get_value (struct t_hdata *hdata, void *pointer, const char *path,
struct t_eval_context *eval_context)
{
char *value, *old_value, *var_name, str_value[128], *pos;
const char *ptr_value, *hdata_name, *ptr_var_name;
char *value, *old_value, *var_name, str_value[128], *pos, *property;
const char *ptr_value, *hdata_name, *ptr_var_name, *open_paren;
int type, debug_id;
struct t_hashtable *hashtable;
@@ -1257,10 +1257,23 @@ eval_hdata_get_value (struct t_hdata *hdata, void *pointer, const char *path,
if (pos)
{
/*
* for a hashtable, if there is a "." after name of hdata,
* get the value for this key in hashtable
* for a hashtable, if there is a "." after name of hdata:
* 1) If "()" is at the end, it is a function call to
* hashtable_get_string().
* 2) Otherwise, get the value for this key in hashtable.
*/
hashtable = pointer;
open_paren = strchr (pos, '(');
if (open_paren && open_paren > (pos + 1) && open_paren[1] == ')')
{
property = string_strndup (pos + 1, open_paren - pos - 1);
ptr_value = hashtable_get_string (hashtable, property);
free (property);
value = (ptr_value) ? strdup (ptr_value) : NULL;
break;
}
ptr_value = hashtable_get (hashtable, pos + 1);
if (ptr_value)
{
+7
View File
@@ -950,6 +950,13 @@ TEST(CoreEval, EvalExpression)
WEE_CHECK_EVAL(str_value, "${window.buffer.local_variables}");
WEE_CHECK_EVAL("core", "${window.buffer.local_variables.plugin}");
WEE_CHECK_EVAL("weechat", "${window.buffer.local_variables.name}");
WEE_CHECK_EVAL("name,plugin", "${window.buffer.local_variables.keys_sorted()}");
WEE_CHECK_EVAL("name:weechat,plugin:core", "${window.buffer.local_variables.keys_values_sorted()}");
WEE_CHECK_EVAL("", "${window.buffer.local_variables.nonexisting_func()}");
WEE_CHECK_EVAL("", "${window.buffer.local_variables.nonexisting_func(}");
WEE_CHECK_EVAL("", "${window.buffer.local_variables.nonexisting_func)}");
WEE_CHECK_EVAL("", "${window.buffer.local_variables.keys( )}");
WEE_CHECK_EVAL("", "${window.buffer.local_variables.()}");
hashtable_remove_all (pointers);
/* test with another prefix/suffix */