Is there a way to call a C++ shared library function from within a vim plugin written in vimscript?
Say there is a hello_world.so that has a function hello_world(). I want to call this function whenever the vim user uses a particular key binding.
Yes you can do this, try: help libcall
You'll have to export the functions as undecorated C functions with the "cdecl" calling convention I suspect:
From vim help:
For Win32, the functions you write must be placed in a DLL and use the normal C calling convention (NOT Pascal which is used in Windows System DLLs). The function must take exactly one parameter, either a character pointer or a long integer, and must return a character pointer or NULL. The character pointer returned must point to memory that will remain valid after the function has returned (e.g. in static data in the DLL). If it points to allocated memory, that memory will leak away. Using a static buffer in the function should work, it's then freed when the DLL is unloaded.
There's an example of how to do it here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With