Patch 7.4.1842 (after 7.4.1839)
Problem: get() works for Partial but not for Funcref.
Solution: Accept Funcref. Also return the function itself. (Nikolai Pavlov)
Files: src/eval.c, src/testdir/test_partial.vim, runtime/doc/eval.txt
*** ../vim-7.4.1841/src/eval.c 2016-05-24 18:36:48.099153830 +0200
--- src/eval.c 2016-05-24 22:13:21.538975095 +0200
***************
*** 12423,12439 ****
tv = &di->di_tv;
}
}
! 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 = NULL;
else
--- 12423,12449 ----
tv = &di->di_tv;
}
}
! else if (argvars[0].v_type == VAR_PARTIAL || argvars[0].v_type ==
VAR_FUNC)
{
! 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)
{
char_u *what = get_tv_string(&argvars[1]);
! if (STRCMP(what, "func") == 0 || STRCMP(what, "name") == 0)
{
! rettv->v_type = (*what == 'f' ? VAR_FUNC : VAR_STRING);
if (pt->pt_name == NULL)
rettv->vval.v_string = NULL;
else
*** ../vim-7.4.1841/src/testdir/test_partial.vim 2016-05-24
18:36:48.099153830 +0200
--- src/testdir/test_partial.vim 2016-05-24 22:18:05.522971188 +0200
***************
*** 282,290 ****
func Test_get_partial_items()
let dict = {'name': 'hello'}
! let Cb = function('MyDictFunc', ["foo", "bar"], dict)
! call assert_equal('MyDictFunc', get(Cb, 'func'))
! call assert_equal(["foo", "bar"], get(Cb, 'args'))
call assert_equal(dict, get(Cb, 'dict'))
call assert_fails('call get(Cb, "xxx")', 'E475:')
endfunc
--- 282,299 ----
func Test_get_partial_items()
let dict = {'name': 'hello'}
! let args = ["foo", "bar"]
! let Func = function('MyDictFunc')
! 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_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
*** ../vim-7.4.1841/runtime/doc/eval.txt 2016-05-24 18:36:48.099153830
+0200
--- runtime/doc/eval.txt 2016-05-24 22:28:44.118962404 +0200
***************
*** 1938,1943 ****
--- 1957,1963 ----
garbagecollect([{atexit}]) none free memory, breaking cyclic references
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({func}, {what}) any get property of funcref/partial {func}
getbufline({expr}, {lnum} [, {end}])
List lines {lnum} to {end} of buffer {expr}
getbufvar({expr}, {varname} [, {def}])
***************
*** 3721,3729 ****
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
--- 3772,3781 ----
Get item with key {key} from |Dictionary| {dict}. When this
item is not available return {default}. Return zero when
{default} is omitted.
! get({func}, {what})
! Get an item with from Funcref {func}. Possible values for
{what} are:
+ 'name' The function name
'func' The function
'dict' The dictionary
'args' The list with arguments
*** ../vim-7.4.1841/src/version.c 2016-05-24 19:59:48.207085324 +0200
--- src/version.c 2016-05-24 22:24:08.134966200 +0200
***************
*** 755,756 ****
--- 755,758 ----
{ /* Add new patch number below this line */
+ /**/
+ 1842,
/**/
--
Often you're less important than your furniture. If you think about it, you
can get fired but your furniture stays behind, gainfully employed at the
company that didn't need _you_ anymore.
(Scott Adams - The Dilbert principle)
/// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.