Skip to content

luaeval behavior: functions are serialized to None #550

Description

@wookayin

:python3 vim.funcs.luaeval(...) calls vim.call("luaeval", ...), which then calls nvim_call_function('luaeval', [...]) via RPC, i.e. vim.request('nvim_call_function', 'luaeval', [...]).

Below tested with nvim 0.10.x nightly (as of 11/28/2023) and pynvim 0.5.0 nightly (and 0.4.3).

Primitives are OK:

:python3= vim.funcs.luaeval('1')
:echo nvim_call_function('luaeval', ['1'])
1

:python3= vim.funcs.luaeval('"foo"')
:echo nvim_call_function('luaeval', ['"foo"'])
foo

:python3= vim.funcs.luaeval('nil')
None
:echo nvim_call_function('luaeval', ['nil'])
v:null

:python3= vim.funcs.luaeval('{}')
:echo nvim_call_function('luaeval', ['{}'])
[]

:python3= vim.funcs.luaeval('{ dict = true }')
{'dict': True}
:echo nvim_call_function('luaeval', ['{ dict = true }'])
{'dict': v:true}

Functions are not:

:echo nvim_call_function('luaeval', ['function() end'])
<lambda>36075

" ❌ THIS IS BUGGY !!!!!!!!!
:python3= vim.funcs.luaeval('function() end')
None


" the proxy function is callable!
:call nvim_call_function('luaeval', ['print'])("foo")
foo

:lua vim.api.nvim_call_function('luaeval', { "print" })("foo")
foo

and hence modules:

" ❌ THIS IS BUGGY !!!!!!!!!
:python3= vim.funcs.luaeval('require("vim.ui")')
{'select': None, 'open': None, 'input': None}

:echo nvim_call_function('luaeval', ['vim.ui'])
{'select': function('<lambda>254'), 'open': function('<lambda>255'), 'input': function('<lambda>256')}

which should instead throw an error if conversion is not possible. Ideally it may return some "proxy" callable that delegates to the target lua function via RPC.

Also, the following seems to be neovim core's bug (or a lack of feature):

" ❌ should return a lambda function?
:echo nvim_call_function('eval', ['{ -> 3 }'])
v:null

" ❌ should return a function?
:python3= vim.call('eval', '{ -> 3 }')
None

:echo eval('{ -> 3 }')
function('<lambda>49485')

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Fields

    Effort

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions