Call arbitrary Lua function over RPC?

I am experimenting with having two neovim instances (A and B) talk to each other RPC. I’d like to have instance A call arbitrary lua functions in instance B. Currently I’m calling nvim_command over RPC and passing a string like lua lua.code.here(....).

This seems more roundabout and harder than it should be-- I need to manually serialize the function/args into a lua string, and prefix it with lua. I’m wondering if I’m missing something, but when I look over the nvim_* API methods I come up blank:

  • There doesn’t seem to be a Lua equivalent of nvim_call_function (which calls an arbitrary Vimscript function).
  • nvim_exec_lua is listed as an API method but apparently doesn’t exist? vim.api.nvim_exec_lua is nil.

What’s the best way to call an arbitrary lua function over RPC?

You can use nvim_exec_lua over RPC.

1 Like