This is not necessarily the current version of this TIP.
| TIP: | 207 |
| Title: | Add a -namespace Option to [interp invokehidden] |
| Version: | $Revision: 1.2 $ |
| Author: | Joe Mistachkin <joe at mistachkin dot com> |
| State: | Draft |
| Type: | Project |
| Tcl-Version: | 8.5 |
| Vote: | Pending |
| Created: | Tuesday, 29 June 2004 |
This TIP proposes a -namespace option for the interp invokehidden subcommand to allow hidden commands to be invoked in the specified namespace context in the slave interpreter.
Safe interpreters and namespaces have been useful and important features of Tcl since version 8.0. However, it can sometimes be difficult to use them together effectively. For example, while you can invoke a hidden command in a safe interpreter with interp invokehidden, such as source, you cannot specify the target namespace context where the command should be invoked. Using the interp eval subcommand is not an option because that, by design, does not allow hidden commands to be invoked. In addition, since the interp invokehidden subcommand expects a command name, namespace eval and similar constructs that would typically be used to change the target namespace context cannot be used.
interp invokehidden path ?-namespace namespace? ?-global? ?--? hiddenCmdName ?arg ...?
The interp invokehidden subcommand would continue to function as the current documentation dictates with the following notable exceptions:
The -namespace specifies the target namespace context in the slave interpreter where the command should be invoked.
The target namespace context specified by the -namespace option is created in the slave interpreter if it does not already exist.
If both the -global and -namespace options are present, the -namespace option is ignored.
A -- option (with the standard meaning) will be added as well.
The slave-interpreter command version of invokehidden will be updated in an equivalent way.
The following example scripts illustrates how this feature might be used.
################################################ # file inside.tcl ################################################ set x "this is a test from inside [namespace current]." ################################################ # file invoke.tcl ################################################ set i [interp create -safe] set file [file join [file dirname [info script]] inside.tcl] interp invokehidden $i -namespace ::test::foo::bar source $file set result [interp eval $i [list set ::test::foo::bar::x]] # should be: "this is a test from inside ::test::foo::bar." puts stdout $result
The following additions/changes would be made to the private Tcl C API:
int TclObjInvokeNamespace(Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[], Tcl_Obj *CONST namespaceName, int flags)
Invokes the specified command in the namespace context specified by the namespaceName argument. This is a new function.
Two new flags TCL_INVOKE_NS_MUST_EXIST and TCL_INVOKE_NO_GLOBAL_ONLY would be created for use with the TclObjInvoke* family of functions.
The TCL_INVOKE_NS_MUST_EXIST flag (used with TclObjInvokeNamespace) indicates that the caller does not want the namespace context to be created if it does not already exist. The TCL_INVOKE_NO_GLOBAL_ONLY flag (used with TclObjInvoke) inhibits the use of the TCL_GLOBAL_ONLY during command resolution.
static int SlaveInvokeHidden(Tcl_Interp *interp, Tcl_Interp *slaveInterp, Tcl_Obj *CONST namespaceName, int global, int objc, Tcl_Obj *CONST objv[])
The SlaveInvokeHidden would be modified to accept a namespaceName argument.
The FIND_ONLY_NS flag would be moved from generic/tclNamesp.c to generic/tclInt.h
A reference implementation of this TIP is availble [1].
This document has been placed in the public domain.
This is not necessarily the current version of this TIP.