diff options
-rw-r--r-- | runtime/doc/eval.txt | 6 | ||||
-rw-r--r-- | src/nvim/eval.c | 36 |
2 files changed, 40 insertions, 2 deletions
diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt index 133f35990c..05dcc62903 100644 --- a/runtime/doc/eval.txt +++ b/runtime/doc/eval.txt @@ -3586,6 +3586,12 @@ get({dict}, {key} [, {default}]) Get item with key {key} from |Dictionary| {dict}. When this item is not available return {default}. Return zero when {default} is omitted. +get({partial}, {what}) + Get an item with from Funcref {partial}. Possible values for + {what} are: + 'func' The function + 'dict' The dictionary + 'args' The list with arguments *getbufline()* getbufline({expr}, {lnum} [, {end}]) diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 14e6003ca0..be1eb3ef1c 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -9706,8 +9706,40 @@ static void f_get(typval_T *argvars, typval_T *rettv, FunPtr fptr) if (di != NULL) tv = &di->di_tv; } - } else + } else if (argvars[0].v_type == VAR_PARTIAL) { + partial_T *pt = argvars[0].vval.v_partial; + + if (pt != NULL) { + char_u *what = get_tv_string(&argvars[1]); + + if (STRCMP(what, "func") == 0) { + rettv->v_type = VAR_STRING; + if (pt->pt_name != NULL) { + rettv->vval.v_string = vim_strsave(pt->pt_name); + } + } else if (STRCMP(what, "dict") == 0) { + rettv->v_type = VAR_DICT; + rettv->vval.v_dict = pt->pt_dict; + if (pt->pt_dict != NULL) { + (pt->pt_dict->dv_refcount)++; + } + } else if (STRCMP(what, "args") == 0) { + rettv->v_type = VAR_LIST; + if (rettv_list_alloc(rettv) != NULL) { + int i; + + for (i = 0; i < pt->pt_argc; i++) { + list_append_tv(rettv->vval.v_list, &pt->pt_argv[i]); + } + } + } else { + EMSG2(_(e_invarg2), what); + } + return; + } + } else { EMSG2(_(e_listdictarg), "get()"); + } if (tv == NULL) { if (argvars[2].v_type != VAR_UNKNOWN) @@ -18430,7 +18462,7 @@ handle_subscript ( // Turn "dict.Func" into a partial for "Func" bound to "dict". // Don't do this when "Func" is already a partial that was bound // explicitly (pt_auto is false). - if (self != NULL + if (selfdict != NULL && (rettv->v_type == VAR_FUNC || (rettv->v_type == VAR_PARTIAL && (rettv->vval.v_partial->pt_auto |