-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.lua
More file actions
51 lines (40 loc) · 1.03 KB
/
Copy pathtest.lua
File metadata and controls
51 lines (40 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
local ffi = require('ffi')
local lib = ffi.load('build/release/libfuzzy.so')
ffi.cdef[[
typedef struct
{
char* str;
size_t len;
} fzf_string;
typedef struct
{
fzf_string results[40];
size_t len;
} fzf_output;
void fzf_init(char** ignore, int len);
void fzf_start(fzf_string* prompt);
fzf_output fzf_get_output();
int fzf_char_match(fzf_string* s1, fzf_string* s2);
int fzf_fuzzy_match(fzf_string* s1, fzf_string* s2);
]]
print("fzf_setup")
local ignore = ffi.new('char*[?]', 2)
ignore[0] = ffi.new('char[?]', #'./.git')
ffi.copy(ignore[0], './.git')
ignore[1] = ffi.new('char[?]', #'./build')
ffi.copy(ignore[1], './build')
lib.fzf_init(ignore, 2)
local prompt = ffi.new('fzf_string[?]', 1)
prompt[0].str = ffi.new('char[?]', #'main' + 1)
ffi.copy(prompt[0].str, 'main')
prompt[0].len = #'main'
lib.fzf_start(prompt)
for j = 0, 10 do
local output = lib.fzf_get_output()
local len = tonumber(output.len) - 1
print(len)
for i = 0, len do
local string = output.results[i]
print(ffi.string(string.str, string.len))
end
end