TclBlend is very close to accomplish the task of using Tcl from a Java application. TclBlend provides the ability to call TCL commands from Java, and call Java methods from TCL. I am also trying to do a similar set up for my project at work. In my setup, I want to embed the native TCL core into a Java based application server process. I had to write a patch to the TclBlend code to make this possible. After patching the TclBlend code, I was able to write a tclsh like program using Java. The shell drives the native Tcl interpreter using a Java thread. The Java based shell is able to run and pass almost the same set of tests in the Tcl core test suite as the regular C based "tclsh.exe". My simple Java based shell lacks the ability to take in command line arguments so some of the tests failed. The Java based shell can also run all tests in the "tcljava" tests and "tclblend" tests in the TclBlend/Jacl suite. Originally, I had wanted to use the same tcl.lang.Shell in Jacl, but use a native Tcl engine to do the Tcl work. If that worked, then you can have the same Java code for using Jacl. But when you need to access some TCL functions that are not available in Jacl, you can switch to TclBlend. But I ran into a few problems. 1. tcl.lang.Interp methods for TclBlend cannot be called directly by any threads other than the one running its event loop. The Jacl Shell's console thread actually makes call to the tcl.lang.Interp.commandComplete() method. If using TclBlend, this call will block. In TclBlend, the console thread would need to create a TclEvent to execute the tcl.lang.Interp.commandComplete(). Alternatively, TclBlend can allow other threads to call its commandComplete() method. But I don't know if the native Tcl interpreter's Tcl_CommandComplete() function can be called this way or not. 2. Jacl's Shell sets some variables in the interpreter using Java Strings, such as interp.setVar("argv0", "tcl.lang.Shell", TCL.GLOBAL_ONLY); In TclBlend, the Java String cannot be used directly for the value of the variable. The value "tcl.lang.Shell" needs to be wrapped into a TclObject first. This can be fixed in the TclBlend source code to add another "setVar" method that matches the one in Jacl. 3. In the Jacl Shell, the console thread waits for the event to finish processing using a TclEvent.sync(). Afterward, the console thread extracts the data from the Interpreter on any exception or eval results. In TclBlend, this will block because the console thread would be making calls to the tcl.lang.Interp object. But the console thread is not the thread driving the tcl.lang.Interp object's event loop. This is a similar problem as #1. After seeing these problems, I didn't go further trying to make the Jacl shell work with TclBlend. Overall, the TclBlend stuff looks fairly good. However, to use it in a Java program, one has to know its idiosyncrasies. Due to multi-threaded nature of any Java application, one would need to write a wrapper layer on top of TclBlend to hide the fact that many class methods in TclBlend are not thread safe. The wrapper layer will be thread safe and delegate the work to TclBlend. For example, I would probably write a TclInterp class to wrap around the tcl.lang.Interp so that any thread can call TclInterp.completeCommand() which: 1. queue a TclEvent to execute tcl.lang.Interp.completeCommand() and extract the result 2. call TclEvent.sync() to wait for the result 3. return the result back to the caller of TclInterp.completeCommand(). TclInterp will be implemented such that any thread can call its method. -- Jiang Wu [EMAIL PROTECTED] -----Original Message----- From: Ian F. Graham [mailto:[EMAIL PROTECTED]] Sent: Thursday, March 16, 2000 1:47 AM To: Mo DeJong Cc: [EMAIL PROTECTED] Subject: [Tcl Java] RE: [Tcl Java] tclBlend: pyramidpkg possible path problem ? Maybe you (or someone in the list) give me some pointers on my problem. I have a large tcl app with an exported set of tcl commands. Some of these are implement in C, others are pure tcl procs (dependent on the level of access required by the user). What I need to do is provide an interface to this from Java. The first thought is JNI, but that excludes the commands written in Tcl, so that is where TclBlend comes in (I think). Can you confirm that my approach is correct and if not give me some pointers ? Thanks for the help, Ian ---------------------------------------------------------------- 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