1Tcl_AppInit(3) Tcl Library Procedures Tcl_AppInit(3)
2
3
4
5______________________________________________________________________________
6
8 Tcl_AppInit - perform application-specific initialization
9
11 #include <tcl.h>
12
13 int
14 Tcl_AppInit(interp)
15
17 Tcl_Interp *interp (in) Interpreter for the application.
18_________________________________________________________________
19
20
22 Tcl_AppInit is a ``hook'' procedure that is invoked by the main pro‐
23 grams for Tcl applications such as tclsh and wish. Its purpose is to
24 allow new Tcl applications to be created without modifying the main
25 programs provided as part of Tcl and Tk. To create a new application
26 you write a new version of Tcl_AppInit to replace the default version
27 provided by Tcl, then link your new Tcl_AppInit with the Tcl library.
28
29 Tcl_AppInit is invoked after by Tcl_Main and Tk_Main after their own
30 initialization and before entering the main loop to process commands.
31 Here are some examples of things that Tcl_AppInit might do:
32
33 [1] Call initialization procedures for various packages used by the
34 application. Each initialization procedure adds new commands to
35 interp for its package and performs other package-specific ini‐
36 tialization.
37
38 [2] Process command-line arguments, which can be accessed from the
39 Tcl variables argv and argv0 in interp.
40
41 [3] Invoke a startup script to initialize the application.
42
43 Tcl_AppInit returns TCL_OK or TCL_ERROR. If it returns TCL_ERROR then
44 it must leave an error message in for the interpreter's result; other‐
45 wise the result is ignored.
46
47 In addition to Tcl_AppInit, your application should also contain a pro‐
48 cedure main that calls Tcl_Main as follows:
49 Tcl_Main(argc, argv, Tcl_AppInit);
50 The third argument to Tcl_Main gives the address of the application-
51 specific initialization procedure to invoke. This means that you don't
52 have to use the name Tcl_AppInit for the procedure, but in practice the
53 name is nearly always Tcl_AppInit (in versions before Tcl 7.4 the name
54 Tcl_AppInit was implicit; there was no way to specify the procedure
55 explicitly). The best way to get started is to make a copy of the file
56 tclAppInit.c from the Tcl library or source directory. It already con‐
57 tains a main procedure and a template for Tcl_AppInit that you can mod‐
58 ify for your application.
59
60
62 application, argument, command, initialization, interpreter
63
64
65
66Tcl 7.0 Tcl_AppInit(3)