| Register | FAQ | Calendar | Search | Today's Posts | Mark Forums Read |
|
#1
| |||
| |||
| Hi, all. I encounter the following issue when using tcllib record func: package require struct::record namespace import ::struct::record::* record define sw { name version } record define host { name ip {record sw new_sw} } sw msn_messenger msn_messenger configure -name "msn live messenger" -version "9.0.0" host pc pc configure -name "www.google.com" -ip "10.x.x.x" -sw msn_messenger here, it doesn't work. pc cget -name "www.google.com" -ip "10.x.x.x" -sw {-name {} -version {}} msn_messenger failed to pass its value into instance pc. any one knows how to fix it? i tried -sw [msn_messenger cget] doesn't work. i know it works in this way: pc.sw.name="msn live messenger" pc.sw.version="9.0.0" i am wandering if there's any other way i can seperate info , pass through reference thanks Jarod ZZ |
|
#2
| |||
| |||
| At 2008-08-20 10:50PM, "jarodzz" wrote: > Hi, all. > > I encounter the following issue when using tcllib record func: > > package require struct::record > namespace import ::struct::record::* > > record define sw { > name > version > } > > record define host { > name > ip > {record sw new_sw} > } > > > sw msn_messenger > msn_messenger configure -name "msn live messenger" -version "9.0.0" > > host pc > pc configure -name "www.google.com" -ip "10.x.x.x" -sw msn_messenger > > here, it doesn't work. > > pc cget > -name "www.google.com" -ip "10.x.x.x" -sw {-name {} -version {}} > > msn_messenger failed to pass its value into instance pc. > > any one knows how to fix it? > > i tried -sw [msn_messenger cget] doesn't work. > i know it works in this way: > pc.sw.name="msn live messenger" > pc.sw.version="9.0.0" I see no-one's replies yet. So unless you've figured it out, read on... First of all, you have to use: pc configure ... -new_sw... ^^^^^^ because that's how you've defined your host record. Unless the maintainers of struct::record are willing to fix it, you can't just pass in the name of an existing sub-record -- Tcl by itself has no way to tell that "msn_messenger" is just a string or an existing object name. You have to extract the fields of the sub-records manually. Using tcl 8.5, you can do: pc configure \ -name "www.google.com" \ -ip "10.x.x.x" \ {*}[string map {- -new_sw.} [msn_messenger show]] Using tcl 8.4, you need [eva] -- http://wiki.tcl.tk/1017 I would abstract this into a proc: proc create_host_record {inst_name name ip new_sw_inst} { set inst [::host $inst_name] $inst configure -name $name -ip $ip foreach member [record show members sw] { $inst configure -new_sw.$member [$new_sw_inst cget -$member] } return $inst } create_host_record pc www.google.com 10.x.x.x msn_messenger -- Glenn Jackman Write a wise saying and your name will live forever. -- Anonymous |
|
#3
| |||
| |||
| On Aug 25, 9:56 am, Glenn Jackman <gle...@ncf.ca> wrote: > At 2008-08-20 10:50PM, "jarodzz" wrote: > > > > > Hi, all. > > > I encounter the following issue when using tcllib record func: > > > package require struct::record > > namespace import ::struct::record::* > > > record define sw { > > name > > version > > } > > > record define host { > > name > > ip > > {record sw new_sw} > > } > > > sw msn_messenger > > msn_messenger configure -name "msn live messenger" -version "9.0.0" > > > host pc > > pc configure -name "www.google.com" -ip "10.x.x.x" -sw msn_messenger > > > here, it doesn't work. > > > pc cget > > -name "www.google.com" -ip "10.x.x.x" -sw {-name {} -version {}} > > > msn_messenger failed to pass its value into instance pc. > > > any one knows how to fix it? > > > i tried -sw [msn_messenger cget] doesn't work. > > i know it works in this way: > > pc.sw.name="msn live messenger" > > pc.sw.version="9.0.0" > > I see no-one's replies yet. So unless you've figured it out, read on... > > First of all, you have to use: > pc configure ... -new_sw... > ^^^^^^ > because that's how you've defined your host record. > > Unless the maintainers of struct::record are willing to fix it, you > can't just pass in the name of an existing sub-record -- Tcl by itself > has no way to tell that "msn_messenger" is just a string or an existing > object name. You have to extract the fields of the sub-records > manually. > > Using tcl 8.5, you can do: > > pc configure \ > -name "www.google.com" \ > -ip "10.x.x.x" \ > {*}[string map {- -new_sw.} [msn_messenger show]] > > Using tcl 8.4, you need [eva] --http://wiki.tcl.tk/1017 > > I would abstract this into a proc: > > proc create_host_record {inst_name name ip new_sw_inst} { > set inst [::host $inst_name] > $inst configure -name $name -ip $ip > foreach member [record show members sw] { > $inst configure -new_sw.$member [$new_sw_inst cget -$member] > } > return $inst > } > > create_host_record pcwww.google.com10.x.x.x msn_messenger > Glenn's correct in what he says. I'll just add that it was my intentions to make: pc configure -new_sw [msn_messenger cget] work...but alas I guess I never got around to it. I can look into it to see if I can make it work... |
|
#4
| |||
| |||
| thank you all for the help. I did it pretty much like Glen way. eval pc.new_ws configure [sw cget] thanks Jarod ZZ |
![]() |
| Thread Tools | |
| Display Modes | |
In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.