diff options
author | Bram Moolenaar <Bram@vim.org> | 2020-06-25 19:27:56 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2020-06-25 19:27:56 +0200 |
commit | 801ab069341c8652680d63c174530fd4feb2911e (patch) | |
tree | ff8d365fe4c9ea1dbd5b5918b3a58568a77ec18e /src/testdir/test_lua.vim | |
parent | 832adf9bb8cd39d8e982d8a35ed8a6d39b974494 (diff) | |
download | vim-git-801ab069341c8652680d63c174530fd4feb2911e.tar.gz |
patch 8.2.1054: not so easy to pass a lua function to Vimv8.2.1054
Problem: Not so easy to pass a lua function to Vim.
Solution: Convert a Lua function and closure to a Vim funcref. (Prabir
Shrestha, closes #6246)
Diffstat (limited to 'src/testdir/test_lua.vim')
-rw-r--r-- | src/testdir/test_lua.vim | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/testdir/test_lua.vim b/src/testdir/test_lua.vim index bd50bce56..826a7bce8 100644 --- a/src/testdir/test_lua.vim +++ b/src/testdir/test_lua.vim @@ -541,6 +541,35 @@ func Test_update_package_paths() call assert_equal("hello from lua", luaeval("require('testluaplugin').hello()")) endfunc +func Vim_func_call_lua_callback(Concat, Cb) + let l:message = a:Concat("hello", "vim") + call a:Cb(l:message) +endfunc + +func Test_pass_lua_callback_to_vim_from_lua() + lua pass_lua_callback_to_vim_from_lua_result = "" + call assert_equal("", luaeval("pass_lua_callback_to_vim_from_lua_result")) + lua <<EOF + vim.funcref('Vim_func_call_lua_callback')( + function(greeting, message) + return greeting .. " " .. message + end, + function(message) + pass_lua_callback_to_vim_from_lua_result = message + end) +EOF + call assert_equal("hello vim", luaeval("pass_lua_callback_to_vim_from_lua_result")) +endfunc + +func Vim_func_call_metatable_lua_callback(Greet) + return a:Greet("world") +endfunc + +func Test_pass_lua_metatable_callback_to_vim_from_lua() + let result = luaeval("vim.funcref('Vim_func_call_metatable_lua_callback')(setmetatable({ space = ' '}, { __call = function(tbl, msg) return 'hello' .. tbl.space .. msg end }) )") + call assert_equal("hello world", result) +endfunc + " Test vim.line() func Test_lua_line() new |