comparison modules/sample/external/sample.c @ 996:25e260cb7994

[xemacs-hg @ 2002-09-10 15:27:02 by james] Enable unloading of dynamic modules. Create the first two internal XEmacs modules: LDAP and postgreSQL. Update the sample directory to contain a sample internal XEmacs module and a sample external XEmacs module. Improve support for autoloading modules. Make internal module code compile into the XEmacs binary if XEmacs is configured without module support. Make the internal module directories self-contained so that they can be distributed separately from XEmacs.
author james
date Tue, 10 Sep 2002 15:27:39 +0000
parents
children dce479915b74
comparison
equal deleted inserted replaced
995:4575a219af58 996:25e260cb7994
1 /*
2 * Very simple sample module. Illustrates most of the salient features
3 * of Emacs dynamic modules.
4 * (C) Copyright 1998, 1999 J. Kean Johnston. All rights reserved.
5 * (C) Copyright 2002 Jerry James.
6 */
7
8 #include <config.h>
9 #include "lisp.h"
10
11 /*
12 * This sample introduces three new Lisp objects to the Lisp reader.
13 * The first, a simple boolean value, and the second a string. The
14 * Third is a sample function that simply prints a message.
15 */
16 int sample_bool;
17 Lisp_Object Vsample_string;
18
19 DEFUN ("sample-function", Fsample_function, 0, 0, "", /*
20 This is a sample function loaded dynamically.
21
22 You will notice in the source code for this module that the
23 declaration is identical to internal Emacs functions. This
24 makes it possible to use the exact same code in a dumped
25 version of Emacs.
26 */
27 ())
28 {
29 message ("Eureka! It worked");
30 return Qt;
31 }
32
33 /*
34 * Each dynamically loaded Emacs module is given a name at compile
35 * time. This is a short name, and must be a valid part of a C
36 * identifier. This name is used to construct the name of several
37 * functions which must appear in the module source code.
38 * The first such function, modules_of_XXXX, should load in any dependent
39 * modules. This function is optional, and the module will still load if
40 * it is not present in the module.
41 *
42 * The second function, which is NOT optional, is syms_of_XXXX, in which
43 * all functions that the module will be provided are declared. This
44 * function will contain calls to DEFSUBR().
45 *
46 * The third function, which is also NOT optional, is vars_of_XXXX, in
47 * which you declare all variables that the module provides. This
48 * function will contain calls to DEFVAR_LISP(), DEFVAR_BOOL() etc.
49 *
50 * When declaring functions and variables in the syms_of_XXXX and
51 * vars_of_XXXX functions, you use the exact same syntax that you
52 * would as if this module were being compiled into the pure Emacs.
53 *
54 * The fourth function, which is optional, is unload_XXXX, in which actions
55 * that must be taken to unload the module are listed. XEmacs will unbind
56 * functions and variables for you. Anything else that must be done should
57 * appear in this function.
58 *
59 * All four of these functions are declared as void functions,
60 * taking no parameters. Since this sample module is called 'sample',
61 * the functions will be named 'modules_of_sample', 'syms_of_sample',
62 * 'vars_of_sample', and 'unload_sample'.
63 */
64
65 void
66 modules_of_sample()
67 {
68 /*
69 * This function isn't actually required as we will not be loading
70 * in any dependent modules, but if we were, we would do something like:
71 * emodules_load ("dependent.ell", "sample2", "1.0.0");
72 */
73 }
74
75 void
76 syms_of_sample()
77 {
78 DEFSUBR(Fsample_function);
79 }
80
81 void
82 vars_of_sample()
83 {
84 DEFVAR_LISP ("sample-string", &Vsample_string /*
85 This is a sample string, declared in a dynamic module.
86
87 The syntax and conventions used for all normal Emacs variables
88 apply equally to modules, using an identical syntax.
89 */ );
90
91 DEFVAR_BOOL ("sample-boolean", &sample_bool /*
92 *Sample boolean value, in a dynamic module.
93
94 This is a user-settable variable, as indicated by the *
95 as the first character of the description. Declared in
96 a module exactly as it would be internally in Emacs.
97 */ );
98 }
99
100 #ifdef HAVE_SHLIB
101 void
102 unload_sample()
103 {
104 /* We don't need to do anything here in the sample case. However, if you
105 create any new types with INIT_LRECORD_IMPLEMENTATION (sample_type), then
106 UNDEF_LRECORD_IMPLEMENTATION (sample_type) must appear here. Also, any
107 symbols declared with DEFSYMBOL (Qsample_var), or one of its variants,
108 must have a corresponding unstaticpro_nodump (&Qsample_var) here. */
109 }
110 #endif