<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE TIP SYSTEM "http://www.tcl.tk/cgi-bin/tct/tip/tipxml.dtd">
<!-- Converted at Sat May 25 14:39:33 GMT 2013 -->
<!-- TIP AutoGenerator - written by Donal K. Fellows -->

<TIP number='235'>
<header><title>Exposing a C API for Ensembles</title><author address="mailto:donal.k.fellows@manchester.ac.uk">Donal K. Fellows</author><status type='project' state='final' tclversion="8.5" vote='after'>$Revision: 1.9 $</status><history></history><created day='10' month='dec' year='2004' /></header>
<abstract>This TIP exposes a C API for the ensembles of <tipref type="text" tip="112"/>.</abstract>
<body><section title="Rationale">
<para>As the Tcl core moves to make more use of ensembles, it becomes more necessary for there to be an API available to allow control over those ensembles from the C level so that it is not necessary for such manipulation to be done through the evaluation of Tcl scripts (e.g. because this interferes with the interpreter&apos;s command count and that may be limited in that particular interpreter). Given such an API, it should be exposed to code outside the Tcl core if at all possible.</para>
</section>
<section title="Proposed Change">
<para>This TIP proposes exposing the following functions:</para>
<describe><item.d name='Tcl_CreateEnsemble'><para>Create an ensemble linked to a particular namespace and return the command token for the namespace command. The <emph style="italic">flags</emph> argument specifies the initial version of the set of flags controllable through Tcl_SetEnsembleFlags (see below).</para><para>Tcl_Command <emph style="bold">Tcl_CreateEnsemble</emph>(Tcl_Interp *<emph style="italic">interp</emph>, const char *<emph style="italic">name</emph>, Tcl_Namespace *<emph style="italic">namespacePtr</emph>, int <emph style="italic">flags</emph>)</para></item.d><item.d name='Tcl_FindEnsemble'><para>Return a command token for an ensemble, or NULL if the name does not refer to an ensemble. The <emph style="italic">flags</emph> argument controls whether failure to find an ensemble is an error and should be either 0 or TCL_LEAVE_ERR_MSG.</para><para>Tcl_Command <emph style="bold">Tcl_FindEnsemble</emph>(Tcl_Interp *<emph style="italic">interp</emph>, Tcl_Obj *<emph style="italic">cmdNameObj</emph>, int <emph style="italic">flags</emph>)</para></item.d><item.d name='Tcl_IsEnsemble'><para>Test whether a command token refers to an ensemble.</para><para>int <emph style="bold">Tcl_IsEnsemble</emph>(Tcl_Command <emph style="italic">command</emph>)</para></item.d><item.d name='Tcl_GetEnsembleSubcommandList, Tcl_SetEnsembleSubcommandList'><para>Read and write the (fixed) list of subcommands of the ensemble. Equivalent to manipulating the <emph style="bold">-subcommands</emph> option.</para><para>int <emph style="bold">Tcl_GetEnsembleSubcommandList</emph>(Tcl_Interp *<emph style="italic">interp</emph>, Tcl_Command <emph style="italic">command</emph>, Tcl_Obj **<emph style="italic">subcmdListObjPtr</emph>)</para><para>int <emph style="bold">Tcl_SetEnsembleSubcommandList</emph>(Tcl_Interp *<emph style="italic">interp</emph>, Tcl_Command <emph style="italic">command</emph>, Tcl_Obj *<emph style="italic">subcmdListObj</emph>)</para></item.d><item.d name='Tcl_GetEnsembleMappingDict, Tcl_SetEnsembleMappingDict'><para>Read and write the dictionary that maps subcommands to prefixes of implementation commands. Equivalent to manipulating the <emph style="bold">-map</emph> option.</para><para>int <emph style="bold">Tcl_GetEnsembleMappingDict</emph>(Tcl_Interp *<emph style="italic">interp</emph>, Tcl_Command <emph style="italic">command</emph>, Tcl_Obj **<emph style="italic">mapDictObjPtr</emph>)</para><para>int <emph style="bold">Tcl_SetEnsembleMappingDict</emph>(Tcl_Interp *<emph style="italic">interp</emph>, Tcl_Command <emph style="italic">command</emph>, Tcl_Obj *<emph style="italic">mapDictObj</emph>)</para></item.d><item.d name='Tcl_GetEnsembleUnknownHandler, Tcl_SetEnsembleUnknownHandler'><para>Read and write the command prefix list that is used to implement the unknown-subcommand handler. Equivalent to manipulating the <emph style="bold">-unknown</emph> option.</para><para>int <emph style="bold">Tcl_GetEnsembleUnknownHandler</emph>(Tcl_Interp *<emph style="italic">interp</emph>, Tcl_Command <emph style="italic">command</emph>, Tcl_Obj **<emph style="italic">handlerListObjPtr</emph>)</para><para>int <emph style="bold">Tcl_SetEnsembleUnknownHandler</emph>(Tcl_Interp *<emph style="italic">interp</emph>, Tcl_Command <emph style="italic">command</emph>, Tcl_Obj *<emph style="italic">handlerListObj</emph>)</para></item.d><item.d name='Tcl_GetEnsembleFlags, Tcl_SetEnsembleFlags'><para>Read and write the flags for the ensemble. Currently there is only one settable flag bit, TCL_ENSEMBLE_PREFIX, which is present exactly when <emph style="bold">-prefix</emph> option is true.</para><para>int <emph style="bold">Tcl_GetEnsembleFlags</emph>(Tcl_Interp *<emph style="italic">interp</emph>, Tcl_Command <emph style="italic">command</emph>, int *<emph style="italic">flagsPtr</emph>)</para><para>int <emph style="bold">Tcl_SetEnsembleFlags</emph>(Tcl_Interp *<emph style="italic">interp</emph>, Tcl_Command <emph style="italic">command</emph>, int <emph style="italic">flags</emph>)</para></item.d><item.d name='Tcl_GetEnsembleNamespace'><para>Reads the namespace associated with the ensemble; this value may not be altered.</para><para>int <emph style="bold">Tcl_GetEnsembleNamespace</emph>(Tcl_Interp *<emph style="italic">interp</emph>, Tcl_Command <emph style="italic">command</emph>, Tcl_Namespace **<emph style="italic">namespacePtrPtr</emph>)</para></item.d></describe>
<subsection title="Notes">
<para>The handle for an ensemble is a normal Tcl_Command handle, and any operation valid on such a command (e.g. deleting it or finding its name) is valid. Ensembles are just a special subclass of commands. This allows the ensemble API to be considerably sparser than it would otherwise have to be.</para>
</subsection>
</section>
<section title="Reference Implementation">
<para>The API is already in the core, but with internal naming and not exposed to anyone. Exposure is just renaming a few functions and putting them in the stubs table. No new types are exposed. All this means that a reference implementation is truly trivial.</para>
</section>
<section title="Copyright">
<para>This document has been placed in the public domain.</para>
</section>
</body></TIP>
