diff options
author | dgp <dgp@users.sourceforge.net> | 2006-11-14 16:30:31 (GMT) |
---|---|---|
committer | dgp <dgp@users.sourceforge.net> | 2006-11-14 16:30:31 (GMT) |
commit | d5fe10bc62fe923beb3c1017e3f0612c518d196c (patch) | |
tree | 9f6e7e2f523f55c10797b9ae54af4fb85de196a9 /generic | |
parent | 57cba80ccd1f62287a6b80f4c5c52689f2b2db0f (diff) | |
download | tcl-d5fe10bc62fe923beb3c1017e3f0612c518d196c.zip tcl-d5fe10bc62fe923beb3c1017e3f0612c518d196c.tar.gz tcl-d5fe10bc62fe923beb3c1017e3f0612c518d196c.tar.bz2 |
TIP#261 IMPLEMENTATION
* generic/tclNamesp.c: [namespace import] with 0 arguments introspects
the list of imported commands.
Diffstat (limited to 'generic')
-rw-r--r-- | generic/tclNamesp.c | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/generic/tclNamesp.c b/generic/tclNamesp.c index a33cffa..f3d7bf1 100644 --- a/generic/tclNamesp.c +++ b/generic/tclNamesp.c @@ -22,7 +22,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclNamesp.c,v 1.117 2006/11/02 16:57:54 dgp Exp $ + * RCS: @(#) $Id: tclNamesp.c,v 1.118 2006/11/14 16:30:31 dgp Exp $ */ #include "tclInt.h" @@ -3705,6 +3705,10 @@ NamespaceForgetCmd( * treated as an error. But if the "-force" option is included, then * existing commands are overwritten by the imported commands. * + * If there are no pattern arguments and the "-force" flag isn't given, + * this command returns the list of commands currently imported in + * the current namespace. + * * Results: * Returns TCL_OK if successful, and TCL_ERROR if anything goes wrong. * @@ -3744,6 +3748,24 @@ NamespaceImportCmd( allowOverwrite = 1; firstArg++; } + } else { + /* objc == 2; Command is just [namespace import]; + * Introspection form to return list of imported commands. */ + Tcl_HashEntry *hPtr; + Tcl_HashSearch search; + Namespace *nsPtr = (Namespace *) Tcl_GetCurrentNamespace(interp); + Tcl_Obj *listPtr = Tcl_NewObj(); + + for (hPtr = Tcl_FirstHashEntry(&nsPtr->cmdTable, &search); + hPtr != NULL; hPtr = Tcl_NextHashEntry(&search)) { + Command *cmdPtr = (Command *) Tcl_GetHashValue(hPtr); + if (cmdPtr->deleteProc == DeleteImportedCmd) { + Tcl_ListObjAppendElement(NULL, listPtr, Tcl_NewStringObj( + Tcl_GetHashKey(&nsPtr->cmdTable, hPtr) ,-1)); + } + } + Tcl_SetObjResult(interp, listPtr); + return TCL_OK; } /* |