forked from aniani/vim
patch 7.4.1842
Problem: get() works for Partial but not for Funcref. Solution: Accept Funcref. Also return the function itself. (Nikolai Pavlov)
This commit is contained in:
parent
26852128a2
commit
03e19a04ac
@ -1957,6 +1957,7 @@ function({name} [, {arglist}] [, {dict}])
|
|||||||
garbagecollect([{atexit}]) none free memory, breaking cyclic references
|
garbagecollect([{atexit}]) none free memory, breaking cyclic references
|
||||||
get({list}, {idx} [, {def}]) any get item {idx} from {list} or {def}
|
get({list}, {idx} [, {def}]) any get item {idx} from {list} or {def}
|
||||||
get({dict}, {key} [, {def}]) any get item {key} from {dict} or {def}
|
get({dict}, {key} [, {def}]) any get item {key} from {dict} or {def}
|
||||||
|
get({func}, {what}) any get property of funcref/partial {func}
|
||||||
getbufline({expr}, {lnum} [, {end}])
|
getbufline({expr}, {lnum} [, {end}])
|
||||||
List lines {lnum} to {end} of buffer {expr}
|
List lines {lnum} to {end} of buffer {expr}
|
||||||
getbufvar({expr}, {varname} [, {def}])
|
getbufvar({expr}, {varname} [, {def}])
|
||||||
@ -3771,9 +3772,10 @@ get({dict}, {key} [, {default}])
|
|||||||
Get item with key {key} from |Dictionary| {dict}. When this
|
Get item with key {key} from |Dictionary| {dict}. When this
|
||||||
item is not available return {default}. Return zero when
|
item is not available return {default}. Return zero when
|
||||||
{default} is omitted.
|
{default} is omitted.
|
||||||
get({partial}, {what})
|
get({func}, {what})
|
||||||
Get an item with from Funcref {partial}. Possible values for
|
Get an item with from Funcref {func}. Possible values for
|
||||||
{what} are:
|
{what} are:
|
||||||
|
'name' The function name
|
||||||
'func' The function
|
'func' The function
|
||||||
'dict' The dictionary
|
'dict' The dictionary
|
||||||
'args' The list with arguments
|
'args' The list with arguments
|
||||||
|
18
src/eval.c
18
src/eval.c
@ -12423,17 +12423,27 @@ f_get(typval_T *argvars, typval_T *rettv)
|
|||||||
tv = &di->di_tv;
|
tv = &di->di_tv;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (argvars[0].v_type == VAR_PARTIAL)
|
else if (argvars[0].v_type == VAR_PARTIAL || argvars[0].v_type == VAR_FUNC)
|
||||||
{
|
{
|
||||||
partial_T *pt = argvars[0].vval.v_partial;
|
partial_T *pt;
|
||||||
|
partial_T fref_pt;
|
||||||
|
|
||||||
|
if (argvars[0].v_type == VAR_PARTIAL)
|
||||||
|
pt = argvars[0].vval.v_partial;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
vim_memset(&fref_pt, 0, sizeof(fref_pt));
|
||||||
|
fref_pt.pt_name = argvars[0].vval.v_string;
|
||||||
|
pt = &fref_pt;
|
||||||
|
}
|
||||||
|
|
||||||
if (pt != NULL)
|
if (pt != NULL)
|
||||||
{
|
{
|
||||||
char_u *what = get_tv_string(&argvars[1]);
|
char_u *what = get_tv_string(&argvars[1]);
|
||||||
|
|
||||||
if (STRCMP(what, "func") == 0)
|
if (STRCMP(what, "func") == 0 || STRCMP(what, "name") == 0)
|
||||||
{
|
{
|
||||||
rettv->v_type = VAR_STRING;
|
rettv->v_type = (*what == 'f' ? VAR_FUNC : VAR_STRING);
|
||||||
if (pt->pt_name == NULL)
|
if (pt->pt_name == NULL)
|
||||||
rettv->vval.v_string = NULL;
|
rettv->vval.v_string = NULL;
|
||||||
else
|
else
|
||||||
|
@ -282,9 +282,18 @@ endfunc
|
|||||||
|
|
||||||
func Test_get_partial_items()
|
func Test_get_partial_items()
|
||||||
let dict = {'name': 'hello'}
|
let dict = {'name': 'hello'}
|
||||||
let Cb = function('MyDictFunc', ["foo", "bar"], dict)
|
let args = ["foo", "bar"]
|
||||||
call assert_equal('MyDictFunc', get(Cb, 'func'))
|
let Func = function('MyDictFunc')
|
||||||
call assert_equal(["foo", "bar"], get(Cb, 'args'))
|
let Cb = function('MyDictFunc', args, dict)
|
||||||
|
|
||||||
|
call assert_equal(Func, get(Cb, 'func'))
|
||||||
|
call assert_equal('MyDictFunc', get(Cb, 'name'))
|
||||||
|
call assert_equal(args, get(Cb, 'args'))
|
||||||
call assert_equal(dict, get(Cb, 'dict'))
|
call assert_equal(dict, get(Cb, 'dict'))
|
||||||
call assert_fails('call get(Cb, "xxx")', 'E475:')
|
call assert_fails('call get(Cb, "xxx")', 'E475:')
|
||||||
|
|
||||||
|
call assert_equal(Func, get(Func, 'func'))
|
||||||
|
call assert_equal('MyDictFunc', get(Func, 'name'))
|
||||||
|
call assert_equal([], get(Func, 'args'))
|
||||||
|
call assert_true(empty( get(Func, 'dict')))
|
||||||
endfunc
|
endfunc
|
||||||
|
@ -753,6 +753,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
1842,
|
||||||
/**/
|
/**/
|
||||||
1841,
|
1841,
|
||||||
/**/
|
/**/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user