Next: , Previous: , Up: Top   [Contents][Index]


5 Defining Variables

Rarely will you write a emodule that only contains functions. It is common to also provide variables which can be used to control the behaviour of functions or store a certain state or simply the results of a function being executed. The actual C variable types are the same for emodules and internal SXEmacs primitives, and the declaration of the variables is identical.

See Adding Global Lisp Variables in SXEmacs Internals Manual, for more information on variables and naming conventions.

Once your variables are defined and initialised properly, you need to make the Lisp reader aware of them. This is done in the specially treated init function of your emodule using special SXEmacs macros such as DEFVAR_LISP, DEFVAR_BOOL, DEFVAR_INT etc. The best way to see how to use these macros is to look at existing source code, or read the internals manual.

Below is a small example which declares and properly proclaims two variables. You will note that this code takes into account the fact that this emodule may very well be compiled into SXEmacs itself. This is a prudent thing to do.

Lisp_Object Vsample_string;
int sample_boolean;

void init(void)
{
        DEFVAR_LISP("sample-string", &Vsample_string /*
This is a sample string, declared in a module.

Nothing magical about it.
*/);

        DEFVAR_BOOL("sample-boolean", &sample_boolean /*
*Sample user-settable boolean.
*/);

        sample_boolean = 0;
        Vsample_string = build_string("My string");
}