forsec doesn't seem to work in templates
Posted: Sun Jan 11, 2009 2:03 am
Can anyone explain why this doesn't work? I can't use forsec to change the section access in a template. Right now I think I found a work around by using SectionRef, but it seems really weird that this didn't work. This is a completely stripped down example, most lines are comments to explain what is happening. Here the template should be able to return the number of compartments in the section which it stores the name of.
Thank you for your attention!
Code: Select all
create soma, dend
begintemplate SectionInfo
external soma, dend
public name, access_nseg
objref sref
strdef name
proc init() {
name = $s1
print "In init, section name is: ",name
}
proc access_nseg() {local n
print "In access_nseg, section name is: ",name
print "In access_nseg, currently accessed section is ",secname(),", with nseg = ",nseg
print " which is why we need to change the currently accessed section."
print " Trying to use forsec to print the right name and nseg for section ", name, "..."
forsec name print "In access, using forsec, section ", secname(), " has nseg = ",nseg
print " .... didn't work. Change access manually to show that external worked..."
dend print "In access_nseg, with access changed manually, section ", secname(), " has nseg = ",nseg
}
endtemplate SectionInfo
access soma
nseg=3
dend.nseg=11
objref SD
dend SD = new SectionInfo(secname())
SD.access_nseg()
// Sanity check the offending line from the template "access" function
strdef name
name = "dend"
proc try_offending_line_in_base() {
forsec name print "Using forsec, section ", secname(), " has nseg = ",nseg
}
//try_offending_line_in_base()