Tcl_Ensemble(3)
π Tcl_Ensemble β Tcl Library Procedures π
okay bestie, gather round, because this is the Tcl_Ensemble(3) manual page and it's literally the whole ensemble-command situation. yes, "ensemble" as in a command that's secretly a whole friend group of subcommands. main character energy fr fr. π
β¨ NAME β¨
Tcl_CreateEnsemble, Tcl_FindEnsemble, Tcl_GetEnsembleFlags, Tcl_GetEnsembleMappingDict, Tcl_GetEnsembleNamespace, Tcl_GetEnsembleParameterList, Tcl_GetEnsembleUnknownHandler, Tcl_GetEnsembleSubcommandList, Tcl_IsEnsemble, Tcl_SetEnsembleFlags, Tcl_SetEnsembleMappingDict, Tcl_SetEnsembleParameterList, Tcl_SetEnsembleSubcommandList, Tcl_SetEnsembleUnknownHandler β manipulate ensemble commands π
πΈ SYNOPSIS πΈ
#include <tcl.h>
Tcl_Command
Tcl_CreateEnsemble(interp, name, namespacePtr, ensFlags)
Tcl_Command
Tcl_FindEnsemble(interp, cmdNameObj, flags)
int
Tcl_IsEnsemble(token)
int
Tcl_GetEnsembleFlags(interp, token, ensFlagsPtr)
int
Tcl_SetEnsembleFlags(interp, token, ensFlags)
int
Tcl_GetEnsembleMappingDict(interp, token, dictObjPtr)
int
Tcl_SetEnsembleMappingDict(interp, token, dictObj)
int
Tcl_GetEnsembleParameterList(interp, token, listObjPtr)
int
Tcl_SetEnsembleParameterList(interp, token, listObj)
int
Tcl_GetEnsembleSubcommandList(interp, token, listObjPtr)
int
Tcl_SetEnsembleSubcommandList(interp, token, listObj)
int
Tcl_GetEnsembleUnknownHandler(interp, token, listObjPtr)
int
Tcl_SetEnsembleUnknownHandler(interp, token, listObj)
int
Tcl_GetEnsembleNamespace(interp, token, namespacePtrPtr)
π¦ ARGUMENTS π¦
so here's the full cast list of every parameter these functions take, no skips, no "etc." β every single one, periodt. π
Tcl_Interp *interp(in/out) β the interpreter where the ensemble is gonna be created or found. it's also where error result messages get written, so it's doing double duty. π«Ά and listen: the functions whose names start withTcl_GetEnsembleare the chill ones and may have aNULLfor theinterp, but every other function must not β do not try it, bestie, that's not the vibe. πconst char *name(in) β the name of the ensemble command to be created. that's it, that's the one. β¨Tcl_Namespace *namespacePtr(in) β the namespace the ensemble command is gonna be bound to, orNULLif you just want the current namespace. no biggie either way. πΈint ensFlags(in) β an OR'ed set of flag bits describing the basic configuration of the ensemble. right now literally only one bit has any meaning:TCL_ENSEMBLE_PREFIX, which is present when the ensemble command should also match unambiguous prefixes of subcommands. (yes, prefix matching. slay.) βTcl_Obj *cmdNameObj(in) β a value holding the name of the ensemble command to look up. πint flags(in) β an OR'ed set of flag bits controlling the behavior ofTcl_FindEnsemble. currently onlyTCL_LEAVE_ERR_MSGis supported β that's the whole roster, don't go inventing more. πTcl_Command token(in) β a normal command token that refers to an ensemble command, or one you wish to use for testing as an ensemble command inTcl_IsEnsemble. πint *ensFlagsPtr(out) β pointer to a variable to write the current ensemble flag bits into; currently only the bitTCL_ENSEMBLE_PREFIXis defined. πTcl_Obj *dictObj(in) β a dictionary value to use for the subcommand-to-implementation-command-prefix mapping dictionary in the ensemble. it may beNULLif the mapping dictionary is to be removed. ποΈTcl_Obj **dictObjPtr(out) β pointer to a variable to write the current ensemble mapping dictionary into. πTcl_Obj *listObj(in) β a list value to use for the list of formal pre-subcommand parameters, the defined list of subcommands in the dictionary, or the unknown subcommand handler command prefix. may beNULLif the subcommand list or unknown handler are to be removed. π§Tcl_Obj **listObjPtr(out) β pointer to a variable to write the current list of formal pre-subcommand parameters, the defined list of subcommands, or the current unknown handler prefix into. πTcl_Namespace **namespacePtrPtr(out) β pointer to a variable to write the handle of the namespace the ensemble is bound to into. π
ok so that's the intro, the synopsis and the whole arguments lineup β every flag, every type, every NULL-ability, every in/out marker, all of it. and there's more coming, so don't go anywhere bestie, we're not done. π
π« DESCRIPTION π«
okay so bestie, an ensemble is literally just a command that's bound to some namespace, and it's made up of a whole collection of subcommands that are implemented by other Tcl commands. the first argument you hand to the ensemble command is always read as a selector that says which subcommand to run. main character behavior tbh. π
ensembles get created with Tcl_CreateEnsemble, which takes four arguments: the interpreter you're working in, the name of the ensemble to create, the namespace inside the interpreter to bind the ensemble to, and the default set of ensemble flags. the result of the function is the command token for the ensemble, and you can use that token to configure the ensemble further with the API down below in ENSEMBLE PROPERTIES. slay.
if you've got the name of an ensemble command, you can grab its token with Tcl_FindEnsemble. but heads up β if the command name you passed (in cmdNameObj) does not refer to an ensemble command, the result is NULL, and (if the TCL_LEAVE_ERR_MSG bit is set in flags) an error message gets left in the interpreter result. not me getting rejected π
and if you wanna check whether a command token even refers to an ensemble, use Tcl_IsEnsemble. it returns 1 if the token refers to an ensemble, or 0 otherwise. simple as. β¨
π ENSEMBLE PROPERTIES π
every ensemble has four read-write properties and one read-only property. the whole lineup:
flags(read-write) β the set of flags for the ensemble, expressed as a bit-field. right now the only public flag isTCL_ENSEMBLE_PREFIX, which is set when unambiguous prefixes of subcommands are permitted to be resolved to implementations, on top of exact matches. you read and write these withTcl_GetEnsembleFlagsandTcl_SetEnsembleFlagsrespectively. the result of both of those functions is a Tcl result code (TCL_OK, orTCL_ERRORif the token does not refer to an ensemble). periodt.mapping dictionary(read-write) β a dictionary containing a mapping from subcommand names to lists of words to use as a command prefix (replacing the first two words of the command, which are the ensemble command itself and the subcommand name), orNULLif every subcommand is to be mapped to the command with the same unqualified name in the ensemble's bound namespace. defaults toNULL. you read and write it withTcl_GetEnsembleMappingDictandTcl_SetEnsembleMappingDictrespectively. the result of both of those functions is a Tcl result code (TCL_OK, orTCL_ERRORif the token does not refer to an ensemble), and the dictionary you get fromTcl_GetEnsembleMappingDictshould always be treated as immutable even if it is unshared. also: all command names in prefixes set viaTcl_SetEnsembleMappingDictmust be fully qualified. no shortcuts bestie. πformal pre-subcommand parameter list(read-write) β a list of formal parameter names (the names only being used when generating error messages) that come at invocation of the ensemble between the name of the ensemble and the subcommand argument.NULL(the default) is equivalent to the empty list. read and write it withTcl_GetEnsembleParameterListandTcl_SetEnsembleParameterListrespectively. the result of both of those functions is a Tcl result code (TCL_OK, orTCL_ERRORif the token does not refer to an ensemble), and the dictionary obtained fromTcl_GetEnsembleParameterListshould always be treated as immutable even if it is unshared.subcommand list(read-write) β a list of all the subcommand names for the ensemble, orNULLif this is to be derived from either the keys of the mapping dictionary (see above) or (if that is alsoNULL) from the set of commands exported by the bound namespace. read and write it withTcl_GetEnsembleSubcommandListandTcl_SetEnsembleSubcommandListrespectively. the result of both of those functions is a Tcl result code (TCL_OK, orTCL_ERRORif the token does not refer to an ensemble), and the list obtained fromTcl_GetEnsembleSubcommandListshould always be treated as immutable even if it is unshared.unknown subcommand handler command prefix(read-write) β a list of words to prepend on the front of any subcommand when the subcommand is unknown to the ensemble (according to the current prefix handling rule); peep thenamespace ensemblecommand for more details. ifNULL, the default behavior β generate a suitable error message β will be used when an unknown subcommand is encountered. read and write it withTcl_GetEnsembleUnknownHandlerandTcl_SetEnsembleUnknownHandlerrespectively. the result of both functions is a Tcl result code (TCL_OK, orTCL_ERRORif the token does not refer to an ensemble), and the list obtained fromTcl_GetEnsembleUnknownHandlershould always be treated as immutable even if it is unshared.bound namespace(read-only) β the namespace to which the ensemble is bound; when the namespace is deleted, so too will the ensemble be, and this namespace is also the namespace whose list of exported commands is used if both the mapping dictionary and the subcommand list properties areNULL. you can read it withTcl_GetEnsembleNamespace, which returns a Tcl result code (TCL_OK, orTCL_ERRORif the token does not refer to an ensemble). look but don't touch, babe. π
π¦ REFERENCE COUNT MANAGEMENT π¦
Tcl_FindEnsemble does not modify the reference count of its cmdNameObj argument β it only reads. but ngl, watch out: this function may set the interpreter result, and if that's the only place holding a reference to the object, it will be deleted. π
the ensemble property getters (Tcl_GetEnsembleMappingDict, Tcl_GetEnsembleParameterList, Tcl_GetEnsembleSubcommandList, and Tcl_GetEnsembleUnknownHandler) do not manipulate the reference count of the values they provide out; if those are non-NULL, they will have a reference count of at least 1. also note that these functions may set the interpreter result.
the ensemble property setters (Tcl_SetEnsembleMappingDict, Tcl_SetEnsembleParameterList, Tcl_SetEnsembleSubcommandList, and Tcl_SetEnsembleUnknownHandler) will increment the reference count of the new value of the property they are given if they succeed (and decrement the reference count of the old value of the property, if relevant). and if the property setters return TCL_ERROR, the reference count of the Tcl_Obj argument is left unchanged. no takebacks. π«Ά
okay bestie this is the part where you actually keep track of your refcounts, because Tcl will not do it for you and the crash is not cute.
π SEE ALSO π
π₯ KEYWORDS π₯
command, ensemble
and that's the whole page, bestie!! this one's from Tcl 8.5 and it's the Tcl_Ensemble(3) man page πβ¨ go forth and ensemble responsibly, you absolute icon ππ
π¦ 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
- nixpkgs unstable: tcl 9.1.0
- Copyright (c) 2005 Donal K. Fellows
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms