Next: Module Nonlocal, Previous: Module Values, Up: Writing Dynamic Modules
This subsection describes a few convenience functions provided by
the module API. Like the functions described in previous
subsections, all of them are actually function pointers, and need to
be called via the emacs_env pointer. Description of functions
that were introduced after Emacs 25 calls out the first version where
they became available.
This function returns
trueif the Lisp objects represented by val1 and val2 are identical,falseotherwise. This is the same as the Lisp functioneq(see Equality Predicates), but avoids the need to intern the objects represented by the arguments.There are no API functions for other equality predicates, so you will need to use
internandfuncall, described below, to perform more complex equality tests.
This function tests whether the Lisp object represented by val is non-
nil; it returnstrueorfalseaccordingly.Note that you could implement an equivalent test by using
internto get anemacs_valuerepresentingnil, then useeq, described above, to test for equality. But using this function is more convenient.
object)This function returns the type of object as a value that represents a symbol:
stringfor a string,integerfor an integer,processfor a process, etc. See Type Predicates. You can useinternandeqto compare against known type symbols, if your code needs to depend on the object type.
This function returns an interned Emacs symbol whose name is name, which should be an ASCII null-terminated string. It creates a new symbol if one does not already exist.
Together with
funcall, described below, this function provides a means for invoking any Lisp-callable Emacs function, provided that its name is a pure ASCII string. For example, here's how to intern a symbol whose namename_stris non-ASCII, by calling the more powerful Emacsinternfunction (see Creating Symbols):emacs_value fintern = env->intern (env, "intern"); emacs_value sym_name = env->make_string (env, name_str, strlen (name_str)); emacs_value intern_args[] = { sym_name, env->intern (env, "nil") }; emacs_value symbol = env->funcall (env, fintern, 2, intern_args);
This function calls the specified func passing it nargs arguments from the array pointed to by args. The argument func can be a function symbol (e.g., returned by
interndescribed above), a module function returned bymake_function(see Module Functions), a subroutine written in C, etc. If nargs is zero, args can be aNULLpointer.The function returns the value that func returned.
If your module includes potentially long-running code, it is a good idea to check from time to time in that code whether the user wants to quit, e.g., by typing C-g (see Quitting). The following function, which is available since Emacs 26.1, is provided for that purpose.