Reputation: 49
I want to rename or delete namespace in tcl, can anyone tell me how to do it?
rename gk ""
Here gk is the namespace
Upvotes: 0
Views: 223
Reputation: 11
Maybe this approach offers a solution. Where ns1 is the source namespace, and ns2 the destination.
proc xxxx {ns1 ns2} {
namespace eval ::${ns2} {}
set map [list $ns1 $ns2]
foreach type {commands vars procs } {
foreach item [info $type ${ns1}::*] {
set err ""
catch { rename $item [string map $map $item] } err
if { $err != "" } { puts $err }
}
}
namespace delete $ns1
}
Upvotes: 0
Reputation: 1
Use this proc to rename any given namespace:
proc renameNameSpace {oldNameSpace newNameSpace} {
foreach proc [info procs ::${oldNameSpace}::*] {
rename $proc ::${newNameSpace}::[lindex [split $proc ::] end]
}
}
Upvotes: 0
Reputation: 40783
I don't know of any way to rename an existing namespace. To delete a namespace:
namespace delete namespace_name
All the child namespaces, proc, vars within the namespace will be deleted as the result of this call.
Upvotes: 2