Tcl_AppInit(3tcl)
β¨ Tcl_AppInit(3tcl) β¨
okay bestie, welcome to the Tcl Library Procedures section 3tcl, and today's main character is Tcl_AppInit π
πΈ NAME πΈ
Tcl_AppInit β do the application-specific initialization, no cap
π SYNOPSIS π
#include <tcl.h>
int
Tcl_AppInit(interp)
π¦ ARGUMENTS π¦
Tcl_Interp *interp(in) β the interpreter for the application, bestie. that's it, that's the whole argument list, we love a low-maintenance icon π«Ά
π DESCRIPTION π
so Tcl_AppInit is a βhookβ procedure, right? like, the main programs for Tcl applications β think tclsh and wish β they call it. its whole vibe is letting you build brand-new Tcl applications without touching the main programs that ship as part of Tcl and Tk. iconic behaviour honestly β¨
to make your own application, you write a fresh version of Tcl_AppInit to replace the default one Tcl gives you, and then you link your new Tcl_AppInit with the Tcl library. that's the whole ritual π―οΈ
Tcl_AppInit gets invoked by Tcl_Main and Tk_Main after their own initialization and before they hop into the main loop to process commands. and like, here are some things it might do:
- call the initialization procedures for the various packages your application uses. each initialization procedure adds new commands to
interpfor its package, and does whatever other package-specific setup it needs. slay π - process command-line arguments β you can grab those from the Tcl variables
argvandargv0ininterp. - invoke a startup script to initialize the application. get it set up, get it cute π
- use the routines
Tcl_SetStartupScriptandTcl_GetStartupScriptto set or query the file and encoding that the activeTcl_MainorTk_Mainroutine will use as a startup script. very "who's the one in charge here" energy.
Tcl_AppInit returns TCL_OK or TCL_ERROR. and listen β if it returns TCL_ERROR, then it must leave an error message in for the interpreter's result. otherwise the result just gets ignored, no thoughts, head empty π
β οΈ okay this part matters, so pay attention bestie: if you return TCL_ERROR and don't leave that error message for the interpreter's result, that's on you. the manual says must. must means must. π
in addition to Tcl_AppInit, your application should also have a procedure main that calls Tcl_Main like this:
Tcl_Main(argc, argv, Tcl_AppInit);
the third argument to Tcl_Main is the address of the application-specific initialization procedure to invoke. which means β plot twist β you do not actually have to name your procedure Tcl_AppInit. in practice though? it's nearly always named Tcl_AppInit. (in versions before Tcl 7.4 the name Tcl_AppInit was implicit; there was literally no way to specify the procedure explicitly. ancient history, but we respect the lore π)
the best way to get started, fr fr, is to make a copy of the file tclAppInit.c from the Tcl library or source directory. it already contains a main procedure and a template for Tcl_AppInit that you can modify for your application. free starter kit, take it, it's yours π
π SEE ALSO π
β KEYWORDS β
application, argument, command, initialization, interpreter
and that's the page, bestie!! this one's from the Tcl 7.0 era of the Tcl manual β vintage, but the vibes are timeless. go forth and initialize your application, you've got this π
π¦ where this page comes from
- debian trixie: tcl9.0-doc 9.0.1+dfsg-2
- ubuntu questing: tcl9.0-doc 9.0.2+dfsg-1
- ubuntu resolute: tcl9.0-doc 9.0.3+dfsg-1
- ubuntu stonking: tcl9.0-doc 9.0.4+dfsg-1
- 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