I am interested in Nimrod - Nimrod interaction.
E.g. I have
type my_enum = enum a, b, c proc my_func() : my_enum {.exportc, dynlib.} = ...
How do I use this function from another Nimrod DLL? Do I need to copy the my_enum definition there?
You can copy it, or you can extract common parts to an include file. Also watch out this trick:
when defined(createMyDll):
{.pragma: mydll, exportc: "mydll_$1", dynlib.}
elif defined(useMyDll):
when defined(windows):
const theDLL = "mydll.dll"
elif defined(macosx):
const theDLL* = "mydll.dylib"
else:
const theDLL* = "mydll.so"
{.pragma: mydll, importc: "mydll_$1", dynlib: theDLL.}
else:
{.pragma: mydll.}
type my_enum = enum a, b, c
proc my_func() : my_enum {.mydll.} = ...
When useMyDll is defined, the DLL is used. This works because proc bodies are ignored if the proc is also annotated with importc, dynlib. When createMyDll is defined the DLL is built, otherwise it's a build that doesn't use the DLL which isn't a problem since the proc bodies are available too.
I think I got it, it looks as equivalent of the __declspec(dllexport) trickery in C.
May I assume that this trick is (will be) the cannonic way how to use Nimrod DLLs?
The compiler may then predefine a constant as NOW_COMPILING_DLL_BASE_NAME, so one would not need to define them manually (it is nuissance in C++). Perhaps the trick could be fully supported out of box.