For Programmers: Free Programming Magazines  


Home > Archive > Tcl > August 2006 > Scope during Tcl_Eval...









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 Scope during Tcl_Eval...
MartinLemburg@UGS

2006-08-23, 4:02 am

Hello,

I have to maintain C(++) code using tcl 8.4a2 (no version change
possible) and I found some places where Tcl_GlobalEval is used.

In this places it would be necessary to change this, to let the given
script be evaluated at the scope of the caller of the tcl command
function (in C++).

So ...

1. from tcl a tcl command is called
2. this tcl command function wants to evaluate a string/script in
the callers scope

Must I wrap the script in "uplevel 1 [list ...]"?

Thanks and best regards,

Martin Lemburg
UGS - Transforming the Process of Innovation

Donal K. Fellows

2006-08-23, 8:02 am

MartinLemburg@UGS wrote:
> So ...
> 1. from tcl a tcl command is called
> 2. this tcl command function wants to evaluate a string/script in
> the callers scope
>
> Must I wrap the script in "uplevel 1 [list ...]"?


Tcl does not push a stack frame automatically when executing a command
defined in C; your current context is the caller's context. Only
procedures and [namespace eval] push new contexts (and [uplevel] does
something else; it uses existing contexts...)

Donal.

MartinLemburg@UGS

2006-08-23, 7:03 pm

Hello Donal,

thanks for your reply!

I changed in the tcl command functions the Tcl_GlobalEval calls to
"Tcl_EvalObjEx( ip, scriptObj, 0 )" to execute the script in the
callers context.

This scope thing could be good to be mentioned in the man pages!

I tried to find this information in the man pages, but I didn't find
it.

Best regards,

Martin Lemburg
UGS - Transforming the Process of Innovation

Donal K. Fellows wrote:
> MartinLemburg@UGS wrote:
>
> Tcl does not push a stack frame automatically when executing a command
> defined in C; your current context is the caller's context. Only
> procedures and [namespace eval] push new contexts (and [uplevel] does
> something else; it uses existing contexts...)
>
> Donal.


Donal K. Fellows

2006-08-23, 7:03 pm

MartinLemburg@UGS wrote:
> This scope thing could be good to be mentioned in the man pages!
>
> I tried to find this information in the man pages, but I didn't find
> it.


It's the sort of thing you get from reading books about Tcl. Some things
just don't fit the manpage style of things very well.

Donal.
Sponsored Links







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

Copyright 2008 codecomments.com