vimscript: calling dictionary functions with call()
Posted
by intuited
on Stack Overflow
See other posts from Stack Overflow
or by intuited
Published on 2010-04-01T02:39:55Z
Indexed on
2010/04/01
2:43 UTC
Read the original article
Hit count: 466
I'm hoping to call a "static" dictionary function using call(). By "static" I mean that the keyword 'dict' is not used in the function's definition. I use this nomenclature in the hopes that the effect of this keyword is to declare a static member function as is possible in java/C++/etc, ie to put the function name in the class namespace but allow it to be called without referencing an object.
However this doesn't seem to work. For example:
" Setup:
let testdict = { }
funct! testdict.funct()
echo "called"
endfunct
" Tests:
" Following each line is an indented comment
" containing its output in message land, ie what was echoed.
call testdict.funct()
" called
echo testdict.funct
" 667
echo string(testdict.funct)
" function('667')
echo function('667')
" E475: Invalid argument: 667
echo function('testdict.funct')
" testdict.funct
call call(testdict.funct, [ ])
" E725: Calling dict function without Dictionary: 667
" Same deal if there's an intermediate variable involved.
let TestdictDotFunct = testdict.funct
echo TestdictDotFunct
" 667
echo string(TestdictDotFunct)
" function('667')
call TestdictDotFunct()
" E725: Calling dict function without Dictionary: 667
From the help topic E725:
It is also possible to add a function without the "dict" attribute as a Funcref to a Dictionary, but the "self" variable is not available then.
So logic would seem to indicate that if "self" is not available, then it should be possible to call the function referenced by the Funcref without a Dictionary. However this doesn't seem to be the case. Am I missing something?
Vim version info:
$ aptitude show vim-gnome
Package: vim-gnome
State: installed
Automatically installed: no
Version: 2:7.2.245-2ubuntu2
© Stack Overflow or respective owner