Tcl_AppInit(3)
β¨ Tcl_AppInit(3) β the Tcl Library Procedures glow-up β¨
okay so bestie, we're in the Tcl Library Procedures section of the manual, and today's main character is Tcl_AppInit π
π NAME π
Tcl_AppInit β do your app's own lil setup moment, fr fr
πΈ SYNOPSIS πΈ
#include <tcl.h>
int
Tcl_AppInit(interp)
π¦ ARGUMENTS π¦
Tcl_Interp *interp(in) β the interpreter for the application π«Ά
π DESCRIPTION π
Tcl_AppInit is a "hook" procedure, bestie. Like, it's the little callback that the main programs for Tcl applications (think tclsh and wish, the icons π) invoke when they're getting everything going.
The whole point? It lets you build brand-new Tcl applications without touching the main programs that ship as part of Tcl and Tk. So to make your own app you just write a new version of Tcl_AppInit to replace the default one Tcl gives you, then link your new Tcl_AppInit with the Tcl library. that's it, that's the vibe β¨
Tcl_AppInit gets invoked by Tcl_Main and Tk_Main after they've done their own initialization, and before they head into the main loop to process commands. no cap.
Here's the kind of stuff Tcl_AppInit might get up to:
- Call initialization procedures for the various packages your application uses. Each init procedure adds new commands to
interpfor its package and does other package-specific setup π§ - Process command-line arguments β you can grab those from the Tcl variables
argvandargv0insideinterpπ - Invoke a startup script to initialize the application.
- Use the routines
Tcl_SetStartupScriptandTcl_GetStartupScriptto set or query the file and encoding that the activeTcl_MainorTk_Mainroutine will use as a startup script π
Tcl_AppInit returns TCL_OK or TCL_ERROR. And listen β if it returns TCL_ERROR, it must leave an error message in the interpreter's result. Otherwise the result just gets ignored, no biggie.
β οΈ okay this part matters: TCL_ERROR with no error message left in the result is a whole mess. leave the message. periodt.
In addition to Tcl_AppInit, your application should also contain a procedure main that calls Tcl_Main, like this:
Tcl_Main(argc, argv, Tcl_AppInit);
That third argument to Tcl_Main is the address of the application-specific initialization procedure to invoke. Which means β plot twist β you don't actually have to name it Tcl_AppInit! But in practice it's nearly always named Tcl_AppInit (iykyk). In versions before Tcl 7.4 the name Tcl_AppInit was implicit, and there was literally no way to specify the procedure explicitly. wild π
The best way to get started is to make a copy of the file tclAppInit.c from the Tcl library or source directory. It already has a main procedure and a template for Tcl_AppInit that you can modify for your own application. copy-paste-and-thrive, that's the strategy π
π₯ SEE ALSO π₯
π KEYWORDS π
application, argument, command, initialization, interpreter
and that's the whole page, bestie π this was Tcl_AppInit(3) from the Tcl 7.0 era of the Tcl manual β written by the Tcl crew, living in the Tcl Library Procedures chapter, and honestly? iconic. go forth and write your own init procedure, you've got this π«Άβ¨
π¦ 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) 1993 The Regents of the University of California
- Copyright (c) 1994-1996 Sun Microsystems, Inc
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms