Scroll to navigation

Tcl_Init(3tcl) Tcl Library Procedures Tcl_Init(3tcl)


NAME

Tcl_Init - find and source initialization script

SYNOPSIS

#include <tcl.h>

int
Tcl_Init(interp)

const char *
Tcl_SetPreInitScript(scriptPtr)

typedef int Tcl_PostInitProc(Tcl_Interp *interp, void *clientData)

int
Tcl_RegisterPostInitProc(postInitProc, clientData)

int
Tcl_UnregisterPostInitProc(postInitProc, clientData)

int
Tcl_ClearPostInitProcs(void)

ARGUMENTS

Tcl_Interp *interp (in)
Interpreter to initialize.
const char *scriptPtr (in)
Address of the initialization script.
Tcl_PostInitProc *postInitProc (in)
Function to call post initialization of interpreter.
void *clientData (in)
Arbitrary one-word value to pass to postInitProc.
    

DESCRIPTION

Tcl_Init is a helper procedure that finds and sources the init.tcl script, which should exist somewhere on the Tcl library path.

Tcl_Init is typically called from Tcl_AppInit procedures.

Tcl_SetPreInitScript registers the pre-initialization script and returns the former (now replaced) script pointer. A value of NULL may be passed to not register any script. The pre-initialization script is executed by Tcl_Init before accessing the file system. The purpose is to typically prepare a custom file system (like an embedded zip-file) to be activated before the search.

Tcl_RegisterPostInitProc registers a callback that should be invoked by Tcl_Init at the end of initialization of subsequently created interpreters except safe interpreters. The function returns a Tcl return code.

This callback function is passed the interpreter being initialized and the opaque clientData value that was passed at the time of registration. It should return a Tcl return code. Multiple callbacks are supported and will be invoked in the order of their registration except that an error return from a callback will skip the remaining registrations. The Tcl return code from the last callback invoked is returned as the return value from Tcl_Init.

Tcl_UnregisterPostInitProc unregisters a previously registered callback. Both postInitProc and clientData must match the the corresponding values that were passed to Tcl_RegisterPostInitProc. The function returns a standard Tcl return code. It is not an error if there is no matching prior registration.

The Tcl_ClearPostInitProcs function unregisters all currently registered callbacks.

Callback functions registered through Tcl_RegisterPostInitProc may load static packages, add commands, or set up other facilities so they are available in all interpreters. They cannot however execute any code that may result in new interpreters and should not delete the passed interpreter.

The `Tcl_RegisterPostInitProc` and `Tcl_UnregisterPostInitProc` functions may be invoked from within a registered callback. However, the change in registration will not have effect for the interpreter that is being initialized.

When used in stub-enabled embedders, the stubs table must be first initialized using one of Tcl_InitSubsystems, Tcl_SetPanicProc, Tcl_FindExecutable or TclZipfs_AppHook before Tcl_SetPreInitScript may be called.

SEE ALSO

Tcl_AppInit, Tcl_Main

KEYWORDS

application, initialization, interpreter

9.0 Tcl