On Fri, 14 Apr 2000, Paul Eng wrote:

> I am looking into using Jacl to call Tcl scripts.  I can call interp.eval()
> and then interp.getResult() to get the return value, but the return value is
> a TclObject.  What I would like to do is convert this TclObject result into
> it's appropriate java object, so that if it's a reflected object, I would
> get the java object, if it's a TclString, I would get java.lang.String, etc.
> 
> I found the convertTclObject() method in JavaInvoke which looks like what I
> want, but the method is not public.  Is there a way I can do this or am I
> missing something?
> 
> Thanks,
> Paul Eng

The "trick" here is that Tcl objects have "internal representations",
that could be a float, a Java object, or whatever. Because a Tcl
object is a "wrapper" around an InternalRep, you need to "unwrap"
the TclObject in you Java code if you want to do something with it.
Lets say you invoke a Tcl proc that does some Java related stuff,
it sets the interp result to a ReflectObject, a Tcl "wrapper" for
a Java object.

interp.eval("some_java_func");

Now you can "unwrap" the Java object like so.

TclObject result = interp.getResult();

Object jobj = ReflectObject.get(interp, result);

If you want to know what the Java Class of the reflected
Java object is, you can find that out like this.

Class jcl = ReflectObject.getClass(interp, result);

(WARNING: YOU MUST GET THE REFLECTED CLASS TYPE LIKE THIS,
DO NOT CALL THE jobj.getClass() METHOD TO GET THE
REFLECTED CLASS TYPE, THEY ARE NOT THE SAME THINGS).

To get the "string rep" of a TclObject just call the
toString() method on the TclObject.

I hope that helps.
Mo Dejong
Red Hat Inc.

----------------------------------------------------------------
The TclJava mailing list is sponsored by Scriptics Corporation.
To subscribe:    send mail to [EMAIL PROTECTED]  
                 with the word SUBSCRIBE as the subject.
To unsubscribe:  send mail to [EMAIL PROTECTED] 
                 with the word UNSUBSCRIBE as the subject.
To send to the list, send email to '[EMAIL PROTECTED]'. 
An archive is available at http://www.mail-archive.com/tcljava@scriptics.com

Reply via email to