comparison runtime/doc/if_lua.txt @ 21006:ae185f35e256 v8.2.1054

patch 8.2.1054: not so easy to pass a lua function to Vim Commit: https://github.com/vim/vim/commit/801ab069341c8652680d63c174530fd4feb2911e Author: Bram Moolenaar <Bram@vim.org> Date: Thu Jun 25 19:27:56 2020 +0200 patch 8.2.1054: not so easy to pass a lua function to Vim Problem: Not so easy to pass a lua function to Vim. Solution: Convert a Lua function and closure to a Vim funcref. (Prabir Shrestha, closes #6246)
author Bram Moolenaar <Bram@vim.org>
date Thu, 25 Jun 2020 19:30:21 +0200
parents 74e3316c1d5a
children 08e284594211
comparison
equal deleted inserted replaced
21005:3f0abea9bed2 21006:ae185f35e256
331 :lua d = vim.eval('mydict'); d.len = vim.funcref('Mylen') 331 :lua d = vim.eval('mydict'); d.len = vim.funcref('Mylen')
332 :echo mydict.len() 332 :echo mydict.len()
333 :lua l = d.len -- assign d as 'self' 333 :lua l = d.len -- assign d as 'self'
334 :lua print(l()) 334 :lua print(l())
335 < 335 <
336 Lua functions and closures are automatically converted to a Vim |Funcref| and
337 can be accessed in Vim scripts. Example:
338 >
339 lua <<EOF
340 vim.fn.timer_start(1000, function(timer)
341 print('timer callback')
342 end)
343 EOF
336 344
337 ============================================================================== 345 ==============================================================================
338 7. Buffer userdata *lua-buffer* 346 7. Buffer userdata *lua-buffer*
339 347
340 Buffer userdata represent vim buffers. A buffer userdata "b" has the following 348 Buffer userdata represent vim buffers. A buffer userdata "b" has the following