Tcl\_Init(3) Tcl Library Procedures Tcl\_Init(3)

```

```

# [NAME](#NAME)

Tcl\_Init - find and source initialization script

# [SYNOPSIS](#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](#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](#DESCRIPTION)

**Tcl\_Init** is a helper procedure that finds and **source**s 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](#SEE_ALSO)

Tcl\_AppInit, Tcl\_Main

# [KEYWORDS](#KEYWORDS)

application, initialization, interpreter

9.0 Tcl

---

Document: Tcl_Init(3) from tcl 9.1.0-r2 (Chainguard OS)
Source: https://downloads.sourceforge.net/project/tcl/Tcl/9.1.0/tcl9.1.0-src.tar.gz
