>Hello ROOTers,
>
>I want to embed the CINT interpreter into an application. This app
>needs to evaluate return values of script functions in C++. If I call
>the G__calc() function, the return value works for int or double, but
>I could not interprete the value for structures or objects.
>
>Any help?
>
>Regards,
It depends whther you use G__calc() from the interpreter or in a precompiled
code.
Using G__calc() in the interpreter, it will properly return struct or class
object. For example, if you interpret following code, a2 is correctly a copy
of a1.
class A {
public:
int a;
double d;
}
main() {
A a1,a2;
a1.a=123; a1.d=3.14;
a2=G__calc("a1");
}
Using G__calc() in a precompiled code make a little difference. G__calc()
returns an object of G__value which is defined in $CINTSYSDIR/G__ci.h.
You can use G__int() and G__double() to converto G__value to long or double.
In case of struct and class object, you will get pointer to the returned
object as follows.
A *p;
p=(A*)G__int(G__calc("a1"));
Note that a1 must be registered in the interpreter's dictionary. To test
type of "a1", you can use G__ClassInfo class.
#include "G__ci.h" // need -I$CINTSYSDIR
#include "src/Api.h"
f() {
A *p;
G__value v=G__calc("a1");
G__ClassInfo cls(v.tagnum);
if(strcmp(cls.Name(),"A")==0) p=(A*)G__int(v);
else p=(A*)NULL; // a1 is not type of A
}
Masaharu Goto