TIP #207 Version 1.1: Add a -namespace Option to [interp invokehidden]

This is not necessarily the current version of this TIP.


TIP:207
Title:Add a -namespace Option to [interp invokehidden]
Version:$Revision: 1.1 $
Author:Joe Mistachkin <joe at mistachkin dot com>
State:Draft
Type:Project
Tcl-Version:8.5
Vote:Pending
Created:Tuesday, 29 June 2004

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:

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:

Reference Implementation

A reference implementation of this TIP is availble [1].

Copyright

This document has been placed in the public domain.


Powered by TclThis is not necessarily the current version of this TIP.

TIP AutoGenerator - written by Donal K. Fellows