Thursday, July 7, 2011

Aw: Re: Aw: Re: vim function not first-class variable? how to create an alias for vim function ?



Am Mittwoch, 6. Juli 2011 19:34:05 UTC+2 schrieb ZyX:

There are anonymous functions (:h numbered-function):
    let s:F={}
    function s:F.func()
        echo "Here"
    endfunction
. It is not possible to call anonymous function without a reference to it and
you can't create the reference using function() call, so the above code
effectively restricts write/execute access to the script (unless you pass
s:F.func, s:F or s: somewhere).


Such "anonymous" dictionary functions a.k.a. numbered functions can be called by there name too. You can thus do the following:

let d = {}
function! d.Foo() dict
    return 10
endf

echo d.Foo()
" => 10

echo d["Foo"]
" => 93

echo call(93, [], d)
" => 10

These anonymous functions thus aren't really anonymous if you know the number.

Regards,
Tom

--
You received this message from the "vim_use" 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

No comments: