You are viewing a plain text version of this content. The canonical link for it is here.
Posted to websh-user@tcl.apache.org by David McTavish <dm...@sandvine.com> on 2003/11/24 20:04:20 UTC
local variables and accessibility
Is it possible to access local variables after a command has been
dispatched? ie:
set foo "foo"
web::command default \
{
web::put $foo
}
web::dispatch
<the above fails with error can't read "foo": no such variable>
And more importantly, I have the following that I need to implement:
set foo "foo"
proc doSomething {} \
{
web::put $foo
}
web::command default \
{
doSomething
}
web::dispatch
<the above fails with error can't read "foo": no such variable>
thx,
d.
Re: local variables and accessibility
Posted by Ronnie Brunner <ro...@netcetera.ch>.
As long as your [set foo "foo"] command is in the global namespace,
the first example should actually work (it does in my environment):
the code within a web::command is always evaled in the global
namespace, so every global variable should be visible.
Besides that, the normal Tcl ruels apply: just decalre a variable
global to access it within any other proc (or declare it fully
qualified (i.e. using namespace delimiters)
set f "some stuff"
proc test {} {
global f
web::put $f
}
test
works just like
set ::f "some stuff"
proc test {} {
web::put $::f
}
test
Ronnie
> Is it possible to access local variables after a command has been
> dispatched? ie:
>
> set foo "foo"
> web::command default \
> {
> web::put $foo
> }
> web::dispatch
>
> <the above fails with error can't read "foo": no such variable>
>
> And more importantly, I have the following that I need to implement:
>
> set foo "foo"
> proc doSomething {} \
> {
> web::put $foo
> }
> web::command default \
> {
> doSomething
> }
> web::dispatch
>
> <the above fails with error can't read "foo": no such variable>
>
>
> thx,
> d.
----------------------------------------------------------------------
Ronnie Brunner ronnie.brunner@netcetera.ch
Netcetera AG, 8040 Zuerich phone +41 1 247 79 79 fax +41 1 247 70 75