diff options
Diffstat (limited to 'runtime/doc/if_lua.txt')
-rw-r--r-- | runtime/doc/if_lua.txt | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/runtime/doc/if_lua.txt b/runtime/doc/if_lua.txt index b8d520e6e5..cbc19a63a2 100644 --- a/runtime/doc/if_lua.txt +++ b/runtime/doc/if_lua.txt @@ -365,21 +365,38 @@ VIM.API *lua-api* `vim.api` exposes the full Nvim |API| as a table of Lua functions. -For example, to use the "nvim_get_current_line()" API function, call +Example: to use the "nvim_get_current_line()" API function, call "vim.api.nvim_get_current_line()": > print(tostring(vim.api.nvim_get_current_line())) ------------------------------------------------------------------------------ -VIM.LOOP *lua-loop* +VIM.LOOP *lua-loop* `vim.loop` exposes all features of the Nvim event-loop. This is a lower-level API that provides functionality for networking, filesystem, and process -management. +management. Try this command to see available functions: > + + :lua print(vim.inspect(vim.loop)) See http://docs.libuv.org for complete documentation. See https://github.com/luvit/luv/tree/master/examples for examples. +Note: it is not safe to directly invoke the Nvim API from `vim.loop` +callbacks. This will crash: > + + local timer = vim.loop.new_timer() + timer:start(1000, 0, function() + vim.api.nvim_command('sleep 100m') -- BROKEN, will crash. + end) + +Instead wrap the API call with |vim.schedule()|. > + + local timer = vim.loop.new_timer() + timer:start(1000, 0, function() + vim.schedule(function() vim.api.nvim_command('sleep 100m') end) + end) + Example: repeating timer 1. Save this code to a file. 2. Execute it with ":luafile %". > |