Next | Prev | Up | Top | Contents | Index

Other Features of dlopen

As a side effect of dlopen, a new command is automatically added to the interpreter--the name of the library. For example, the tclMotif library is opened by the command:

sgitcl>dlopen libtclMotif.so

This adds a new command libtclMotif.so, the sole function of which is to permit the calling of routines defined in the library, as shown in the example below.

sgitcl>libtclMotif.so call procedure args...

There are two types of routines that may be called: init routines and call routines.

The init routine has the following prototype:

int Init_Routine(Tcl_Interp* interp)

The interp argument is set to the interpreter pointer created by Tcl. To reference an init routine, type:

sgitcl>library-name init Init-routine

The call routine has the following prototype:

int Call_Routine(Tcl_Interp* interp, int argc, char* argv[])

The interp argument is the Tcl interpreter; argc is a count of arguments and argv is an array of argument strings with argc elements in the array. To call such a routine, type:

sgitcl>library-name call routine-name args...

Tcl will parse the args in the same way that command arguments are parsed, and pass them to the routine in argc and argv.

Both routine types should return TCL_OK if successful or TCL_ERROR if something went wrong. Additionally, your procedure should set interp->result to a descriptive error string. The return value of an init or call routine will be the value that your procedure places in interp->result, or the empty string if you fail to set a return value.

Note that dlopen allows an optional init or call to follow the library name:

sgitcl>dlopen libname.so init init-routine


Next | Prev | Up | Top | Contents | Index