There is a third-party proc that I have been using, NANDFLASH::Init,
that I "source'd" from a file that contained it. NANDFLASH is
namespace rooted in global namespace.
#===============================================================================
# proc NANDFLASH::Init
#-------------------------------------------------------------------------------
proc NANDFLASH::Init {} {
global target
variable appletAddr
variable appletMailboxAddr
variable appletFileName
puts "-I- NANDFLASH::Init (trace level : $target(traceLevel))"
# Load the applet to the target
GENERIC::Init $NANDFLASH::appletAddr $NANDFLASH::appletMailboxAddr
$NANDFLASH::appletFileName [list $target(comType) $target(traceLevel)]
}
In my own code, I have been using this NANDFLASH::Init successfully
for a few weeks by invoking it from the global namespace. Last week, I
tried to invoke it from within a proc, burn_device:
proc burn_device {} {
::NANDFLASH::Init
....
}
The proc burn_device is called by another proc GO. GO is invoked upon
clicking a Tk button. Now, when I force the invocation of GO by
clicking the button, I get the following errors. I would like to avoid
editing the third-party function if possible. My guess is that there
is some kind of scoping I need to do. Any help appreciated.
-Le Chaud Lapin-
can't read "NANDFLASH::appletAddr": no such variable
can't read "NANDFLASH::appletAddr": no such variable
while executing
"GENERIC::Init $NANDFLASH::appletAddr $NANDFLASH::appletMailboxAddr
$NANDFLASH::appletFileName [list $target(comType)
$target(traceLevel)]"
(procedure "::NANDFLASH::Init" line 10)
invoked from within
"::NANDFLASH::Init"
(procedure "burn_device" line 85)
invoked from within
"burn_device"
(procedure "GO" line 8)
invoked from within
"GO"
invoked from within
".frame_primary.frame_secondary.button_go invoke "
invoked from within
".frame_primary.frame_secondary.button_go instate {pressed !disabled}
{ .frame_primary.frame_secondary.button_go state !
pressed; .frame_primary.frame_s..."
(command bound to event)
You probably need to change $NANDFLASH::... to $::NANDFLASH::...
Namespaces without a leading :: are taken from the current namespace,
and that might not be the global one!
Regards,
Arjen
There's no need to qualify var names when you have used [variable]
inside
a procedure.
Replace the last line for
GENERIC::Init $appletAddr $appletMailboxAddr \
$appletFileName [list $target(comType) $target(traceLevel)]
and it will work.
Regards
Emiliano
Try this:
uplevel #0 ::NANDFLASH::Init
That executes the call in global scope rather than the current scope.
Perhaps Init will be able to resolve the missing variable there.
I read all the responses, but I reply to this one only.
The problem was my feeble knowledge of TCL. Essentially, a long
sequence of "source'ing" of files was broken because a global variable
that needed to be defined by my code was defined/declared after the
"source'ing" began. The error conditions were masked by my abuse of
catch.
One of the would-have-been-properly-sourced files contained the global
variable that the interpreter legitimately complained about not being
defined.
Thanks All,
-Le Chaud Lapin-
catch is a very useful command, but it tends to mask Tcl's sublime
error handling system :).
Regards,
Arjen