mh_eval Tcl Command

NAME

mh_eval - Evaluate Tcl code

SYNOPSIS

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.

This command is nearly equivalent to:

proc mh_eval {msg} {
    set rc [catch [concat uplevel #0 $msg] result]
    return [list $rc $result] 
    }
However, the above Tcl procedure does not properly handle arguments in msg that are lists.

SEE ALSO

eval, global, mbx_RPC, send

AUTHOR

Ed Hume, Hume Integration Software

KEYWORDS

RPC, evaluate