A dynamic Emacs module is a shared library that provides additional functionality for use in Emacs Lisp programs, just like a package written in Emacs Lisp would.
Functions that load Emacs Lisp packages can also load dynamic modules. They recognize dynamic modules by looking at their file-name extension, a.k.a. “suffix”. This suffix is platform-dependent.
This variable holds the system-dependent value of the file-name extension of the module files. Its value is .so on POSIX hosts, .dylib on macOS, and .dll on MS-Windows.
On macOS, dynamic modules can also have the suffix .so in addition to .dylib.
Every dynamic module should export a C-callable function named
emacs_module_init, which Emacs will call as part of the call to
require which loads the module. It should also
export a symbol named
plugin_is_GPL_compatible to indicate that
its code is released under the GPL or compatible license; Emacs will
signal an error if your program tries to load modules that don’t
export such a symbol.
If a module needs to call Emacs functions, it should do so through the API (Application Programming Interface) defined and documented in the header file emacs-module.h that is part of the Emacs distribution. See Writing Dynamically-Loaded Modules, for details of using that API when writing your own modules.
Modules can create
user-ptr Lisp objects that embed pointers to
C struct’s defined by the module. This is useful for keeping around
complex data structures created by a module, to be passed back to the
module’s functions. User-ptr objects can also have associated
finalizers – functions to be run when the object is GC’ed; this
is useful for freeing any resources allocated for the underlying data
structure, such as memory, open file descriptors, etc. See Conversion Between Lisp and Module Values.
This function returns
t if its argument is a
Emacs calls this low-level primitive to load a module from the
specified file and perform the necessary initialization of the
module. This is the primitive which makes sure the module exports the
plugin_is_GPL_compatible symbol, calls the module’s
emacs_module_init function, and signals an error if that
function returns an error indication, or if the user typed C-g
during the initialization. If the initialization succeeds,
t. Note that file must
already have the proper file-name extension, as this function doesn’t
try looking for files with known extensions, unlike
module-load doesn’t record the module in
load-history, doesn’t print any messages, and doesn’t protect
against recursive loads. Most users should therefore use
require instead of
Loadable modules in Emacs are enabled by using the --with-modules option at configure time.