swig-fortran / swig

This fork of SWIG creates Fortran wrapper code from C++ headers.
http://www.swig.org
Other
44 stars 11 forks source link

Reverse linking #178

Closed LecrisUT closed 1 year ago

LecrisUT commented 1 year ago

It would be nice to be able to generate helper classes/struct for link in reverse as well. E.g. defining a string type in fortran that can be instantiated on the fortran side and passed to the C side as fortran::string with a simple implicit converter to std::string.

LecrisUT commented 1 year ago

I have made a simple repo with some desirable interface.

sethrj commented 1 year ago

@LecrisUT Sorry I didn't see this issue until today. Generating C++ code from "target language" code is well outside the scope of SWIG, which can only parse C++ and only generates wrappers in the target language (which is, in this case, Fortran). From the second paragraph of the SWIG-Fortran documentation:

SWIG differs from other attempts to couple C/C++ and Fortran in that it is designed to provide C and C++ functionality to Fortran, and not to generically make these two languages (or others like Python) interoperable. SWIG only parses C and C++ code; it does not parse Fortran code or generate C/C++ interfaces to Fortran libraries. SWIG assumes that you, the library developer, have an existing, working C/C++ interface that you wish to adapt to the Fortran target language. This adaptation may include tweaks for ease of use or familiarity for Fortran users, but it does not require that your library be developed around a central interface language. This is in contrast to other existing cross-language interoperability tools such as Babel.

What you suggest would be neat and could indeed use some of the wrapper code that's defined by SWIG, but it's not the intent of SWIG.