Understanding the use of Tcl namespace variable -
i have namespace variable defined below:
namespace eval ::smb::{ variable smbinfo ------ ------ proc ::smb::smbcreate {name dutport} { variable smbinfo global dutports dutport_2 dutports_3 smb ------ ------ if{"" != [info command smb::$name]} { return -code error "command name \"$name\" exists" } set smbinfo($name -dutport) $dutport
i new tcl , trying understand above piece of code. few questions, please correct me if wrong @ point:
the variable smbinfo defined on top in namespace getting overridden 1 declared in procedure smbcreate. unable figure out objective of line:
set smbinfo($name -dutport) $dutport
i can see 'dutports' defined global not find 'dutport'. have not executed code yet. error?
is ($name - dutport) creating array index variable smbinfo , value of $dutport being set particular array variable?
i have similar code structures in file below
set smbinfo($name - smbsetdmac) [buildmac1 $smbinfo($from_name-dutport)]
where buildmac1 procedure. bit explanation of above code might make thing clear.
if missed post in question, kindly point me, edit question. in advance.
- the second declaration doesn't override, it's same variable in both cases.
- the command syntax error because of space after $name. intent seems to assign value of $dutport member of smbinfo has name "$name -dutport" (where $name replaced variable value).
- a similar assignment, here value comes result of command.
there few syntax errors in code, many or few spaces here , there. seems unlikely code has ever been executed.
the purpose of smb::smbcreate command seem to 1) create new command in smb namespace named first parameter (unless such command exists) , 2) store metadata in smbinfo namespace variable, indexed a) name parameter , b) keyword such -dutport or -smbsetdmac.
code implements ad-hoc object-oriented interface. if whitespace issues resolved, should work fine.
Comments
Post a Comment