On Tue, 10 Aug 1999 [EMAIL PROTECTED] wrote:
> Hey folks,
>
> After many hours of wandering around the JACL html files, I'm
> beginning to conclude that JACL just wasn't designed to do what I'm
> trying to do. Maybe I'm trying to do something too weird (this seems
> to be a tendency I have with languages I encounter :-().
Humm, this sounds like something that Jacl would be good at.
> I'm trying to have my java program at one point pass a structure
> of vectors about four levels deep into a TCL script, and have the
> script iterate over the vector and do some sorting and sifting. It
> should remove objects from the vector, and pass the resulting values
> back out if necessary; perhaps it could just act on the the objects
> referenced and there's no need to pass it values. The purpose of this
> is to allow maximum tweaking of the sorting/sifting/transforming by
> end-users.
You would use the tcl.lang.ReflectObject class to "reflect" the Java
objects in the interp. This means a Java object reference would be
seen in the interp as a command (like java0x1). What you are trying to
do is not strange at all. In fact, I have done just this sort of
thing in my Tcl + Java Media Framework package. I have attached a
file call "TclJavaGlue.java", which is an example created by another
Tcl/Java user that demonstrates the use of the
interp.getNotifier().queueEvent() method. This method should be used from
Java code to invoke methods in a running Tcl interp. The main point is
that you need to create a "callback wrapper" class that is used by the
interp to actually do the eval in a thread safe way. You would want to
do any setup (like reflecting your Java object references)
inside this callback before actually calling interp.eval().
> None of the JACL docs seem to address how to pass java object
> references into an interp script. I understand why; most of them were
> written with the idea of using JACL to glue java objects otgether, or
> using Java objects to extend TCL commands. Is what I'm trying to do
> feasible?
Well, you could define and call a proc with every eval, but that would
be slower that defining the proc before hand and then just calling
interp.eval("proc args"). Perhaps I am not understanding what you
are saying.
> I'm planning to load the TCL source into a java string variable
> (or set of variables), and keep them around to reduce the overhead of
> setting up new interp objects for each request. I'm thinking each
> TCL script would be eval'd by the interp to set up a specific command
> proc. If I understand this properly, the script file should be simply
> a TCL proc definition that I submit to interp.eval().
I think you might want to do something like this. Just keep in mind that
this example does not use the thread safe stuff mentioned above.
Interp interp = new Interp();
interp.pkgRequire("java", null, false);
String my_tcl_setup_code = "...";
interp.eval(my_tcl_setup_code);
Object obj = new Object(); // the Java object to reflect
TclObject ref_obj =
ReflectObject.newInstance(interp, Object.class, obj);
interp.setVar("REFLECTED_OBJECT", ref_obj, 0);
interp.eval("my_proc");
When my_proc is eval'ed a the global variable REFLECTED_OBJECT will be
a reference to the Java Object from your Java code.
I hope that helps
Mo
> I get as far as instantiating the interp object, but I'm drawing
> a blank on how to pass the data in and get the results out. (not to
> mention writing the actual TCL for the initial implementation, but
> that should be straightfoward; most of it is stuff like "remove the
> top of any branch that has a certain value in one of the
> subbranches").
>
> Can somebody send me a short step-by-step tutorial or suggestions?
>
>
> Steven J. Owens
> [EMAIL PROTECTED]
> [EMAIL PROTECTED]
>
> ----------------------------------------------------------------
> The TclJava mailing list is sponsored by WebNet Technologies.
> 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]'.
> A list archive is at: http://www.findmail.com/listsaver/tcldallas/
>
----------------------------------------------------------------
The TclJava mailing list is sponsored by WebNet Technologies.
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]'.
A list archive is at: http://www.findmail.com/listsaver/tcldallas/