0

I'm trying to use v:lua to call functions written in lua (actually it's fennel, which compiles to lua).

Now I have a function named lisp-style , then I can't directly use v:lua.lisp-style() because it's not a valid symbol in vim script.

Here's the specific situation:

_G["lisp-style"] = function() return "b" end
vim.api.nvim_set_keymap("n", "<leader>a", "v:lua.lisp-style()", {noremap=true, expr=true})

So, is there a better approach?

Thanks a lot!

1
0

As an example,

function! LuaCall(...) abort
    return luaeval('_G[_A[1]](unpack(_A, 2))', a:000)
endfunction

:echo LuaCall('lisp-style', 1, 2, 3)

But probably you should just create another variable with a more appropriate name:

:lua lisp_style = _G['lisp-style']
:echo v:lua.lisp_style()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.