I am wondering how bindings for toolkits written in C++ are created.
Let's consider a "high" level language like Perl/Python/OCaml - AFAIR they are written in "C".
Let's consider a couple of toolkits written in C++, say, Qt and Armadillo ( http://arma.sourceforge.net/
). One has to pay attention that the latter is (mostly ?) C++ templates.
I think I understand how conceptually bindings are written for "simple" (no templates at public interface level) toolkits. A set of "C" wrappers that, first of all, call the C++ toolkit constructors (through "placement new") and call C++ toolkit destructors.
Also, a set of marshallers is needed to interface between the two entities ("high" level language <-> C++ toolkit) is needed.
This set of constructors + destructors can be "packaged" into a (dynamic) library and the library can be linked with the "high" level language and through the "C" wrappers constructors can be called (i.e. objects can be created) and object methods can then be called - they apparently also need "C" wrappers to deal with 'this' issue - 'this' is not known to "C".
So far so good.
Now, the difficult (just to me ?) part - templates. If I understand correctly, if we have C++ stuff to be instantiated through template specialization, we need to include the C++ file and to compile it with the code which is to use the template stuff.
This inclusion + compilation is trivial in C++ world, but not (just to me ?) trivial in the "high" level language written in "C" world.
I am thinking of something along the JIT/late binding lines. I.e. a set of constructs for the "high" level language is created. The constructs will probably internally look like
compile_cxx(template_class_name, template_param_1, ..., template_param_N, ...)
where template_class_name, template_param_1, ..., template_param_N are strings.
Then, when such a construct (in whatever syntactic disguise) is met in "high" level language source, the necessary C++ files are "pulled", the template_class_name template with template_param_1, ..., template_param_N is instantiated, and according to some naming convention a "C" wrapper is created, then that "C" wrapper can be linked to the "high" level language.
Which means yet another pass to parse the "high" level language source is apparently necessary.
The above is a very rough picture, I just want to understand whether I'm thinking in the right direction and whether I'm missing something big.