SWIG

SWIG (Simplified Wrapper and Interface Generator) is a programming tool written in C or C modules for other programming languages ​​, in particular scripting languages ​​, makes available.

SWIG is an open source project and operating system- independent ( cross-platform ) applications.

As a starting languages ​​are C and C are supported as target languages ​​, script languages ​​Tcl, Perl, Python, Ruby, PHP, Lua, and further also Java, C #, Scheme, Ocaml and Go.

Operation

The variety of modern programming languages ​​is therefore sensible to use, because all these languages ​​already existing can access in libraries bundled software on a wide inventory. Operating System-related libraries are mainly written in C. One way to integrate C libraries, belong to the basic scope of any general-purpose scripting language; a language must possess such a mechanism in order to be included as a target language in SWIG can.

The integration is usually done in such a way that the source code of the library output remains unchanged, and additional C functions, so-called wrappers are created. These wrappers are used to interface between the library and the target language and can be called from the target language, accept parameters from the target language and return results to these. Since the wrapper functions to make only one interface adaptation, this in turn call the appropriate function of the output library. In order to achieve a simple use of the target language, it is usually also necessary to encapsulate the calls through constant definitions and / or wrapper in this language.

This process is automated SWIG extensively. You just have to expand the header file of the library to output some specific instructions or embed it in a SWIG - specific super header. Then, SWIG C source code that contains the wrappers for all functions of the output library. In addition, the necessary wrapper code for the target language is generated. In Java, for example, calls via the JNI.

For generating the wrapper is no access to the source code of the output library is required. The wrapper can be compiled with a platform-specific compiler and linked with either in the starting library or into a separate library.

Since only Swig is a code generator and the code is written into by the compiler / linker to the library, in the use of the target language no more runtime is needed.

Confines

The limits of SWIG are essentially determined by the target language. It involves all language elements of C or C that can not be mapped useful there. An example is the multiple inheritance of C , which hardly exist in other languages. In these cases, an adjustment of the source of the starting library, or by a second capsules are necessary.

757533
de