I have some cpp files, and I want to combine them with LuaJit using FFI.
But the problem is that, I have to add extern "c"
symbols for almost every function to make it possible for FFI to access them.
Is there a simpler way to make this done?
I have some cpp files, and I want to combine them with LuaJit using FFI.
But the problem is that, I have to add extern "c"
symbols for almost every function to make it possible for FFI to access them.
Is there a simpler way to make this done?
Several functions can be placed inside a single extern "C"
block. This allows you to type extern "C"
only once for each header file.
extern "C" {
void function1();
void function2();
}
Though it is non-portable, you could implement a function signature and generates the Mangled name using the name mangling protocol to find the symbol name for FFI.
Gcc and Clang on Linux use the Itanium C++ ABI Name Mangling Rules, which can be found here.
On Windows, MSVC uses a non-documented name mangling scheme.
Yes. Define a simple, minimal, wrapper API and export it:
// NOTE: Exported functions do heavy parley and medical-research leveraging C++ under the hood (and only and the hood).
extern "C" {
void achieve_world_peace(void);
void treat_cancer(void);
}