diff options
author | Andrew Potter <agpotter@gmail.com> | 2023-03-10 20:19:03 +0100 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2023-03-10 20:19:03 +0100 |
commit | e3f588679ce7b3f911502bef1685e65b12ad212e (patch) | |
tree | 876fbcfbd32a83f9a15eb2458808597d2033539b /src | |
parent | dd65e91a753de52bb50804ec18c94627d5f3ff90 (diff) | |
download | weechat-e3f588679ce7b3f911502bef1685e65b12ad212e.zip |
core: allow /eval to get hashtable properties
Diffstat (limited to 'src')
-rw-r--r-- | src/core/wee-command.c | 6 | ||||
-rw-r--r-- | src/core/wee-eval.c | 21 |
2 files changed, 23 insertions, 4 deletions
diff --git a/src/core/wee-command.c b/src/core/wee-command.c index 62ac281f4..365f3a211 100644 --- a/src/core/wee-command.c +++ b/src/core/wee-command.c @@ -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" diff --git a/src/core/wee-eval.c b/src/core/wee-eval.c index d80be2df9..5bfd4a166 100644 --- a/src/core/wee-eval.c +++ b/src/core/wee-eval.c @@ -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) { |