Re: retrieving line number in case of error - "simple debugger"



Nicolas Castagne wrote:
Tcl is widely used to let end-users write scripts that impact a big C/C++ application.
I myself currently develop a sort of modeler for physical models, that will involve both a GUI and a Tcl-based end-user language.


The Tcl-based language will let the user decribe the model, by calling C routine that will build the model in memory (hope it is clear enough).
The scripts will be written within a text canvas holded by the GUI, and interpreted through a TclInterp ran by the GUI.

In such a case, you have complete control over the execution of the code. You can, for instance, tell the user which line of the user-entered script has an error with something like this:


set script [.text get 1.0 end-1c]
set lineno 0
foreach line [split $script \n] {
    if {![info exists command]} {
        set command $line
    } else {
        append command \n $line
    }
    incr lineno
    if {[info complete $command]} {
        if {[catch $command err]} {
            puts "error on line $lineno: $err"
        }
        unset command
    }
}

That isn't precise, but it gives you a rough idea.

With a bit more code you can highlight the code in the text widget that is about to be executed, and have buttons on a toolbar that cause the code to be executed or stepped over, one line at a time.

So, perhaps the answer to your question is "info complete" and "catch". That is, you can use [info complete] to know if a line or lines of user-entered text is a complete command, and "catch" to execute the command and to retrieve the result.
.



Quantcast