Tcl_CreateAlias(3tcl)
โจ NAME โจ
okay so bestie, this whole page is about one iconic squad of functions: Tcl_IsSafe, Tcl_CreateChild, Tcl_GetChild, Tcl_GetParent, Tcl_GetInterpPath, Tcl_CreateAlias, Tcl_CreateAliasObj, Tcl_GetAliasObj, Tcl_ExposeCommand, and Tcl_HideCommand. They all live in the Tcl Library Procedures and theyโre here to help you manage multiple Tcl interpreters, aliases and hidden commands. This is the Tcl_CreateAlias(3tcl) manual page, and itโs giving very much โI run a whole multiverse of interpretersโ energy. ๐ฆ
๐ธ 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 ๐
Tcl_Interp *interp(in) โ the interpreter where you want to run the specified command. Like, the main characterโs home base. ๐const char *name(in) โ the name of the child interpreter youโre creating or manipulating. Gotta name your babies. ๐int isSafe(in) โ if this is non-zero, you get a โsafeโ child thatโs suitable for running untrusted code. If itโs zero, you get a trusted child. Choose wisely, bestie. ๐Tcl_Interp *childInterp(in) โ the interpreter used to create the source command for an alias (peep the description below for the full tea). โconst char *childCmd(in) โ the name of the source command for the alias. Itโs the command that gets aliased. โจTcl_Interp *targetInterp(in) โ the interpreter that contains the target command for an alias. So, where the real magic happens. ๐ฏconst char *targetCmd(in) โ the name of the target command for the alias, living insidetargetInterp. ๐ฏTcl_Size argc(in) โ how many additional arguments youโre passing to the alias command. Count โem up. ๐ขconst char *const *argv(in) โ a vector of strings: the additional arguments to pass to the alias command. This storage is owned by the caller. So you brought it, you manage it. ๐Tcl_Size objc(in) โ count of additional value arguments to pass to the aliased command. Same vibes asargc, but for objects. ๐ฆTcl_Obj **objv(in) โ a vector ofTcl_Objstructures, the additional value arguments to pass to the aliased command. This storage is owned by the caller too. You keep it, you clean it. ๐งนTcl_Interp **targetInterpPtr(in) โ pointer to a location where weโll store the address of the interpreter where a target command is defined for an alias. Itโs like a little mailbox for an interpreter address. ๐ฌconst char **targetCmdPtr(out) โ pointer to a location where weโll store the address of the name of the target command for an alias. Another mailbox, but for a command name. ๐ฎTcl_Size | int *objcPtr(out) โ pointer to a location where weโll 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 ๐. No cap, thatโs the warning.Tcl_Obj ***objvPtr(out) โ pointer to a location where weโll store a vector ofTcl_Objstructures: the additional arguments to pass to an alias command. The location is in storage owned by the caller, but the vector ofTcl_Objstructures is owned by the called function. So like, you get the address, they own the goodies. ๐ซถconst char *cmdName(in) โ the name of an exposed command to hide or create. Itโs the commandโs public-facing name. ๐const char *hiddenCmdName(in) โ the name under which a hidden command is stored, and with which it can be exposed or invoked. Itโs the secret identity. ๐ต๏ธโโ๏ธ
thatโs part 1, bestie โ more Tcl interpreter chaos is coming in part 2, so donโt go anywhere ๐
๐ซ DESCRIPTION ๐ซ
Okay bestie, listen up, because these procedures are literally the VIP pass into Tcl's multiple interpreter facility from inside C programs. They let you manage a whole lil hierarchy of interpreters, plus handle aliases โ and an alias is just a command that, when you invoke it in one interpreter, runs a command over in another interpreter. Iconic crossover behavior, fr.
The return value for any of these procedures that returns an int is either TCL_OK or TCL_ERROR. And if it hands you back TCL_ERROR? Then the interpreter's result is holding an error message. No cap, go read it.
Tcl_CreateChildโ makes a brand new interpreter as a child of interp. It also creates a child command named name in interp, which is how interp gets to manipulate the new baby child. If isSafe is zero, the command creates a trusted child, where Tcl code has access to all the Tcl commands. If isSafe is1, you get a โsafeโ child, where Tcl code only gets access to the set of Tcl commands defined as โSafe Tclโ โ peep the manual entry for the Tclinterpcommand for the details. And if creating that new child interpreter failed? You getNULL. ๐Tcl_IsSafeโ returns1if interp is โsafeโ (meaning it was created with theTCL_SAFE_INTERPRETERflag specified), and0otherwise. Simple as.Tcl_GetChildโ hands you back a pointer to a child interpreter of interp. The child is identified by name. If no such child interpreter exists, you getNULL. ๐Tcl_GetParentโ hands you back a pointer to the parent interpreter of interp. If interp has no parent (it's a top-level interpreter, main character energy), thenNULLcomes back.Tcl_GetInterpPathโ stores in the result of interp the relative path between interp and childInterp; and heads up, childInterp must be a child of interp. If the computation of the relative path goes well,TCL_OKis returned. OtherwiseTCL_ERRORcomes back and an error message gets stored as the result of interp.Tcl_CreateAliasโ creates a command named childCmd in childInterp that, when invoked, will cause targetCmd to be invoked in targetInterp. The arguments specified by the strings contained in argv are always prepended to any arguments supplied in the invocation of childCmd, and passed along to targetCmd. ReturnsTCL_OKif it succeeds, orTCL_ERRORif it fails โ and in that failure case, an error message is left in the value result of childInterp. Also, bestie, plot twist: there are no restrictions on the ancestry relationship (as created byTcl_CreateChild) between childInterp and targetInterp. Any two interpreters can be used, with zero restrictions on how they're related. Slay.Tcl_CreateAliasObjโ same vibe asTcl_CreateAlias, except it takes a vector of values to pass as additional arguments instead of a vector of strings. Small change, big difference. โจTcl_GetAliasObjโ returns info in the form of a pointer to a vector ofTcl_Objstructures about an alias aliasName in interp. Any of the result fields can beNULL, in which case the corresponding datum is just not returned. If a result field is non-NULL, the address indicated gets set to the corresponding datum. For example, if targetCmdPtr is non-NULL, it gets set to a pointer to the string containing the name of the target command. ๐Tcl_ExposeCommandโ moves the command named hiddenCmdName from the set of hidden commands over to the set of exposed commands, putting it under the name cmdName. hiddenCmdName must be the name of an existing hidden command, or the operation returnsTCL_ERRORand leaves an error message as the result of interp. If an exposed command named cmdName already exists, the operation returnsTCL_ERRORand leaves an error message as the result of interp. If everything goes right, it returnsTCL_OK. After executing this command, attempts to use cmdName in any script evaluation mechanism will again succeed. Welcome back to the spotlight, babe. ๐Tcl_HideCommandโ moves the command named cmdName from the set of exposed commands to the set of hidden commands, under the name hiddenCmdName. cmdName must be the name of an existing exposed command, or the operation returnsTCL_ERRORand leaves an error message as the result of interp. Currently both cmdName and hiddenCmdName must not contain namespace qualifiers, or the operation returnsTCL_ERRORand leaves an error message as the result of interp. Also, cmdName will be looked up in the global namespace, and not relative to the current namespace โ even if the current namespace is not the global one. Sneaky but true. And if a hidden command whose name is hiddenCmdName already exists, the operation also returnsTCL_ERRORand an error message is left as the result of interp. If it succeeds, it returnsTCL_OK. After executing this command, attempts to use cmdName in any script evaluation mechanism will fail. Gone. Ghosted. ๐ป
If you want the deets on the Tcl interface to multiple interpreters, go see interp(3tcl).
๐ซถ REFERENCE COUNT MANAGEMENT ๐ซถ
Okay this part is important, don't skip it:
Tcl_CreateAliasObjincrements the reference counts of the values in its objv argument. (And that reference lasts the same length of time as the owning alias.) So it's holding onto those values, periodt.Tcl_GetAliasObjreturns โ via its objvPtr argument โ a pointer to values that it holds a reference to. Keep that in mind and you won't get got. ๐
๐ SEE ALSO ๐
โญ KEYWORDS โญ
alias, command, exposed commands, hidden commands, interpreter, invoke, parent, child
And that's the whole tea, bestie ๐ this was Tcl_CreateAlias(3tcl) from Tcl 7.6, dated the same way the page itself signs off โ go forth and manage those interpreters like the icon you are, mwah ๐โจ
๐ฆ where this page comes from
- ubuntu stonking: tcl9.0-doc 9.0.4+dfsg-1
- 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