next up previous contents
Next: 6.2.3 Documentation Up: 6.2.2 Language Binding Previous: Defining new Types

C++/VLisp Binding

The C++ binding to VLisp is similar to the C binding. In addition to all possible C constructs, C++ classes with explicit programmed methods can be bound to VLisp. Special documented variables of the class may be accessed directly from VLisp using the get and set methods of the associated VLisp class. Only the basic C types and their compatible definitions are supported for direct object access as listed in Table 6.8. This is a subset of the types supported by C with the exception of C++ objects. For the corresponding TAC classes see Section 8.4. If no explicit class definition can be found, no object variables are accessible, but binding code is still generated. For each C++ class a corresponding VLisp class is defined and an own VLisp node type for holding the object pointer is created.

  table3581
Tabelle 6.8: Supported C++ class variable types

Additional new user defined types may be used if they have a getclass method defined in their respective tac::name class. To export an instance variable from a class to TAC for binding, it must be documented with a /*** comment instead of a comment with a single /*. An example of a simple binary tree after Adelson-Velskii and Landis[Wir79] (AVL tree) is shown in Figure 6.15. The class definition in the C++ header file is used to make the class known to TAC that it can be later used for method binding.

  figure3624
Abbildung 6.15: Documented C++ class definition for VLisp binding

In this case the C++ class has only two variables. The first root is private to the class methods written in C++, the second size can be accessed later on from VLisp by using
lispprog3638
Since the variable is marked with the key readonly its value cannot be modified from VLisp. Using the VLisp function newobject to the class name avl::tree, the name is constructed by the same rules as C names, a new AVL tree can be generated. If the node is no longer reachable from within the VLisp interpreter, the AVL is automatically freed by the garbage collector. A default method delete to destroy the AVL tree is also implicitly available. Additional methods can be added to the class by documenting C++ methods as shown in Figure 6.16.

  figure3653
Abbildung 6.16: Documented C++ class methods for VLisp binding

With this definitions three additional methods are defined for the VLisp class avl::tree. They allow to insert, remove or search for membership of a string in the AVL tree. The example code will return 3, t for the first pprint command and NIL for the second.


block3669

C++ supports method overloading, e.g., that methods of one class can have the same function name but is distinguishable by the number and/or type of the parameters. TAC is able to create the same VLisp method bindings as long as no parameter conversion conflict exists, e.g., it will not work correctly if two VLisp parameters are identical but differ in C++.


next up previous contents
Next: 6.2.3 Documentation Up: 6.2.2 Language Binding Previous: Defining new Types

IUE WWW server
Fri Jan 3 17:00:13 MET 1997