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:

  1. 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?

  2. is ($name - dutport) creating array index variable smbinfo , value of $dutport being set particular array variable?

  3. 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.

  1. the second declaration doesn't override, it's same variable in both cases.
  2. 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).
  3. 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

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -