Re: vim9script job function handler not recognized

13 views
Skip to first unread message

Bram Moolenaar

unread,
Mar 19, 2021, 3:13:46 PM3/19/21
to vim...@googlegroups.com, Ni Va

Ni Va wrote:

> I got not recognized function handler starting a job in vim9script.
>
>
> *"*
> *Error detected while processing function <SNR>24_ZipUpDir:*
> *line 60:*
> *E700: Unknown function: MyHandlerCallback *
> "
>
> And this is the vim9script:
>
> "
> vim9script
>
> var jobid: job
> var options: dict<any>
>
> # Job Part {{{
> def MyHandlerExit(channel: channel, msg: string): void
> job_stop(jobid)
> echomsg 'Exiting ' .. string(msg) .. ' ' .. string(@z)
>
> def MyHandlerCallback2(channel: channel, msg: string)
> echomsg string(msg)
> enddef
>
> options = { "callback": function('MyHandlerCallback2') }
> job_start(cmd, options)
> enddef
>
> def MyHandlerCallback(channel: channel, msg: string): void
> echomsg string(msg)
> enddef
>
> options = { 'callback': function('MyHandlerCallback'), 'exit_cb':
> function('MyHandlerExit'), 'timeout': 30000 }
> jobid = job_start(cmd, options) | echomsg 'jobid: ' .. string(jobid)
>
> "

"cmd" is not defined. But you probably want to remove function() and
use MyHandlerCallback directly. The function will be defined
script-local, and using it as a string won't work inside job-start().

You don't need the ": void" for the function, not returning anything is
the default.

--
Contrary to popular belief, it's often your clothing that gets promoted, not
you.
(Scott Adams - The Dilbert principle)

/// Bram Moolenaar -- Br...@Moolenaar.net -- 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 ///

Ni Va

unread,
Mar 19, 2021, 3:19:04 PM3/19/21
to vim_use
Hi Bram,


I was inspired by testdir/test_vim9script...vim  and write these lines. 
I wonder how can this job can be monitored during its running life  maybe by callback or another job.



"
  # Zip command line
  @z = stampedDir .. archiveName 
  var archive_cmd: string = sevenZ.exe .. sevenZ.exclusion  .. ' a "' .. @z .. '" "' .. archiveSourcePath .. '"' .. sevenZ.compression


  # Zip's job
  var jobid: job
  var source: list<number>

  def Out_cb(...l: any)
      eval [][0]
  enddef
  def Exit_cb(...l: any)
sleep 1m
source += l
echomsg 'Exiting ' .. string(l) .. ' ' .. string(@z)
  enddef

  jobid = job_start(archive_cmd, { out_cb: Out_cb, exit_cb:  Exit_cb, mode: 'raw', timeout: 30000 } )
  echomsg 'jobid: ' .. string(jobid)
"


Reply all
Reply to author
Forward
0 new messages