[vtkusers] Questions on wrapping a C++ library for use in VTK Scripting (eg. TCL)

Prabhu Ramachandran prabhu at aero.iitm.ernet.in
Fri Oct 25 09:05:06 EDT 2002


Hi,

>>>>> "MN" == Markus Neff <markus at noodle.med.yale.edu> writes:

    MN> 1. Is there a way of automatically wrapping C++ exceptions to
    MN> the corresponding exception mechanisms of TCL / JAVA /Python
    MN> etc. ?  If there is no such thing (I guess there is nothing
    MN> like that by now) what would be the best way to provide
    MN> sophisticated error handling facilities to the script writers
    MN> ?
   
SWIG support for wrapping C++ has improved by leaps and bounds in the
last year or so.  It now supports a huge range of things.  I think it
supports C++ exceptions too.  boost.python also supports exceptions
from C++ but it will work only for Python.

    MN> 2. Is there support for automatically wrapping "std::string"
    MN> or "std::vector" arguments in C++ class-methods ?

I think SWIG can handle this, so can boost.  Essentially yes you can
do it.  However, I am not sure its easy to do from within VTK's
wrapping mechanism.
   
    MN> 3. Has someone ever used SWIG together with VTK and some
    MN> scripting language (because it seams to support some of the
    MN> features I am asking about) ?
   
I'm not sure -- thus far no one seems to have responded to this so I
am guessing.  Anyway a week or so back I mailed the list some code on
how to get the VTK C++ object from Python into a C++ function.  Surely
something similar must be there for the Tcl and Java wrappers but I am
not sure and have not looked.  Under Python I think it should be
fairly easy to use SWIG along with the VTK wrappers to do what you
need to do.  Again, I'm only talking about the Python side of things.
I do not know about the other wrappers.
   
    MN> 4. Is it possible to pass out multiple strings to the
    MN> scripting languages with just one call similar to the
    MN> following C++ code:

    MN>    void passOutTwoStrings(std::string& string1, std::string&
    MN> string2) { string1 = std::string( "one" ); string2 =
    MN> std::string( "two" ); }
   
I think this should be possible with boost.python and SWIG.  I havent
done it but am fairly confident that it should be possible.  Even if
its not possible the way you want it there will be a way to pass
strings from the scripted language to Python/Tcl/Java.
   
I am not sure how you want to do the wrapping yet.  If you want to
write code by hand to wrap your classes pretty much anything should be
possible.  If you want to use another tool maybe Cable (as Ken
mentioned) or SWIG would be a good idea.

cheers,
prabhu



More information about the vtkusers mailing list