Thread: [tcljava-user] How to use Interp.setResult?
Brought to you by:
mdejong
From: Bret C. W. <bc...@ya...> - 2009-03-03 02:16:59
|
Hello, I have not found good documentation for some of Jacl - the API docs on the tcljava.sourceforge.net site are not giving me a good enough understanding to determine how to solve an exception. I have a command-line java program. In it's primary class constructor, it creates a TCL Interp session with the name of an external script file, and exits when the Interp session is complete. In response to various commands found in a script, various Java objects are created, and methods called on those objects from the script. I have a number of working examples of this, including some that successfully return values to the Interp session for further processing. But I haven't figured out what Interp.setResult() does, and it looks as if it might be useful. Consider these two methods. The first (getColumnCount) works as expected, and I can access the return value in my script. The second (getEntry) always provokes the exception listed below. 'myInterp' was set with a reference to the (one-and-only) Interp session when the object these methods belong to was created and is valid for the entire time. Please don't tell me to read the docs, I have and have tried many experiments and they don't tell me what circumstance to use the Interp.setResult() method in or what might be the problem here. Thanks in advance, bcw TCL: $tableName getEntry $column $row Java: /** * *@return* int - The number of columns in this result set. */ *public* *int* getColumnCount() { log.debug( "getColumnCount - columnCount is " + columnCount ); *return* columnCount; } *public* *void* getEntry( String columnName, *int* currentRow ) *throws* TclException { log.debug( "getEntry - column name is " + columnName ); myInterp.setResult( "an Answer" ); } tcl.lang.ReflectException at tcl.lang.JavaInvoke.call(JavaInvoke.java:328) at tcl.lang.JavaInvoke.callMethod(JavaInvoke.java:161) at tcl.lang.ReflectObject.cmdProc(ReflectObject.java:916) at tcl.lang.Parser.evalObjv(Parser.java:826) at tcl.lang.Parser.eval2(Parser.java:1228) at tcl.lang.Parser.evalTokens(Parser.java:1008) at tcl.lang.Parser.eval2(Parser.java:1215) at tcl.lang.Procedure.cmdProc(Procedure.java:174) at tcl.lang.Parser.evalObjv(Parser.java:826) at tcl.lang.Parser.eval2(Parser.java:1228) at tcl.lang.Parser.evalTokens(Parser.java:1008) at tcl.lang.Parser.eval2(Parser.java:1215) at tcl.lang.Interp.eval(Interp.java:2679) at tcl.lang.Interp.eval(Interp.java:2747) at tcl.lang.IfCmd.cmdProc(IfCmd.java:64) at tcl.lang.Parser.evalObjv(Parser.java:826) at tcl.lang.Parser.eval2(Parser.java:1228) at tcl.lang.Interp.eval(Interp.java:2679) at tcl.lang.Interp.eval(Interp.java:2747) at tcl.lang.ForeachCmd.cmdProc(ForeachCmd.java:98) at tcl.lang.Parser.evalObjv(Parser.java:826) at tcl.lang.Parser.eval2(Parser.java:1228) at tcl.lang.Interp.eval(Interp.java:2679) at tcl.lang.Interp.eval(Interp.java:2747) at tcl.lang.WhileCmd.cmdProc(WhileCmd.java:43) at tcl.lang.AutoloadStub.cmdProc(Extension.java:119) at tcl.lang.Parser.evalObjv(Parser.java:826) at tcl.lang.Parser.eval2(Parser.java:1228) at tcl.lang.Procedure.cmdProc(Procedure.java:174) at tcl.lang.Parser.evalObjv(Parser.java:826) at tcl.lang.Parser.eval2(Parser.java:1228) at tcl.lang.Parser.evalTokens(Parser.java:1008) at tcl.lang.Parser.eval2(Parser.java:1215) at tcl.lang.Interp.eval(Interp.java:2679) at tcl.lang.Interp.evalFile(Interp.java:2940) at com.ssg.dataconverter.DataConverter.<init>(DataConverter.java:76) at com.ssg.dataconverter.DataConverter.main(DataConverter.java:159) |
From: Mo D. <mo...@mo...> - 2009-04-14 18:02:19
|
Bret Comstock Waldow wrote: > Hello, > > I have not found good documentation for some of Jacl - the API docs on > the tcljava.sourceforge.net site are not giving me a good enough > understanding to determine how to solve an exception. > > I have a command-line java program. In it's primary class constructor, > it creates a TCL Interp session with the name of an external script > file, and exits when the Interp session is complete. In response to > various commands found in a script, various Java objects are created, > and methods called on those objects from the script. I have a number of > working examples of this, including some that successfully return values > to the Interp session for further processing. > > But I haven't figured out what Interp.setResult() does, and it looks as > if it might be useful. The setResult() method sets the "result" pointer in a Jacl interpreter to a specific TclObject. It is typically used from a Java implementation of a Tcl method to indicate the result of a Tcl command. If you have a Java method, it is better to just have it return a Java result and then invoke the method with the java::call command or from a class instance handle (like java0x1, a result object from a java::new command). > TCL: > $tableName getEntry $column $row > > Java: > /** > * *@return* int - The number of columns in this result set. > */ > *public* *int* getColumnCount() > { > log.debug( "getColumnCount - columnCount is " + columnCount ); > *return* columnCount; > } > > *public* *void* getEntry( String columnName, *int* currentRow ) > *throws* TclException > { > log.debug( "getEntry - column name is " + columnName ); > myInterp.setResult( "an Answer" ); > } > > > tcl.lang.ReflectException > at tcl.lang.JavaInvoke.call(JavaInvoke.java:328) > at tcl.lang.JavaInvoke.callMethod(JavaInvoke.java:161) > at tcl.lang.ReflectObject.cmdProc(ReflectObject.java:916) > It is not clear what if going on from this example code and stack trace. Typically, the ReflectException means there was some error in the Java code and it got wrapped into a ReflectException when moving from Java back to tcl. When Jacl hits a ReflectException, it saves the original Java exception object and a description string are saved in the global variable named "errorCode". Printing out a stace trace of the Java exception found there would likely be a good place to start. Mo DeJong |