2022-07-23 07:49:45 +00:00
|
|
|
local library_path = (function()
|
2023-06-09 18:07:01 +00:00
|
|
|
local root = string.sub(debug.getinfo(1).source, 2, #"/libivy.lua" * -1)
|
|
|
|
|
local release_path = root .. "../../target/release"
|
|
|
|
|
return package.searchpath("libivyrs", release_path .. "/?.so;" .. release_path .. "/?.dylib;")
|
2022-07-23 07:49:45 +00:00
|
|
|
end)()
|
|
|
|
|
|
|
|
|
|
local ffi = require "ffi"
|
2022-12-28 14:49:03 +00:00
|
|
|
local ok, ivy_c = pcall(ffi.load, library_path)
|
|
|
|
|
if not ok then
|
|
|
|
|
vim.api.nvim_err_writeln(
|
|
|
|
|
"libivyrs.so not found! Please ensure you have complied the shared library."
|
|
|
|
|
.. " For more info refer to the documentation, https://github.com/AdeAttwood/ivy.nvim#compiling"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
return
|
|
|
|
|
end
|
2022-07-23 07:49:45 +00:00
|
|
|
|
|
|
|
|
ffi.cdef [[
|
|
|
|
|
void ivy_init(const char*);
|
2022-09-04 12:10:11 +00:00
|
|
|
char* ivy_cwd();
|
2022-07-23 07:49:45 +00:00
|
|
|
int ivy_match(const char*, const char*);
|
|
|
|
|
char* ivy_files(const char*, const char*);
|
|
|
|
|
]]
|
|
|
|
|
|
|
|
|
|
local libivy = {}
|
|
|
|
|
|
|
|
|
|
libivy.ivy_init = function(dir)
|
|
|
|
|
ivy_c.ivy_init(dir)
|
|
|
|
|
end
|
|
|
|
|
|
2022-09-04 15:13:02 +00:00
|
|
|
libivy.ivy_cwd = function()
|
|
|
|
|
return ffi.string(ivy_c.ivy_cwd())
|
2022-09-04 12:10:11 +00:00
|
|
|
end
|
|
|
|
|
|
2022-07-23 07:49:45 +00:00
|
|
|
libivy.ivy_match = function(pattern, text)
|
|
|
|
|
return ivy_c.ivy_match(pattern, text)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
libivy.ivy_files = function(pattern, base_dir)
|
|
|
|
|
return ffi.string(ivy_c.ivy_files(pattern, base_dir))
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
return libivy
|