Lubos Vrba wrote:

> Thanks for advice, but I just don't know how use it.
> May be I definition of my problem was pure. I'll try to do it better:
> In next.tcl isn't only one puts commands!

i hope :-)

> I don't want tcl script print some messages!

ok, but i suppose you want to retrieve some value returned by your script
next.tcl?

> I dont want to use some procedures in tcl (if it's possible).

I dont know how to do it without proc ...

> I don't know how to use getResult().toString(), it still returns nothing!

here is the sources i am using (in which getResult().toString() returns
something):

the shell in java:

   [...]
  // start shell interpretation
  while(!theCommand.equals("exit")) {
   System.out.print("> ");

    // try to readln the command typed
   try {
    StringBuffer theLineRead = new StringBuffer(
     (new BufferedReader(new InputStreamReader(System.in))).readLine()
    );
    theCommand = theLineRead.toString();
   } catch (IOException e ){
    e.printStackTrace();
   }

   // try to evaluate command read
   try {
    theInterpretor.eval(theCommand);
    System.out.println("returned value = '"+
theInterpretor.getResult().toString() + "'");
   } catch (TclException e) {
    e.printStackTrace();
   }
 }
[...]

if you use a shell interpreting like that, you can type:
> puts foo
foo
returned value = ''
> return foo
tcl.lang.TclException
        at tcl.lang.ReturnCmd.cmdProc(ReturnCmd.java:99)
        at tcl.lang.Parser.evalObjv(Parser.java:740)
        at tcl.lang.Parser.eval2(Parser.java:1138)
        at tcl.lang.Parser.evalTokens(Parser.java:930)
        at tcl.lang.Parser.eval2(Parser.java:1125)
        at tcl.lang.Interp.eval(Interp.java:1781)
        at tcl.lang.Interp.eval(Interp.java:1810)
        at com.odisei.application.tcl.ShellTcl.<init>(ShellTcl.java:87)
        at com.odisei.application.tcl.ShellTcl.main(ShellTcl.java:34)
> proc bar {} {return foo}

returned value = ''
> bar
foo
returned value = 'foo'
>

I don't know if it helps you, but i means :
- puts do not set the result of the interpretor, it simply prints something on
stdout (then its not interesting)
- retrurn can not be used outside a proc
- if a proc return something, the returned value can be retrieved using
interp.getResult() (then you have to use a proc!)

conclusion, if you want to get a value evaluated by a script, you should write
next.tcl like that:
----------------------------
proc myProc {parameters} {
    evalutate whateverYouWant
    return theEvaluatedValue
}
myProc {"foo" "bar"}
----------------------------
write in your java shell implementation

theInterpretor.eval("source next.tcl");
System.out.println("returned value = '"+ theInterpretor.getResult().toString()
+ "'");

and you will get the value evaluated by your script. i hope this is a solution
to your problem.

philippe - france




----------------------------------------------------------------
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/

Reply via email to