Hi Pere, The answer to your 3 questions is to use TMethodCall. A small example: void pere() { // example illustrating the use of TMethodCall void pere() { // example illustrating the use of TMethodCall //create a TMethodCall for the TLine constructor TMethodCall mc,mcdraw; mc.InitWithPrototype(TLine::Class(),"TLine","double,double,double,double"); mcdraw.InitWithPrototype(TLine::Class(),"Draw","const char*"); Long_t l,ldraw; TRandom r; char params[100]; //draw 100 lines for (int i=0;i<100;i++) { sprintf(params,"%f,%f,%f,%f",r.Rndm(),r.Rndm(),r.Rndm(),r.Rndm()); mc.Execute(0,params,l); mcdraw.Execute((TLine*)l," ",ldraw); } } In the InitWithPrototype call, you can specify any complex type: - basic type, - class - pointer, etc to pass a pointer, simply encode the value of the pointer, eg for a TLine* sprintf(params,"(TLine*)0x%x",line); //where line is a TLine* Rene Brun Pere Mato wrote: > > Hi All, > > I am trying to make an exercise of interfacing ROOT with Python using the > API provided by the ROOT Meta classes (TClass, TMethod, TDataMember, etc.) > and I have several questions: > > - How to call a constructor with arguments. The method TClass::New() calls > only the default constructor. I naively tried to call the class constructor > method as a normal method using TObject::Execute(...) immediately after the > object has been created with TClass::New() but it does not seem to work. > > - How to get the return value of a function/method call. The method > TObject::Execute(...) does not give you this possibility. Also the method > TMethodCall::Execute(...) allows only to return either a long, double or a > string but nothing else. > > - How I can pass a "complex" data type as an argument to a method. In > particular, how I can give a TObject* as argument. The way I understand the > method TObject::Execute() works is by constructing a string with comma > separated argument values. In the case of being within the CINT interpreter > it seems that you can pass the name of a CINT variable pointing to your > complex data type. But if you are not in CINT, which is exactly my case I do > not see how I can do it. > > Thanks in advance for any hint or suggestion, > > ------------------------------------------------------------ > Pere Mato CERN, EP Division, CH 1211 Geneva 23, Switzerland > e-mail: Pere.Mato@cern.ch tel: +41 22 76 78696 > fax: +41 22 76 79425 gsm: +41 79 20 10855
This archive was generated by hypermail 2b29 : Sat Jan 04 2003 - 23:50:38 MET