For Programmers: Free Programming Magazines  


Home > Archive > Tcl > May 2006 > Re: How does the Tcl interpret handle results returned from C-created Tcl commands ?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: How does the Tcl interpret handle results returned from C-created Tcl commands ?
Aric Bills

2006-05-25, 4:15 am

When writing Tcl commands in C, you need to make a distinction between
the "status code" and the return value. Ironically, you provide the
status code with the [return] command, and you provide the return value
with Tcl_SetObjResult, Tcl_AppendResult, or some other such command.

I can see where you're going with your code; if you want to go that
route, you should do something like this:

if {[catch {check_hist_aint_option}]} {
# deal with the error
} else {
# proceed as normal
}

Another alternative is to return TCL_OK as the status code in either
case, and return true or false as the result. Something like:

if (can_do_histogram) {
Tcl_SetObjResult(interp, Tcl_NewBooleanObj(1));
} else {
Tcl_SetObjResult(interp, Tcl_NewBooleanObj(0));
}
return TCL_OK;

Your Tcl code can then go like this:

if {[check_hist_aint_option]} {
# proceed with histogram
} else {
# give negative feedback
}

Does that help?

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com