简体   繁体   中英

Grab the content of tcl namespace from one interpreter and pass to another interpreter

I use cpptcl.hpp library to create TCL interpreters and evaluate some the expressions. Now I stuck in one problem: In one interpreter (Tcl::interpreter interp1;) I have a namespace called MyNamespace in one interpreter, where there are some variables and procedures defined, and I want to be able to evaluate some TCL expressions in another interpreter (Tcl::interpreter interp2;) by using the predefined variables and procedures in MyNamespace namespace. How I can do that?

You can't. At least, not easily.

Of course, if your interp does only contain pure Tcl code, and no packages loaded, you are able, in principle, to serialize everything (to a string) and evaluate it in an another interp; the wiki has examples on this (search for "saving state" etc).

But to me it looks like you're trying to create a "reference" interp and then use it as a kind of template. If so, I would instead just write a code which sets up an interp and then would call it each time to get an appropriately prepared interp.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM