File tree 2 files changed +25
-21
lines changed
2 files changed +25
-21
lines changed Original file line number Diff line number Diff line change 1
1
local M = {}
2
2
3
- --- @type ffi.namespace*
4
- local C = nil
5
-
6
- function M .setup ()
7
- local ffi = require (" ffi" )
8
- local ok , err = pcall (
9
- ffi .cdef ,
10
- [[ typedef int32_t RgbValue;
3
+ --- @return ffi.namespace*
4
+ function M .load ()
5
+ -- Put in a global var to make sure we dont reload
6
+ -- when plugin reloaders do their thing
7
+ if not _G .noice_C then
8
+ local ffi = require (" ffi" )
9
+ local ok , err = pcall (
10
+ ffi .cdef ,
11
+ [[ typedef int32_t RgbValue;
11
12
typedef struct attr_entry {
12
13
int16_t rgb_ae_attr, cterm_ae_attr;
13
14
RgbValue rgb_fg_color, rgb_bg_color, rgb_sp_color;
@@ -18,25 +19,21 @@ function M.setup()
18
19
void update_screen();
19
20
bool cmdpreview;
20
21
]]
21
- )
22
- --- @diagnostic disable-next-line : need-check-nil
23
- if not ok and not err :find (" redefine" ) then
24
- error (err )
22
+ )
23
+ --- @diagnostic disable-next-line : need-check-nil
24
+ if not ok then
25
+ error (err )
26
+ end
27
+ _G .noice_C = ffi .C
25
28
end
26
- C = ffi . C
29
+ return _G . noice_C
27
30
end
28
31
29
32
return setmetatable (M , {
30
33
__index = function (_ , key )
31
- if not C then
32
- M .setup ()
33
- end
34
- return C [key ]
34
+ return M .load ()[key ]
35
35
end ,
36
36
__newindex = function (_ , k , v )
37
- if not C then
38
- M .setup ()
39
- end
40
- C [k ] = v
37
+ M .load ()[k ] = v
41
38
end ,
42
39
})
Original file line number Diff line number Diff line change
1
+ local lazy = require (" noice.util.lazy" )
2
+
3
+ describe (" ffi" , function ()
4
+ it (" cmdpreview is false" , function ()
5
+ assert (lazy (" noice.util.ffi" ).cmdpreview == false )
6
+ end )
7
+ end )
You can’t perform that action at this time.
0 commit comments