ffi_spec.lua 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. local helpers = require('test.functional.helpers')(after_each)
  2. local eq = helpers.eq
  3. local exec_lua = helpers.exec_lua
  4. local clear = helpers.clear
  5. before_each(clear)
  6. describe('ffi.cdef', function()
  7. it('can use Neovim core functions', function()
  8. if not exec_lua("return pcall(require, 'ffi')") then
  9. pending('missing LuaJIT FFI')
  10. end
  11. eq(12, exec_lua[[
  12. local ffi = require('ffi')
  13. ffi.cdef('int curwin_col_off(void);')
  14. vim.cmd('set number numberwidth=4 signcolumn=yes:4')
  15. return ffi.C.curwin_col_off()
  16. ]])
  17. eq(20, exec_lua[=[
  18. local ffi = require('ffi')
  19. ffi.cdef[[
  20. typedef struct window_S win_T;
  21. typedef struct {} stl_hlrec_t;
  22. typedef struct {} StlClickRecord;
  23. typedef struct {} statuscol_T;
  24. typedef struct {} Error;
  25. win_T *find_window_by_handle(int Window, Error *err);
  26. int build_stl_str_hl(
  27. win_T *wp,
  28. char *out,
  29. size_t outlen,
  30. char *fmt,
  31. char *opt_name,
  32. int opt_scope,
  33. int fillchar,
  34. int maxwidth,
  35. stl_hlrec_t **hltab,
  36. StlClickRecord **tabtab,
  37. statuscol_T *scp
  38. );
  39. ]]
  40. return ffi.C.build_stl_str_hl(
  41. ffi.C.find_window_by_handle(0, ffi.new('Error')),
  42. ffi.new('char[1024]'),
  43. 1024,
  44. ffi.cast('char*', 'StatusLineOfLength20'),
  45. nil,
  46. 0,
  47. 0,
  48. 0,
  49. nil,
  50. nil,
  51. nil
  52. )
  53. ]=])
  54. -- Check that extern symbols are exported and accessible
  55. eq(true, exec_lua[[
  56. local ffi = require('ffi')
  57. ffi.cdef('uint64_t display_tick;')
  58. return ffi.C.display_tick >= 0
  59. ]])
  60. end)
  61. end)