fix: wrap ffi.load in pcall and give a better error message

Now if libivyrs is not found you get a better message that points the
user to the docs on compiling to try and help them resolve the issue.

Ref: #35
This commit is contained in:
Ade Attwood 2022-12-28 14:49:03 +00:00
parent 3d8d55a146
commit 1af1f0e252

View file

@ -4,7 +4,15 @@ local library_path = (function()
end)()
local ffi = require "ffi"
local ivy_c = ffi.load(library_path)
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
ffi.cdef [[
void ivy_init(const char*);