I’m working on some D bindings for an existing C library, and I have a bunch of function definitions, and a bunch of bindings for them. For example:
// Functions
void function(int) funcA;
long function() funcB;
bool function(bool) funcC;
char function(string) funcD;
// etc...
// Bindings
if(!presentInLibrary("func")) return false;
if(!bindFunction(funcA, "funcA")) return false;
if(!bindFunction(funcB, "funcB")) return false;
if(!bindFunction(funcC, "funcC")) return false;
if(!bindFunction(funcD, "funcD")) return false;
// etc...
This model is very similar to how Derelict handles OpenGL extension loading. However, this seems like a lot of redundant typing. I’d really like a way to express the “binding” portion above as something like:
BINDGROUP("func", "funcA", "funcB", "funcC", "funcD", ...); // Name of function group, then variable list of function names.
Is this something that can be done with mixins?
I used this when I was doing dynamic loading, while it doesn’t answer your question you may be able to adapt it:
Here
bindFunctions("a", "b", "c")returns a string that looks something like:Where
lib.getSymbol()returns a pointer fromdl_open()etc. Hope this helps.