Diff
Not logged in

Differences From Artifact [1f25effdd6]:

To Artifact [97e907519f]:


23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
\fBTcl_InitSubsystems\fR(\fIflags\fR, \fI...\fR)
.SH ARGUMENTS
.AS char *argv0
.AP char *argv0 in
The first command-line argument to the program, which gives the
application's name.
.AP int flags in
Any combination of TCL_INIT_PANIC or TCL_INIT_CREATE, which indicate
whether a custom panicProc is registered and/or a real interpreter is created.
The value 0 can be used if Tcl is used as utility library only.
.BE

.SH DESCRIPTION
.PP
The \fBTcl_FindExecutable\fR procedure computes the full path name of
the executable file from which the application was invoked and saves







|
|







23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
\fBTcl_InitSubsystems\fR(\fIflags\fR, \fI...\fR)
.SH ARGUMENTS
.AS char *argv0
.AP char *argv0 in
The first command-line argument to the program, which gives the
application's name.
.AP int flags in
Any combination of flags which indicate whether a custom panicProc
is registered and/or a real interpreter is created.
The value 0 can be used if Tcl is used as utility library only.
.BE

.SH DESCRIPTION
.PP
The \fBTcl_FindExecutable\fR procedure computes the full path name of
the executable file from which the application was invoked and saves
75
76
77
78
79
80
81


82
83
84
85
86

87
88
89
90



91
92
93
94
95




96

97
98
99
100


101
102

103
104
105
106
107
108










109
110
111
112
113
is returned which can be used only by \fBTcl_InitStubs\fR
to initialize the stub table. This opens up the Tcl Stub
technology for Tcl embedders, which now can dynamically
load the Tcl shared library and use functions in it
without ever creating an interpreter. E.g. the
following code can be compiled with -DUSE_TCL_STUBS:
.CS


    handle = dlopen("libtcl8.6.so", RTLD_NOW|RTLD_LOCAL);
    initSubSystems = dlsym(handle, "Tcl_InitSubsystems");
    interp = initSubSystems(0); /* not a real interpreter */
    Tcl_InitStubs(interp, NULL, 0); /* initialize the stub table */
    interp = Tcl_CreateInterp(); /* now we have a real interpreter */

.CE
The function \fBTcl_CreateInterp\fR, or any other Tcl function you
would like to call, no longer needs to be searched for in the
shared library. It can be called directly though the stub table. 



.PP
If you supply the flag TCL_INIT_PANIC to \fBTcl_InitSubsystems\fR,
the function expects an additional argument, a custom panicProc.
This is equivalent to calling \fBTcl_SetPanicProc\fR immediately
before \fBTcl_InitSubsystems\fR.




.PP

If you supply the flag TCL_INIT_CREATE to \fBTcl_InitSubsystems\fR,
the function gets two additional parameters, argc and argv. A real
Tcl interpreter will be created and if argc > 0 then the variables
"argc" and "argv" will be set in this interpreter. So, the above


example code could be simplified to:
.CS

    handle = dlopen("libtcl8.6.so", RTLD_NOW|RTLD_LOCAL);
    initSubSystems = dlsym(handle, "Tcl_InitSubsystems");
    interp = initSubSystems(TCL_INIT_CREATE, 0, NULL); /* real interpreter */
    Tcl_InitStubs(interp, NULL, 0); /* initialize the stub table */
.CE
.PP










The interpreter returned by Tcl_InitSubsystems(0) cannot be passed to
any other function than Tcl_InitStubs(). Tcl functions with an "interp"
argument can only be called if this function supports passing NULL.
.SH KEYWORDS
binary, executable file







>
>
|

|
|
|
>



|
>
>
>




|
>
>
>
>

>
|
|
|
|
>
>
|

>
|

|



>
>
>
>
>
>
>
>
>
>


|


75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
is returned which can be used only by \fBTcl_InitStubs\fR
to initialize the stub table. This opens up the Tcl Stub
technology for Tcl embedders, which now can dynamically
load the Tcl shared library and use functions in it
without ever creating an interpreter. E.g. the
following code can be compiled with -DUSE_TCL_STUBS:
.CS
    Tcl_Interp *interp, *(*initSubSystems)(int, ...)
    const char *version;
    void *handle = dlopen("libtcl8.6.so", RTLD_NOW|RTLD_LOCAL);
    initSubSystems = dlsym(handle, "Tcl_InitSubsystems");
    interp = initSubSystems(0); /* Not a real interpreter */
    version = Tcl_InitStubs(interp, NULL, 0); /* initialize the stub table */
    interp = Tcl_CreateInterp(); /* Now we have a real interpreter */
    Tcl_InitStubs(interp, version, 0); /* Initialize the stub table again */
.CE
The function \fBTcl_CreateInterp\fR, or any other Tcl function you
would like to call, no longer needs to be searched for in the
shared library. It can be called directly though the stub table.
Note that the stub table needs to be initialized twice, in order
to be sure that you can call all functions without limitations
after the real interpreter is created.
.PP
If you supply the flag TCL_INIT_PANIC to \fBTcl_InitSubsystems\fR,
the function expects an additional argument, a custom panicProc.
This is equivalent to calling \fBTcl_SetPanicProc\fR immediately
before \fBTcl_InitSubsystems\fR, except that you possibly cannot do
that yet if it requires an initialized stub table. Of course you
could call \fBTcl_SetPanicProc\fR immediately after \fBTcl_InitSubsystems\fR,
but then panics which could be produced by the initialization
itself still use the default panic procedure. 
.PP
If you supply one of the flags TCL_INIT_CREATE, TCL_INIT_CREATE_UTF8 or
TCL_INIT_CREATE_UNICODE to \fBTcl_InitSubsystems\fR, the function
gets two additional parameters, argc and argv. Then a real
Tcl interpreter will be created. If argc > 0 then the variables
\fBargc\fR and \fBargv\fR will be set in this interpreter. The 3
variants assume a different encoding for the arguments, except for
\fIargv[0]\fR which is always assumed to be in the system encoding.
So, the above example code could be simplified to:
.CS
    Tcl_Interp *interp, *(*initSubSystems)(int, ...)
    void *handle = dlopen("libtcl8.6.so", RTLD_NOW|RTLD_LOCAL);
    initSubSystems = dlsym(handle, "Tcl_InitSubsystems");
    interp = initSubSystems(TCL_INIT_CREATE, 0, NULL); /* Real interpreter */
    Tcl_InitStubs(interp, NULL, 0); /* initialize the stub table */
.CE
.PP
The reason for argv0 always using the system encoding is that this way,
argv0 can be derived directly from the main() (or mainw, on Windows)
arguments without any processing. TCL_INIT_CREATE_UNICODE is really only
useful on Windows. But on Windows, the argv0 parameter is not used for
determining the value of [info executable] anyway. Modern UNIX system already
have UTF-8 as system encoding, so TCL_INIT_CREATE_UTF8 would have the same
effect as TCL_INIT_CREATE, only slightly faster. Other parameters can be
preprocessed at will by the application, and if the application uses unicode
or utf-8 internally there is no need to convert it back to the system encoding.
.PP
The interpreter returned by Tcl_InitSubsystems(0) cannot be passed to
any other function than Tcl_InitStubs(). Tcl functions with an "interp"
argument can only be called if the function supports passing NULL.
.SH KEYWORDS
binary, executable file