TclXInit(3tcl)

πŸ“¦ version 8.6.3, in ubuntu stonking

TclXInit(3tcl) β€” Extended Tcl initialization πŸ’–βœ¨

okay so this one is from the 3tcl manual section, and it's basically the "how do I boot up Extended Tcl" page. if you're wiring TclX into your own app, this is your girlie. grab a snack, we're going in πŸ“


πŸŽ€ NAME πŸŽ€

Tclx_Init, Tclxcmd_Init, TclX_Main, Tkx_Init, TkX_Main β€” Extended Tcl initialization. literally the starter pack, no cap ✨


🌈 SYNOPSIS 🌈

first, link it:

-ltclx -ltcl

then:

#include "tclExtend.h"

int
Tclx_Init (Tcl_Interp *interp);

int
Tclxcmd_Init (Tcl_Interp *interp);

int
void
TclX_Main (int               argc,
           char            **argv,
           Tcl_AppInitProc  *appInitProc);

int
Tkx_Init (Tcl_Interp *interp);

void
TkX_Main (int               argc,
          char            **argv,
          Tcl_AppInitProc  *appInitProc);

void
TclX_SetAppInfo (int   defaultValues,
                 char *appName,
                 char *appLongName,
                 char *appVersion,
                 int   appPatchlevel);

(and yes bestie, that int / void stack on TclX_Main is exactly how it's written up there. not me editing it. periodt. πŸ’…)


πŸ’… DESCRIPTION πŸ’…

these functions are how you initialize Extended Tcl, and also how you initialize apps that are built on top of Extended Tcl. this page ALSO spills the tea β˜• on the whole "how do I even integrate TclX into my other app" situation β€” multiple approaches, all discussed down below.


✨ Tclx_Init ✨

boots up Extended Tcl and adds the extended command set to the interpreter. you call this from Tcl_AppInit. important: it has to be called after the Tcl_Init function. and it's not just the standard command set β€” it also unlocks the use of tlib package libraries and makes the standard TclX library available. the full glow-up 🌸

Parameters

  • interp β€” a pointer to the interpreter you want to add the commands to.

Returns: TCL_OK if all is ok, TCL_ERROR if an error occurred.


πŸ¦‹ Tclxcmd_Init πŸ¦‹

adds the TclX command set to the interpreter β€” but minus the TclX library management commands. this is normally called by Tclx_Init itself, and you should only reach for it directly if you specifically don't want the TclX library handling. it's giving "diet TclX, but make it intentional" πŸ₯€

Parameters

  • interp β€” a pointer to the interpreter you want to add the commands to.

Returns: TCL_OK if all is ok, TCL_ERROR if an error occurred.


πŸ‘‘ TclX_Main πŸ‘‘

this function parses the command line according to the TclX shell specification (Unix shell compatible, iykyk). it creates an interpreter and calls the function you hand it, appInitProc, so you can initialize any app-specific commands of your own. after that it either evaluates the command or script specified on the command line, or drops into an interactive command loop.

heads up bestie: this procedure never returns β€” it exits the process when it's done. no coming back, it's the main character now πŸ‘‘

using the TclX shell ALSO gives you SIGINT handling in interactive shells. iconic behavior.


🧚 Tkx_Init 🧚

initializes the Extended Tcl Tk environment. you call this from Tcl_AppInit β€” and it goes after the Tk_Init function. order matters, bestie ✨

Parameters

  • interp β€” a pointer to the interpreter you want to add the commands to.

Returns: TCL_OK if all is ok, TCL_ERROR if an error occurred.


🌟 TkX_Main 🌟

this one parses the command line according to the wish shell specification. it creates an interpreter, calls the function you gave it, appInitProc, to initialize any app-specific commands, and then either evaluates the command or script specified on the command line or enters an interactive command loop.

again, runner: this procedure never returns β€” it exits the process when it's done.

using the TclX wish shell gets you SIGINT handling in interactive shells. other than that? it's identical to standard wish. same vibe, extra sparkle πŸ¦‹


πŸ’œ TclX_SetAppInfo πŸ’œ

stores the application information that gets returned by infox. it's the little name tag for your app πŸŽ€

Parameters

  • defaultValues β€” if true, then the values are assigned only if they're not already defined (i.e. defaulted). if false, the values are always set.
  • appName β€” application symbolic name.
  • appLongName β€” long, natural language application name.
  • appVersion β€” version number of the application.
  • appPatchlevel β€” patch level of the application. if less than zero, don't change.
⚠️ important, don't skip: string pointers are saved without copying β€” so do NOT release that memory. and if the arguments are NULL, the values don't change.

πŸ”₯ DYNAMIC LOADING OF TCLX πŸ”₯

TclX can be dynamically loaded on systems that support shared libraries and the load command. you can do this with either the load command or the package require commands.

if you're going the package require route, you need to construct a pkgIndex,tcl. here's the tea though: pkg_mkIndex does not generate a pkgIndex.tcl file that works with TclX. 😭

instead, a command similar to this one:

package ifneeded Tclx 7.5.0 "load $dir/libtclx.so"

should be placed in the directory containing the TclX shared library.

TclX also builds a prototype pkgIndex,tcl file and installs it in the run time directory under the name pkgIndex,proto. but it can't be used as-is! you should rename it and copy it, or combine it with an existing pkgIndex,tcl in the directory containing the shared library.

and lastly β€” there is no need to dynamically load libtkx.so, since it only contains support for wishx. save yourself the effort, bestie πŸ™ˆ


🌈 INTEGRATING TCLX WITH OTHER EXTENSIONS AND APPLICATIONS 🌈

the main thing to figure out here is whether your application is based on the standard Tcl/Tk shells or on the TclX shells. that's the whole vibe check.

if you want the standard shells? all you gotta do is call Tclx_Init after Tcl_Init and

Tkx_Init after Tk_Init.

and this functionality may also be dynamically loaded. easy ✨

to get the TclX shell in a Tcl-only application β€” with the tcl command functionality β€” call TclX_Main from the main function instead of Tcl_Main. this shell has arguments conforming to other Unix shells, plus SIGINT signal handling when interactive,. πŸ’…

to get the TclX shell in a Tk application β€” with the wishx command functionality β€” call TkX_Main from the main function instead of Tk_Main. this shell has SIGINT signal handling when interactive,


and that's the whole page, bestie!! 🫢 this came to you from the Tcl crew, filed under the TclXInit(3tcl) name β€” go forth and initialize something iconic πŸ‘‘πŸ’–

πŸ“¦ where this page comes from