[tcljava-user] TclBlend issue with uplevel in proc
Brought to you by:
mdejong
From: Dan D. <dda...@ya...> - 2011-05-26 18:08:17
|
Can anyone explain why TclBlend is not holding on to the Java object when I use uplevel in a proc? And what I can do to work around it. package require java proc execute { args } { #puts "Executing: $args" <-- COMMENTED OR NOT COMMENTED # execute the command if {[catch { set ret [uplevel #0 $args] } errmsg]} { return "ERROR:[lindex [split $errmsg "\n"] 0]" } else { puts "Executed: $args" return "SUCCESS:$ret" } } With the puts executing line commented out in works: % execute set x [java::new String] SUCCESS:java0x2 % puts $x java0x2 % java::info class $x java.lang.String % With the puts executing line enabled: % execute set x [java::new String] Executing: set x java0x4 Executed: set x java0x4 SUCCESS:java0x4 % puts $x java0x4 % java::info class $x unknown java object "java0x4" % Is this because the [java::new String] actually executes before entering the execute function and if it is not immediately set to a variable in the next command, it will be released? My real script does something a little more complicated, reading the command(s) to be executed via a socket. This was the simplest example that demonstrates the problem. |