Tcl_CreateAlias(3)
okay bestie welcome to the Tcl_CreateAlias(3) page from the Tcl Library Procedures manual π This one is all about juggling multiple Tcl interpreters, aliases, and hidden commands like the main character you are.
β¨ NAME β¨
So this whole page is the friend group for:
Tcl_IsSafeTcl_CreateChildTcl_GetChildTcl_GetParentTcl_GetInterpPathTcl_CreateAliasTcl_CreateAliasObjTcl_GetAliasObjTcl_ExposeCommandTcl_HideCommand
and their collective slay is to manage multiple Tcl interpreters, aliases and hidden commands. no cap.
πΈ SYNOPSIS πΈ
#include <tcl.h>
int
Tcl_IsSafe(interp)
Tcl_Interp *
Tcl_CreateChild(interp, name, isSafe)
Tcl_Interp *
Tcl_GetChild(interp, name)
Tcl_Interp *
Tcl_GetParent(interp)
int
Tcl_GetInterpPath(interp, childInterp)
int
Tcl_CreateAlias(childInterp, childCmd, targetInterp, targetCmd,
argc, argv)
int
Tcl_CreateAliasObj(childInterp, childCmd, targetInterp, targetCmd,
objc, objv)
int
Tcl_GetAliasObj(interp, childCmd, targetInterpPtr, targetCmdPtr,
objcPtr, objvPtr)
int
Tcl_ExposeCommand(interp, hiddenCmdName, cmdName)
int
Tcl_HideCommand(interp, cmdName, hiddenCmdName)
π ARGUMENTS π
Here's the tea on every single parameter:
Tcl_Interp *interp(in) β the interpreter where you wanna run the specified command. it's giving home base.const char *name(in) β the name of the child interpreter you're creating or manipulating. name drop, literally.int isSafe(in) β if this is non-zero, you get a "safe" child that's suitable for running untrusted code; otherwise you get a trusted child. choose wisely bestie.Tcl_Interp *childInterp(in) β the interpreter used to create the source command for an alias (see below). source command energy.const char *childCmd(in) β the name of the source command for the alias. the origin story.Tcl_Interp *targetInterp(in) β the interpreter that contains the target command for an alias. where the magic happens.const char *targetCmd(in) β the name of the target command for the alias intargetInterp. the destination.Tcl_Size argc(in) β count of additional arguments to pass to the alias command. how many extra besties you're bringing.const char *const *argv(in) β vector of strings, the additional arguments to pass to the alias command. this storage is owned by the caller. so you're responsible for it, not us.Tcl_Size objc(in) β count of additional value arguments to pass to the aliased command. same vibe but withTcl_Obj.Tcl_Obj **objv(in) β vector ofTcl_Objstructures, the additional value arguments to pass to the aliased command. this storage is owned by the caller too. you keep it, we just borrow.Tcl_Interp **targetInterpPtr(in) β pointer to a location to store the address of the interpreter where a target command is defined for an alias. it's a pointer to a pointer, very meta.const char **targetCmdPtr(out) β pointer to a location to store the address of the name of the target command for an alias. out means we write here.Tcl_Size | int *objcPtr(out) β pointer to a location to store the count of additional value arguments to be passed to the alias. the location is in storage owned by the caller. if it points to a variable whose type is notTcl_Size, a compiler warning will be generated. if your extension is compiled with-DTCL_8_API, this function will returnTCL_ERRORfor aliases with more thanINT_MAXvalue arguments, otherwise expect it to crash π. so yeah, not a vibe to ignore.Tcl_Obj ***objvPtr(out) β pointer to a location to store a vector ofTcl_Objstructures, the additional arguments to pass to an alias command. the location is in storage owned by the caller; the vector ofTcl_Objstructures is owned by the called function. so we own the vector, you own the location.const char *cmdName(in) β the name of an exposed command to hide or create. main character name.const char *hiddenCmdName(in) β the name under which a hidden command is stored and with which it can be exposed or invoked. secret identity, iykyk.
β¨ DESCRIPTION β¨
okay so bestie, these procedures are literally intended for access to the multiple interpreter facility from inside C programs. They enable managing multiple interpreters in a hierarchical relationship, and the management of aliases β commands that when invoked in one interpreter execute a command in another interpreter. The return value for those procedures that return an int is either TCL_OK or TCL_ERROR. If TCL_ERROR is returned then the interpreter's result contains an error message. periodt π
Tcl_CreateChildβ creates a new interpreter as a child ofinterp. It also creates a child command namednameininterpwhich allowsinterpto manipulate the new child. IfisSafeis0, the command creates a trusted child in which Tcl code has access to all the Tcl commands. If it is1, the command creates a βsafeβ child in which Tcl code has access only to set of Tcl commands defined as βSafe Tclβ; see the manual entry for the Tclinterpcommand for details. If the creation of the new child interpreter failed,NULLis returned. πTcl_IsSafeβ returns1ifinterpis βsafeβ (was created with theTCL_SAFE_INTERPRETERflag specified),0otherwise. πTcl_GetChildβ returns a pointer to a child interpreter ofinterp. The child interpreter is identified byname. If no such child interpreter exists,NULLis returned. π¦Tcl_GetParentβ returns a pointer to the parent interpreter ofinterp. Ifinterphas no parent (it is a top-level interpreter) thenNULLis returned. πΈTcl_GetInterpPathβ stores in the result ofinterpthe relative path betweeninterpandchildInterp;childInterpmust be a child ofinterp. If the computation of the relative path succeeds,TCL_OKis returned, elseTCL_ERRORis returned and an error message is stored as the result ofinterp. β¨Tcl_CreateAliasβ creates a command namedchildCmdinchildInterpthat when invoked, will cause the commandtargetCmdto be invoked intargetInterp. The arguments specified by the strings contained inargvare always prepended to any arguments supplied in the invocation ofchildCmdand passed totargetCmd. This operation returnsTCL_OKif it succeeds, orTCL_ERRORif it fails; in that case, an error message is left in the value result ofchildInterp. Note that there are no restrictions on the ancestry relationship (as created byTcl_CreateChild) betweenchildInterpandtargetInterp. Any two interpreters can be used, without any restrictions on how they are related. πTcl_CreateAliasObjβ similar toTcl_CreateAliasexcept that it takes a vector of values to pass as additional arguments instead of a vector of strings. π₯Tcl_GetAliasObjβ returns information in the form of a pointer to a vector ofTcl_Objstructures about an aliasaliasNameininterp. Any of the result fields can beNULL, in which case the corresponding datum is not returned. If a result field is non-NULL, the address indicated is set to the corresponding datum. For example, iftargetCmdPtris non-NULLit is set to a pointer to the string containing the name of the target command. πTcl_ExposeCommandβ moves the command namedhiddenCmdNamefrom the set of hidden commands to the set of exposed commands, putting it under the namecmdName.HiddenCmdNamemust be the name of an existing hidden command, or the operation will returnTCL_ERRORand leave an error message as the result ofinterp. If an exposed command namedcmdNamealready exists, the operation returnsTCL_ERRORand leaves an error message as the result ofinterp. If the operation succeeds, it returnsTCL_OK. After executing this command, attempts to usecmdNamein any script evaluation mechanism will again succeed. πTcl_HideCommandβ moves the command namedcmdNamefrom the set of exposed commands to the set of hidden commands, under the namehiddenCmdName.CmdNamemust be the name of an existing exposed command, or the operation will returnTCL_ERRORand leave an error message as the result ofinterp. Currently bothcmdNameandhiddenCmdNamemust not contain namespace qualifiers, or the operation will returnTCL_ERRORand leave an error message as the result ofinterp. TheCmdNamewill be looked up in the global namespace, and not relative to the current namespace, even if the current namespace is not the global one. If a hidden command whose name ishiddenCmdNamealready exists, the operation also returnsTCL_ERRORand an error message is left as the result ofinterp. If the operation succeeds, it returnsTCL_OK. After executing this command, attempts to usecmdNamein any script evaluation mechanism will fail. π
For a description of the Tcl interface to multiple interpreters, see interp(n). π«Ά
β¨ REFERENCE COUNT MANAGEMENT β¨
Tcl_CreateAliasObjincrements the reference counts of the values in itsobjvargument. (That reference lasts the same length of time as the owning alias.) πTcl_GetAliasObjreturns (via itsobjvPtrargument) a pointer to values that it holds a reference to. π§
β¨ SEE ALSO β¨
interp(n)π
β¨ KEYWORDS β¨
alias,command,exposed commands,hidden commands,interpreter,invoke,parent,childπ
π that's it bestie! this page is from Tcl 7.6, and it's the Tcl_CreateAlias(3) manual page. mwah! π
π¦ where this page comes from
- alpine 3.23: tcl9-doc 9.0.3-r0 Β· TCL
- alpine 3.24: tcl9-doc 9.0.3-r2 Β· TCL
- fedora 43: tcl-doc 1:9.0.2-1.fc43 Β· TCL AND GPL-3.0-or-later WITH Bison-exception-2.2 AND BSD-3-Clause
- fedora 44: tcl-doc 1:9.0.2-1.fc44 Β· TCL AND GPL-3.0-or-later WITH Bison-exception-2.2 AND BSD-3-Clause
- nixos 26.05: tcl 9.0.3
- Copyright (c) 1995-1996 Sun Microsystems, Inc
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms