Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 23bdec52944997938c5d2ac02f4a8acbaf820491
Ticket: 98217d03e0c0032a72590b0f6af71b33d46494c6
Add option to "namespace import" command for importing also variables
User & Date: anonymous on 2015-04-25 20:41:08
Changes

  1. icomment:
    Hi Miguel,
    
    now I am using the next trick. But don't you think that it's more concise something like this "namespace import -variable moduleA::moduleB::moduleC::moduleD::constants"?
    
    This is the trick:
    
    proc import_constants {path_to_constants variable_name args } {
        upvar $variable_name _variable_name
        upvar $path_to_constants _path_to_constants
        
        if { [llength $args] > 0} {
    
    	foreach arg $args {
                set _variable_name($arg)  [dict get $_path_to_constants $arg]
    	}
        } else {
                array set _variable_name $_path_to_constants
        }
    }
    
    
    namespace eval moduleA::moduleB::moduleC::moduleD {		
        variable constants [ dict create {*}{ 
    		constant1 value1
    		constant2 value2
    		constant3 value3
    	}]
    }
    
    import_constants moduleA::moduleB::moduleC::moduleD::constants constants
    
    puts $constants(constant1)
    
  2. login: "anonymous"
  3. mimetype: "text/plain"