I'm trying to write a Neovim module in Odin, it compiles as dynamicall-linked library and load by require(my_odin_neovim_configuration) in Lua.
The module has the following entry point:
@(export)
luaopen_my_odin_neovim_configuration :: proc "c" () -> c.int {
fmt.printf("\n>>> Hello from Odin neovim plugin.")
// nvim_api_test()
return 1
}
Compiled and can be loaded in Neovim and the printf works fine (I redirect the stderr to a file can see the print content: nvim 2>debug.log.
cat debug.log
>>> Hello from Odin neovim plugin.
#
# This comes from the C version module
#cat debug.log
>>> My neovim configuration C version:)
>>> api_ptr: 0x484590
But now, I tried to call neovim C API, so I write a sample API binding like this:
//
// Ignore all types,struct migrate from C to Odin...
//
when ODIN_OS == .Linux || ODIN_OS == .FreeBSD || ODIN_OS == .Darwin {
// foreign import nvim "system:nvim" // This won't work, as 'libnvim.so' doesn't exists
// foreign import nvim "nvim" // This won't work, as 'libnvim.so' doesn't exists
foreign import nvim "" // This won't work, as not allow for emtry string
} else when ODIN_OS == .Windows {
foreign import nvim "system:nvim.dll"
}
@(default_calling_convention="c")
foreign nvim {
nvim_buf_line_count :: proc "c" (buffer: Buffer, err: ^Error) -> Integer ---
}
But the problem is that it seems Odin foreign import forces you to define the libraray part, so the odin compiler does -l libXXX link flag for you. In this case, I believe my_odin_neovim_configuration.so doesn't need to link at compile time, as nvim_buf_line_count will exists when Neovim is running. The C version works fine, as you only declare a foreign function by the extern keyword without providing any linker flag. Does it possible in Odin?