Version 2 of Breakpoints in Tcl

Updated 2014-05-05 21:52:57 by AMG

On facebook someone asked "how do you stop tcl script at a particular line"

The quickest way, if you know the line is (immediately before that line):

error "I have to stop here"

But if you are looking for something a little more elegant, create a proc which tells Tcl to enter the event loop, and stay there until a condition has been satisfied. In this case we will assume our program is running from a command line, and we want to prompt the user to press any key to continue.

proc breakpoint {} { 
  update
  set ::breakpoint 0
  puts stdout "Press <Any Key> to continue"
  fileevent stdin readable {set ::breakpoint 1}
  vwait ::breakpoint
}

For a tk based application:

proc breakpoint {} { 
  update
  tk_messageBox -type ok -message "Press OK to continue"
}