---
name: "Ns_TclInitModule"
section: "3aolserver"
platform: "linux"
package: "aolserver4-dev"
version: "4.5.1-18.1"
release: "Debian 9 (Stretch)"
platforms: ["linux"]
url: "https://new.carta.tech/Ns_TclInitInterps/3aolserver"
---

# Ns\_TclInitModule(3aolserver)

library procedures

Part of [Ns\_TclInitInterps(3aolserver)](/Ns_TclInitInterps/3aolserver.md).

```

```

## NAME

Ns\_TclInitInterps, Ns\_TclInitModule, Ns\_TclInterpServer, Ns\_TclLibrary - library procedures

## SYNOPSIS

```
#include "ns.h"

int
Ns_TclInitInterps(server, initProc, arg)

Ns_TclInitModule(arg, arg)

char *
Ns_TclInterpServer(interp)

char *
Ns_TclLibrary(void)
```

## ARGUMENTS

- char *\*server* (in)

  Name of virtual server.

- Ns\_TclInterpInitProc *\*initProc* (in)

  Procedure to call to initialize interps.

- void *\*arg* (in)

  Callback data to pass to *initProc*.

- Tcl\_Interp *\*interp* (in)

  Tcl interp to get server.

  ```

  ```

## DESCRIPTION

**Ns\_TclInitInterps** arranges for *initProc* to be  called on the startup initialization interp. *initProc* should have arguments and result that match the type *Ns\_TclInterpInitProc*:

```
typedef int Ns_TclInterpInitProc(Tcl_Interp *interp, void *arg);
```

The *arg* parameter to *initProc* is a copy of the *arg* argument given to **Ns\_TclInitInterps**. A typical *initProc* will create new commands in the given interp with Tcl\_CreateCommand. The following AOLserver module example results in the *msg* command being in all interps.  The command simply sets the "hello" static string as the interp result:

```
static Ns_TclInterpInitProc AddCmds;
static Tcl_CmdProc MsgCmd;
int
Ns_ModuleInit(char *server, char *module)
{
    static char *arg = "hello";
    return Ns_TclInitInterps(server, AddCmds, arg);
}
static int
AddCmds(Tcl_Interp *interp, void *arg)
{
    Tcl_CreateCommand(interp, "msg", MsgCmd, arg, NULL);
    return TCL_OK;
}
static int
MsgCmd(ClientData arg, Tcl_Interp *interp, int argc, char **argv)
{
    Tcl_SetResult(interp, (char *) arg, TCL_STATIC);
    return TCL_OK;
}
```

In AOLserver 3.x, the effect of **Ns\_TclInitInterps** is to invoke *initProc* immediately on the single initializaton interp of the server and the result of **Ns\_TclInitInterps** is the return code of *initProc*.  The state of this interp (command, procedures) will then be copied to other interps when created via the **Ns\_TclAllocInterp** routine.  This differs from the original AOLserver 2.0 where *initProc* was called on each interp in an interp pool, the 2.1-2.3 behavior where *initProc* was called once on an interp linked to the per-server shared command tables, and the upcoming 4.0 behavior where *initProc* is called at interp create time.  In fact, the 4.0 behavior is that of the **Ns\_TclRegisterAtCreate** routine.  In practice, if your *initProc* **does nothing but create commands with NULL or shared** **client data the effect is the same in all releases.**

**Ns\_TclInterpServer** returns the virtual server in which the given interp was created.

**Ns\_TclLibrary** returns the shared Tcl library of the server installation (e.g., /usr/local/aolserver/modules/tcl).

## SEE ALSO

[Ns\_TclRegisterAtCreate(3)](/Ns_TclRegisterAtCreate/3.md), Ns\_TclAllocInterp(3)

## KEYWORDS
