Skip to content

add vim.call() for lua and vim.fn.*#6063

Closed
prabirshrestha wants to merge 7 commits intovim:masterfrom
prabirshrestha:lua-call
Closed

add vim.call() for lua and vim.fn.*#6063
prabirshrestha wants to merge 7 commits intovim:masterfrom
prabirshrestha:lua-call

Conversation

@prabirshrestha
Copy link

@prabirshrestha prabirshrestha commented May 11, 2020

Based on #6056 (comment) neovim > v0.5.0 will have support for vim.fn which is already in their master.

There are two new apis exposed to lua interface i.e. vim.call and vim.fn.

  • :lua print(vim.call('has', 'nvim'))
  • :lua vim.fn.has('nvim')
  • document vim.call
  • document vim.fn
  • add tests for vim.call
  • add tests for vim.fn

Additional features that can be done in different PR:

  • currently all everything from lua to vim is always converted to flow so certain functions such as timer_stop which only takes integer doesn't work. neovim seems to handle it correctly already.
  • luaV_totypval needs to be able to convert lua functions to vimfunc. This will allow us to use functions such as timer_start which takes in function.

@justinmk
Copy link
Contributor

During the plan for Vim9, @brammool declared that the legacy interfaces (lua, tcl, python, etc.) in Vim were deprecated. Did that change?

@brammool
Copy link
Contributor

brammool commented May 11, 2020 via email

@justinmk
Copy link
Contributor

During the plan for Vim9, @brammool declared that the legacy interfaces (lua, tcl, python, etc.) in Vim were deprecated. Did that change?

No change. It doesn't mean no more changes are allowed, just that it's less likely more work will be done.

What makes it less likely?

@prabirshrestha
Copy link
Author

@brammool I have updated the PR with tests and docs so should be good for review. Let me know if I'm missing anything else.

Few things to note:
Instead of all numbers being turned to float it tries to use integer if possible which is similar to neovim. The code is ported from neovim.
Lua callback can't be converted to vim function for use. This would block using features such as timer_start and job_start(). It would be good if someone who has expertise in lua c bindings and vim code base to contribute here. While not required for this PR to be merged it would really be good to have this support so that one could just use vim.call or vim.fn check instead of checking for version numbers. Neovim is already capable of converting lua functions to vim but their lua interface code seems to have diverged so didn't dig around much to port it.

@brammool
Copy link
Contributor

Thanks. I'll include this. If more changes are desirable for plugin writers that use Lua I hope someone can pick that up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants