comparison src/testdir/test_lua.vim @ 14235:e3bc8cdc94dd v8.1.0134

patch 8.1.0134: Lua interface does not support funcref commit https://github.com/vim/vim/commit/ca06da92432a57e5dcf3e0eebd322fae80941a6b Author: Bram Moolenaar <Bram@vim.org> Date: Sun Jul 1 15:12:05 2018 +0200 patch 8.1.0134: Lua interface does not support funcref Problem: Lua interface does not support funcref. Solution: Add funcref support. (Luis Carvalho)
author Christian Brabandt <cb@256bit.org>
date Sun, 01 Jul 2018 15:15:06 +0200
parents 2e95ea9afa1e
children 7457bf2db968
comparison
equal deleted inserted replaced
14234:4abb1a6122f1 14235:e3bc8cdc94dd
395 call assert_equal('a:1,b:2,', luaeval('str')) 395 call assert_equal('a:1,b:2,', luaeval('str'))
396 396
397 lua str, k, v, d = nil, nil, nil, nil 397 lua str, k, v, d = nil, nil, nil, nil
398 endfunc 398 endfunc
399 399
400 func Test_funcref()
401 function I(x)
402 return a:x
403 endfunction
404 let R = function('I')
405 lua i1 = vim.funcref"I"
406 lua i2 = vim.eval"R"
407 lua msg = "funcref|test|" .. (#i2(i1) == #i1(i2) and "OK" or "FAIL")
408 lua msg = vim.funcref"tr"(msg, "|", " ")
409 call assert_equal("funcref test OK", luaeval('msg'))
410
411 " dict funcref
412 function Mylen() dict
413 return len(self.data)
414 endfunction
415 let l = [0, 1, 2, 3]
416 let mydict = {'data': l}
417 lua d = vim.eval"mydict"
418 lua d.len = vim.funcref"Mylen" -- assign d as 'self'
419 lua res = (d.len() == vim.funcref"len"(vim.eval"l")) and "OK" or "FAIL"
420 call assert_equal("OK", luaeval('res'))
421 endfunc
422
400 " Test vim.type() 423 " Test vim.type()
401 func Test_type() 424 func Test_type()
402 " The following values are identical to Lua's type function. 425 " The following values are identical to Lua's type function.
403 call assert_equal('string', luaeval('vim.type("foo")')) 426 call assert_equal('string', luaeval('vim.type("foo")'))
404 call assert_equal('number', luaeval('vim.type(1)')) 427 call assert_equal('number', luaeval('vim.type(1)'))
412 " The following values are specific to Vim. 435 " The following values are specific to Vim.
413 call assert_equal('window', luaeval('vim.type(vim.window())')) 436 call assert_equal('window', luaeval('vim.type(vim.window())'))
414 call assert_equal('buffer', luaeval('vim.type(vim.buffer())')) 437 call assert_equal('buffer', luaeval('vim.type(vim.buffer())'))
415 call assert_equal('list', luaeval('vim.type(vim.list())')) 438 call assert_equal('list', luaeval('vim.type(vim.list())'))
416 call assert_equal('dict', luaeval('vim.type(vim.dict())')) 439 call assert_equal('dict', luaeval('vim.type(vim.dict())'))
440 call assert_equal('funcref', luaeval('vim.type(vim.funcref("Test_type"))'))
417 endfunc 441 endfunc
418 442
419 " Test vim.open() 443 " Test vim.open()
420 func Test_open() 444 func Test_open()
421 call assert_notmatch('XOpen', execute('ls')) 445 call assert_notmatch('XOpen', execute('ls'))