VTK/Wrappers: Difference between revisions
Line 11: | Line 11: | ||
# Compile and link the glue code to create wrapper-language modules | # Compile and link the glue code to create wrapper-language modules | ||
Steps 1, 2, and 5 are done by CMake. Steps 3 and 4 are done by the VTK wrapping tools | Steps 1, 2, and 5 are done by CMake. Steps 3 and 4 are done by the VTK wrapping tools (steps 3 and 4 are often done by a single program). | ||
== Wrapping Macros == | == Wrapping Macros == |
Revision as of 17:13, 9 November 2012
In addition to C++, VTK can be used through Tcl, Python, Java, and .NET (e.g. C#, Visual Basic). These are commonly referred to as the "wrapper languages" for VTK. Wrapping is the process by which the API of VTK (i.e. its class interfaces, as described by the VTK class header files) are made available in another language through the creation of "glue code".
Wrapping Process
Wrapping is a multi-stage process, involving the following steps:
- Identify header files that contain wrappable interfaces
- Generate build rules that will create glue code from header files
- Parse the header files to generate a description of the interfaces
- Generate glue code from these descriptions
- Compile and link the glue code to create wrapper-language modules
Steps 1, 2, and 5 are done by CMake. Steps 3 and 4 are done by the VTK wrapping tools (steps 3 and 4 are often done by a single program).
Wrapping Macros
TBD
Wrapping Tools
The wrapping tools that come with VTK are:
- vtkWrapPython
- vtkWrapTcl
- vtkWrapJava/vtkParseJava
- vtkWrapJavaBeans (obsolete)
- vtkWrapHierarchy
- vtkHTML (obsoleted in favor of Doxygen)
- vtkPrint (obsolete)
Usage of command-line tools:
Source Code
The source code for the VTK wrapper tools is located in VTK/Wrapping/Tools.
vtkParse.y (vtkParse.tab.c): A C++ parser built with "yacc". The file vtkParse.y contains the rules of the C++ grammar, or at least all rules that are needed to parse a C++ interface. It parses everything except for the code within function bodies, which it ignores. The file vtkParse.tab.c is generated from vtkParse.y with "yacc":
yacc -b vtkParse vtkParse.y
vtkParse.l (lex.yy.c): A helper file for the parser, which is responsible for breaking a C++ header file into C++ tokens, and also for calling upon the preprocessor when macros and preprocessor directives are encountered in the code. The source file lex.yy.c is generated from vtkParse.l with the following command:
flex --nodefault -olex.yy.c vtkParse.l
vtkParsePreprocess.c: A C++ preprocessor, which evaluates preprocessor directives and expands macros.
vtkParseMain.c: Contains code for reading options from the command line.
vtkWrapPython.c: Generates glue code for the python wrappers.