1Tcl_AppInit(3)              Tcl Library Procedures              Tcl_AppInit(3)
2
3
4
5______________________________________________________________________________
6

NAME

8       Tcl_AppInit - perform application-specific initialization
9

SYNOPSIS

11       #include <tcl.h>
12
13       int
14       Tcl_AppInit(interp)
15

ARGUMENTS

17       Tcl_Interp *interp (in)          Interpreter for the application.
18______________________________________________________________________________
19
20

DESCRIPTION

22       Tcl_AppInit  is a “hook” procedure that is invoked by the main programs
23       for Tcl applications such as tclsh and wish.  Its purpose is  to  allow
24       new  Tcl applications to be created without modifying the main programs
25       provided as part of Tcl and Tk.  To create a new application you  write
26       a new version of Tcl_AppInit to replace the default version provided by
27       Tcl, then link your new Tcl_AppInit with the Tcl library.
28
29       Tcl_AppInit is invoked by Tcl_Main and Tk_Main after their own initial‐
30       ization  and  before  entering the main loop to process commands.  Here
31       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       [4]    Use the routines Tcl_SetStartupScript  and  Tcl_GetStartupScript
44              to  set  or query the file and encoding that the active Tcl_Main
45              or Tk_Main routine will use as a startup script.
46
47       Tcl_AppInit returns TCL_OK or TCL_ERROR.  If it returns TCL_ERROR  then
48       it must leave an error message in for the interpreter's result;  other‐
49       wise the result is ignored.
50
51       In addition to Tcl_AppInit, your application should also contain a pro‐
52       cedure main that calls Tcl_Main as follows:
53
54              Tcl_Main(argc, argv, Tcl_AppInit);
55
56       The  third  argument  to Tcl_Main gives the address of the application-
57       specific initialization procedure to invoke.  This means  that  you  do
58       not have to use the name Tcl_AppInit for the procedure, but in practice
59       the name is nearly always Tcl_AppInit (in versions before Tcl  7.4  the
60       name  Tcl_AppInit was implicit;  there was no way to specify the proce‐
61       dure explicitly).  The best way to get started is to make a copy of the
62       file tclAppInit.c from the Tcl library or source directory.  It already
63       contains a main procedure and a template for Tcl_AppInit that  you  can
64       modify for your application.
65
66

SEE ALSO

68       Tcl_Main(3)
69
70

KEYWORDS

72       application, argument, command, initialization, interpreter
73
74
75
76Tcl                                   7.0                       Tcl_AppInit(3)
Impressum