Yegappan wrote:
> On Thu, Dec 9, 2021 at 6:24 AM Bram Moolenaar <[email protected]> wrote: > > > > > > Patch 8.2.3765 > > Problem: Vim9: cannot use a lambda for 'opfunc' and others. > > Solution: Convert the lambda to a string. > > This doesn't work in some cases. For example: > > ---------------------------------------------------------------------------- > vim9script > > def MyomniFunc1(val: number, findstart: number, base: string): any > add(g:MyomniFunc1_args, [val, findstart, base]) > return findstart ? 0 : [] > enddef > > def Test_omnifunc_callback() > var Fn: func = function('s:MyomniFunc1', [14]) > &omnifunc = Fn > new | only > setline(1, 'four') > g:MyomniFunc1_args = [] > feedkeys("A\<C-X>\<C-O>\<Esc>", 'x') > assert_equal([[14, 1, ''], [14, 0, 'four']], g:MyomniFunc1_args) > bw! > enddef > > Test_omnifunc_callback() > ---------------------------------------------------------------------------- > > If you source the above script, it fails with "E119: Not enough > arguments for function: <SNR>15_MyomniFunc1" Yes, a closure with function() does not work, since the function will be evaluated without the partial. It works when using a lambda: var Fn: func = (f, b) => s:MyomniFunc1(14, f, b) &omnifunc = Fn or: &omnifunc = (f, b) => s:MyomniFunc1(14, f, b) However, using a variable instead of "14" does not work, since the lambda is invoked without the context of where it was defined. -- hundred-and-one symptoms of being an internet addict: 16. You step out of your room and realize that your parents have moved and you don't have a clue when it happened. /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net \\\ /// \\\ \\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ /// \\\ 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]. To view this discussion on the web visit https://groups.google.com/d/msgid/vim_dev/20211209164249.CD4D71C0C1F%40moolenaar.net.
