TIP #207: Add a -namespace Option to [interp invokehidden]
From: Joe Mistachkin (joe_at_mistachkin.com)
Date: 07/08/04
- Next message: Bruce Hartweg: "Re: Matching of optional parts in regular expressions"
- Previous message: Peter MacDonald: "ANN: Line numbers patch and debugger for Tcl (TIP 86)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 8 Jul 2004 16:55:41 +0000 (UTC)
TIP #207: ADD A -NAMESPACE OPTION TO [INTERP INVOKEHIDDEN]
============================================================
Version: $Revision: 1.1 $
Author: Joe Mistachkin <joe_at_mistachkin.com>
State: Draft
Type: Project
Tcl-Version: 8.5
Vote: Pending
Created: Tuesday, 29 June 2004
URL: http://purl.org/tcl/tip/207.html
WebEdit: http://purl.org/tcl/tip/edit/207
Post-History:
-------------------------------------------------------------------------
ABSTRACT
==========
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.
RATIONALE
===========
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.
SPECIFICATION
===============
*interp invokehidden* /path/ ?*-global*? ?*-namespace*
/namespace/? ?*--*? /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.
EXAMPLE USAGE
---------------
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
PROPOSED INTERNAL C API CHANGES
=================================
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/, int /global/, Tcl_Obj *CONST /namespaceName/, 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/
REFERENCE IMPLEMENTATION
==========================
A reference implementation of this TIP is availble
[<URL:http://sf.net/tracker/?func=detail&aid=981841&group_id=10894&atid=310894>].
COPYRIGHT
===========
This document has been placed in the public domain.
-------------------------------------------------------------------------
TIP AutoGenerator - written by Donal K. Fellows
[[Send Tcl/Tk announcements to tcl-announce@mitchell.org
Announcements archived at http://groups.yahoo.com/group/tcl_announce/
Send administrivia to tcl-announce-request@mitchell.org
Tcl/Tk at http://tcl.tk/ ]]
- Next message: Bruce Hartweg: "Re: Matching of optional parts in regular expressions"
- Previous message: Peter MacDonald: "ANN: Line numbers patch and debugger for Tcl (TIP 86)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]