Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling a C++ library function in vimscript

Tags:

vim

vim-plugin

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.

like image 940
Vamsi Avatar asked Jan 23 '12 09:01

Vamsi


1 Answers

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.

like image 134
Benj Avatar answered Oct 05 '22 04:10

Benj