
c++ class-method & Tcl_CreateCommand
In a message on 5 Mar 1996 13:48:43 -0700, wrote :
EG> C++ methods implicitly take an extra "this" pointer argument. Thus,
EG> in order to invoke a method you really need two pointers: one to the
EG> object and another to the method (static methods don't need "this" and
EG> can be used much like C procedures).
EG>
EG> What I do (for itcl 2.0) is use generic c call backs that then use hash
EG> tables which map itcl object names to object instance pointers and, for
EG> each object class, method names to method pointers. This is not particularly
EG> elegant nor efficient (since I'm doing the same hash lookups in my tables
EG> that itcl is doing in its tables) but it does allow me to create "natural"
EG> (ie: inheritable) itcl interfaces to C++ classes in a relatively simple
EG> manner.
EG>
I do something similar: I use the "Handle" extension of TclX to generate
instance names and associate them with Tcl_CreateCommand() with ClientData ==
this pointer value. See my code for Home Librarian and Role Playing database
packages for details. I also have a method for actually implementing the
method functions for the class that is called be a static stub C function than
casts the ClientData pointer to the correct class type and then launches the
Tcl processing method.
EG> >Is there a way to use a class-method as the function-parameter of
EG> >Tcl_CreateCommand ? At the time I use a workaround. I create the command with a
EG> >normal c-function and this c-function calls the method of the object.
EG> >
EG> >================================================================================
EG> > Peter Schartner Royal Holloway | University of Technology
EG> > University of London | Graz, Austria
EG> >
EG> > PGP key available on request
EG> >================================================================================
EG> >
EG>
EG>
EG> --
EG>
EG>
--
\/
http://www.*-*-*.com/ ~heller ||FidoNet: 1:321/153
http://www.*-*-*.com/ ;/\