ffi_spec.lua (1927B)
1 local t = require('test.testutil') 2 local n = require('test.functional.testnvim')() 3 4 local eq = t.eq 5 local exec_lua = n.exec_lua 6 local clear = n.clear 7 8 before_each(clear) 9 10 describe('ffi.cdef', function() 11 it('can use Neovim core functions', function() 12 if not exec_lua("return pcall(require, 'ffi')") then 13 pending('N/A: missing LuaJIT FFI') 14 end 15 16 eq( 17 12, 18 exec_lua(function() 19 local ffi = require('ffi') 20 21 ffi.cdef [[ 22 typedef struct window_S win_T; 23 int win_col_off(win_T *wp); 24 extern win_T *curwin; 25 ]] 26 27 vim.cmd('set number numberwidth=4 signcolumn=yes:4') 28 29 return ffi.C.win_col_off(ffi.C.curwin) 30 end) 31 ) 32 33 eq( 34 20, 35 exec_lua(function() 36 local ffi = require('ffi') 37 38 ffi.cdef [[ 39 typedef struct {} stl_hlrec_t; 40 typedef struct {} StlClickRecord; 41 typedef struct {} statuscol_T; 42 typedef struct {} Error; 43 44 win_T *find_window_by_handle(int Window, Error *err); 45 46 int build_stl_str_hl( 47 win_T *wp, 48 char *out, 49 size_t outlen, 50 char *fmt, 51 int opt_idx, 52 int opt_scope, 53 int fillchar, 54 int maxwidth, 55 stl_hlrec_t **hltab, 56 StlClickRecord **tabtab, 57 statuscol_T *scp 58 ); 59 ]] 60 61 return ffi.C.build_stl_str_hl( 62 ffi.C.find_window_by_handle(0, ffi.new('Error')), 63 ffi.new('char[1024]'), 64 1024, 65 ffi.cast('char*', 'StatusLineOfLength20'), 66 -1, 67 0, 68 0, 69 0, 70 nil, 71 nil, 72 nil 73 ) 74 end) 75 ) 76 77 -- Check that extern symbols are exported and accessible 78 eq( 79 true, 80 exec_lua(function() 81 local ffi = require('ffi') 82 83 ffi.cdef('uint64_t display_tick;') 84 85 return ffi.C.display_tick >= 0 86 end) 87 ) 88 end) 89 end)