Re: [tcljava-user] TclBlend issue with uplevel in proc
Brought to you by:
mdejong
From: Mo D. <mo...@mo...> - 2011-05-26 18:22:17
|
The most likely cause of the problem is that you are expecting "x" to get set at the global scope, but by the time the set command is executed at the global scope, the internal rep is losing the Java representation. The most simple way to work around this would be to set a specific variable to the Java object, and then in the uplevel you reference that variable instead of passing the value to uplevel. Something like this: set ::GObj [java::new String] execute {set x $GObj} Mo On May 26, 2011, at 11:08 AM, Dan Diolosa wrote: > 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. > > > ------------------------------------------------------------------------------ > vRanger cuts backup time in half-while increasing security. > With the market-leading solution for virtual backup and recovery, > you get blazing-fast, flexible, and affordable data protection. > Download your free trial now. > http://p.sf.net/sfu/quest-d2dcopy1_______________________________________________ > tcljava-user mailing list > tcl...@li... > https://lists.sourceforge.net/lists/listinfo/tcljava-user |