Revision: 10476 http://pure-data.svn.sourceforge.net/pure-data/?rev=10476&view=rev Author: eighthave Date: 2009-01-06 18:08:40 +0000 (Tue, 06 Jan 2009)
Log Message: ----------- now 'pd-gui' can handle commands from 'pd' that have \n in them. this technique has promise for handling other errors as well, since the Tcl catch is already there
Modified Paths: -------------- branches/pd-devel/0.41.4/src/pd.tk branches/pd-devel/0.41.4/src/pd_connect.tcl
Modified: branches/pd-devel/0.41.4/src/pd.tk =================================================================== --- branches/pd-devel/0.41.4/src/pd.tk 2009-01-06 05:05:36 UTC (rev 10475) +++ branches/pd-devel/0.41.4/src/pd.tk 2009-01-06 18:08:40 UTC (rev 10476) @@ -17,6 +17,7 @@ package require pd_menus package require pd_bindings
+# import 'pd' into the global namespace for backwards compatibility namespace import ::pd_connect::pd
# ------------------------------------------------------------------------------
Modified: branches/pd-devel/0.41.4/src/pd_connect.tcl =================================================================== --- branches/pd-devel/0.41.4/src/pd_connect.tcl 2009-01-06 05:05:36 UTC (rev 10475) +++ branches/pd-devel/0.41.4/src/pd_connect.tcl 2009-01-06 18:08:40 UTC (rev 10476) @@ -10,15 +10,15 @@
proc ::pd_connect::connect_to_pd {portnumber} { variable pd_socket - puts stderr "Connecting to 127.0.0.1 $portnumber ..." - if {[catch {set pd_socket [socket 127.0.0.1 $portnumber]}]} { + puts stderr "Connecting to localhost $portnumber ..." + if {[catch {set pd_socket [socket localhost $portnumber]}]} { puts stderr "WARNING: connect to pd failed, retrying port $portnumber." after 1000 ::pd_connect::connect_to_pd $portnumber return } puts stderr "Connected to pd on port $portnumber" fconfigure $pd_socket -blocking 1 -buffering line - fileevent $pd_socket readable [list pd_readsocket $::pd_connect::pd_socket] + fileevent $pd_socket readable [list ::pd_connect::pd_readsocket ""] }
# send a message from Tcl to Pd @@ -30,9 +30,21 @@
# figure out which namespace the eval is using... this probably needs to be # global so that eval runs in the global namespace -proc pd_readsocket {pd_socket} { - set cmd_from_pd [gets $pd_socket] - puts stderr "cmd_from_pd $cmd_from_pd" - eval $cmd_from_pd -# eval [gets $pd_socket] +proc ::pd_connect::pd_readsocket {cmd_from_pd} { + variable pd_socket + if {$cmd_from_pd == ""} {puts stderr "called with blank args aka READABLE"} + append cmd_from_pd [gets $pd_socket] + puts stderr "cmd_from_pd: $cmd_from_pd" + if {[catch {uplevel #0 $cmd_from_pd}]} { + global errorInfo + puts stderr "errorInfo <<$errorInfo>>" + if {[regexp -line -- "^missing close-brace.*" $errorInfo]} { + # TODO consider using [info complete $cmd_from_pd] in a loop + puts stderr "appending another line" + pd_readsocket $cmd_from_pd + } else { + #puts stderr "DIFFERENT ERROR on eval: $errorInfo" + puts stderr "DIFFERENT ERROR on eval" + } + } }
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.