For Programmers: Free Programming Magazines  


Home > Archive > Tcl > October 2005 > Working with namespaces...









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Working with namespaces...
Fredderic

2005-10-28, 3:57 am

I've got a few namespace related questions...

1) I've got a procedure which keeps various information about each
script that calls it in an array, for example;
upvar #0 my_private_data_$script data
What would be the cleanest/best equivalent to this that would pluck
"my_private_data" out of the callers namespace instead of having to
pass a script name to the procedure, and having to store all those as
globals (which get left behind if the namespace gets deleted).

2) What's the easiest/best way to make a procedure execute within the
caller's namespace, instead of the namespace within which it was
defined. If ::green::cow calls ::blue::moo, I want ::blue::moo to run
within the ::green namespace instead of its own.

Hints and tips with this kind of thing would be muchly appreciated...


Fredderic
Ronnie Brunner

2005-10-28, 7:58 am

Fredderic wrote:

> 1) I've got a procedure which keeps various information about each
> script that calls it in an array, for example;
> upvar #0 my_private_data_$script data
> What would be the cleanest/best equivalent to this that would pluck
> "my_private_data" out of the callers namespace instead of having to
> pass a script name to the procedure, and having to store all those as
> globals (which get left behind if the namespace gets deleted).


An example might help... Don't know what you're talking about ...

> 2) What's the easiest/best way to make a procedure execute within the
> caller's namespace, instead of the namespace within which it was
> defined. If ::green::cow calls ::blue::moo, I want ::blue::moo to run
> within the ::green namespace instead of its own.


proc ::blue::moo {} {
uplevel {
# code is evaled in caller's context
}
}


hth
Ronnie
--
----------------------------------------------------------------------
Ronnie Brunner ronnie.brunner@netcetera.ch
Netcetera AG, 8040 Zuerich phone +41 1 247 79 79 fax +41 1 247 70 75
Schelte Bron

2005-10-28, 7:58 am

On 10/28/05 05:35, Fredderic wrote:
> 1) I've got a procedure which keeps various information about each
> script that calls it in an array, for example;
> upvar #0 my_private_data_$script data
> What would be the cleanest/best equivalent to this that would pluck
> "my_private_data" out of the callers namespace instead of having to
> pass a script name to the procedure, and having to store all those as
> globals (which get left behind if the namespace gets deleted).
>

Like Ronnie, I don't exactly understand what you are looking for but
maybe [info script] or [info level -1] will give you the information you
are looking for.

Schelte.
--
set Reply-To [string map {nospam schelte} $header(From)]
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com