mh_eval Tcl Command

NAME

mh_eval - Evaluate Tcl code

SYNOPSIS

dmh::mh_eval tcl_code


DESCRIPTION

This command is similar to the usual Tcl eval except that it always returns a two element list result. The first element of the list is the Tcl error code obtained from executing the tcl_code. The second element of the list is the usual result of execution. If called with the correct number of arguments, mh_eval will not return an error. For example:

mh_eval "set pi 3.1415"
0 3.1415

mh_eval "an error" 1 {invalid command name "an" while executing "an error"}

The command is typically used during interprocess communication with other Tcl applications. The command makes it easy to support the functionality of Remote Procedure Calls with an asynchronous messaging system such as the Distributed Message Hub from Hume Integration Software. The mbx_RPC command is an example.

The tcl_code argument is executed at the topmost global level. You do not need to declare references to data items as global, but at the same time, you need to be careful about littering your application with unintended global data items, or creating subtle errors from accessing the same data items in multiple usages.

The command is found in the ::dmh namespace. During initialization of the dmh package, the command is imported into the global namespace for compatibility with the inspect application unless the environment variable NO_DDE_IMPORT is set.

This command is nearly equivalent to:

proc mh_eval {msg} {
    set rc [catch [concat uplevel #0 [list $msg]] result]
    return [list $rc $result] 
    }
However, the compiled version provides better performance, and a complete stack backtrace in the event of an error result.

SEE ALSO

catchmbx_RPCsenduplevel

AUTHOR

Ed Hume, Hume Integration Software

KEYWORDS

RPC, evaluate