diff options
author | Björn Linse <bjorn.linse@gmail.com> | 2019-06-23 20:10:28 +0200 |
---|---|---|
committer | Björn Linse <bjorn.linse@gmail.com> | 2019-06-30 13:13:08 +0200 |
commit | d33aaa0f5f96afb1608a4a3eb2057da956a24b2b (patch) | |
tree | 914d11e9d5d4d769069a11841371d1cc8cd1a802 /runtime | |
parent | 7030d7daf1f40e5a3963340d1107d7b7a713df5f (diff) | |
download | rneovim-d33aaa0f5f96afb1608a4a3eb2057da956a24b2b.tar.gz rneovim-d33aaa0f5f96afb1608a4a3eb2057da956a24b2b.tar.bz2 rneovim-d33aaa0f5f96afb1608a4a3eb2057da956a24b2b.zip |
libluv: use luv_set_callback to control callback execution
Disable the use of deferred API functions in a fast lua callback
Correctly display error messages from a fast lua callback
Diffstat (limited to 'runtime')
-rw-r--r-- | runtime/doc/if_lua.txt | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/runtime/doc/if_lua.txt b/runtime/doc/if_lua.txt index cbc19a63a2..6dcf3f9fa9 100644 --- a/runtime/doc/if_lua.txt +++ b/runtime/doc/if_lua.txt @@ -382,20 +382,26 @@ management. Try this command to see available functions: > 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: > + *E5560* *lua-loop-callbacks* +Note: it is not allowed to directly invoke most of the Nvim API from `vim.loop` +callbacks. This will result in an error: > local timer = vim.loop.new_timer() timer:start(1000, 0, function() - vim.api.nvim_command('sleep 100m') -- BROKEN, will crash. + vim.api.nvim_command('echomsg "test"') end) -Instead wrap the API call with |vim.schedule()|. > +The `vim.schedule_wrap` helper can be used to defer the callback until it +is safe to execute API methods. > local timer = vim.loop.new_timer() - timer:start(1000, 0, function() - vim.schedule(function() vim.api.nvim_command('sleep 100m') end) - end) + timer:start(1000, 0, vim.schedule_wrap(function() + vim.api.nvim_command('echomsg "test"') + end)) + +A subset of the API is available in direct luv callbacks ("fast" callbacks), +most notably |nvim_get_mode()| and |nvim_input()|. + Example: repeating timer 1. Save this code to a file. |