Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

something wrong with luaeval() #22863

Closed
wsdjeg opened this issue Apr 2, 2023 · 6 comments
Closed

something wrong with luaeval() #22863

wsdjeg opened this issue Apr 2, 2023 · 6 comments
Labels
bug issues reporting wrong behavior lua stdlib

Comments

@wsdjeg
Copy link
Contributor

wsdjeg commented Apr 2, 2023

Problem

when use luaeval() to get the lua value, can not change the value.

Steps to reproduce

create two files:

  1. autoload/testl.vim
function! testl#test() abort
  return luaeval('require("testluaeval").test()')
endfunction
  1. lua/testluaeval.lua
--!/usr/bin/lua

local M = {}


function M.test() -- {{{
  local a = {}
  a.t = true
  function a.change_t() -- {{{
    a.t = false
  end
  return a
  -- }}}
end
-- }}}


return M
  1. run following command:
let wsd = testl#test()
call wsd.change_t()
echo wsd.t

you will see v:true, but it should be v:false

  1. it works well in lua:
lua wsd = require('testluaeval').test()
lua wsd.change_t()
lua print(wsd.t)

then it works well, and you will see false printed.

Expected behavior

in the reproduce step 3, echo wsd.t should be v:false.

Neovim version (nvim -v)

NVIM v0.7.0

Vim (not Nvim) behaves the same?

no

Operating system/version

win 11

Terminal name/version

neovim-qt

$TERM environment variable

empty

Installation

release page

@wsdjeg wsdjeg added the bug issues reporting wrong behavior label Apr 2, 2023
@bfredl
Copy link
Member

bfredl commented Apr 2, 2023

We don't have bindeval for tables. related: #1898 .

A workaround for your usecase might be to return both setter and a getter functions (closures are bound).

@zeertzjq zeertzjq added the lua stdlib label Apr 2, 2023
@wsdjeg

This comment was marked as resolved.

@bfredl
Copy link
Member

bfredl commented Apr 2, 2023

are you sure? it works for me. check :messages in case the printed message got lost.

@wsdjeg

This comment was marked as resolved.

@wsdjeg

This comment was marked as resolved.

@wsdjeg
Copy link
Contributor Author

wsdjeg commented Apr 3, 2023

@bfredl thanks, I fixed it in my plugin. as a workaroud for this:

change the lua code in step2 to:

local M = {}


function M.test() -- {{{
  local a = {}
  a.t = true
  function a.change_t() -- {{{
    a.t = false
  end
  function a.get_t() -- {{{
    return a.t
  end
  -- }}}
  return a
  -- }}}
end
-- }}}


return M

and in step 3:

let wsd = testl#test()
call wsd.change_t()
echo wsd.get_t()  " use get_t() function instead of value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug issues reporting wrong behavior lua stdlib
Projects
None yet
Development

No branches or pull requests

3 participants