Feature detection is a must in order to support backwards compatibility. Was writing a plugin in lua and noticed that it is currently not possible to support it without eval.
lua print(vim.has('perl')) lua print(vim.has('perl', 1))
Signature is the same as vim's has() function.
https://github.com/vim/vim/pull/6056
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.![]()
Thanks. How about also updating the tests in src/testdir/test_lua.vim?
@prabirshrestha pushed 1 commit.
—
You are receiving this because you are subscribed to this thread.
Added tests. How do I only run that file or function for test.
Added tests. How do I only run that file or function for test.
Getting test failures since luaeval seems to auto-convert integer to float. Now that I think of it it might be better to use boolean in lua side instead of number.
1 FAILED:
Found errors in Test_lua_has():
function RunTheTest[39]..Test_lua_has line 1: Expected 0 but got 0.0
function RunTheTest[39]..Test_lua_has line 2: Expected 1 but got 1.0
function RunTheTest[39]..Test_lua_has line 3: Expected 1 but got 1.0
function RunTheTest[39]..Test_lua_has line 4: Expected 1 but got 1.0
function RunTheTest[39]..Test_lua_has line 5: Expected 0 but got 0.0
function RunTheTest[39]..Test_lua_has line 6: Expected 0 but got 0.0
—
You are receiving this because you commented.
@prabirshrestha pushed 1 commit.
—
You are receiving this because you are subscribed to this thread.
Updated to return boolean for lua instead of number. Fixed the tests.
—
You are receiving this because you commented.
Neovim is doing a lot with Lua, don't they have this?
—
You are receiving this because you commented.
@justinmk Any idea if neovim already include has() api in lua? I coudn't find one.
Neovim has vim.api which is usually prefixed with nvim. I guess that is to avoid conflict with future vim apis but I'm not sure about this. Will let Justin comment on this. Example from docs:
function! CurrentLineInfo() lua << EOF local linenr = vim.api.nvim_win_get_cursor(0)[1] local curline = vim.api.nvim_buf_get_lines( 0, linenr, linenr + 1, false)[1] print(string.format("Current line [%d] has %d bytes", linenr, #curline)) EOF endfunction
I'm planning to add few more functions in lua primarily for use in asyncomplete.vim for perf. Given that it is very small and easy to port goal is to have both vimscript and lua port of the plugin but if it has lua support I want to avoid the plugin to use vimscript at all and viceversa. @brammool @justinmk Would you instead prefer me to send a PR with only doc changes so we can discuss on just the apis and do the actual implementation separately.
One thing to note is that neovim exposes the entire luv bindings. This allows one to even easily create http servers and clients. But for vim this is not possible without eval. I would like to propose something like vim.sleep(1000) so that vim can use internal sleep and neovim can use luv. This would avoid if..else in plugin code.
local luv = require('luv') luv.sleep(1000)
Primary reason for starting the doc PR is I want to have some high level apis such as timer, jobs, autocmd, augroup, json, complete(), pumvisible() without going through too much jumping between vimscript and lua. Neovim also includes std-lib for lua.
local timer = vim.loop.new_timer() timer:start(1000, 0, vim.schedule_wrap(function() vim.api.nvim_command('echomsg "test"') end))
—
You are receiving this because you commented.
Any idea if neovim already include has() api in lua? I coudn't find one.
You can call has by lua like this.
:lua vim.api.nvim_call_function("has", {"nvim"})
If you use Nvim-HEAD version( > v0.4.3), you can use vim.fn like this.
:lua print(vim.fn.has("nvim"))
:lua vim.fn will include Nvim v0.5.0.
—
You are receiving this because you commented.
@h-michael That is great. I think it would be good to officially bring vim.fn.* to vim. vim would then also need to support passing functions around. We would first need to implement vim.call which is internally used by vim.fn. https://github.com/neovim/neovim/blob/1407899c32018f1988936adfddc1dede73c559cb/src/nvim/lua/vim.lua#L262-L271
My JavaScript PR support also had similar __vimcall() which would allow this. #5198
@h-michael Do you know how neovim deals with float vs number. I had issues with timer_stop only supporting integer and not float. How does neovim handle this?
@brammool What are your thoughts on this?
—
You are receiving this because you commented.