3 Copyright (C) 2015 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
21 #ifndef EMACS_MODULE_H
22 #define EMACS_MODULE_H
29 #define EMACS_EXTERN_C_BEGIN extern "C" {
30 #define EMACS_EXTERN_C_END }
32 #define EMACS_EXTERN_C_BEGIN
33 #define EMACS_EXTERN_C_END
36 #if defined(__cplusplus) && __cplusplus >= 201103L
37 #define EMACS_NOEXCEPT noexcept
39 #define EMACS_NOEXCEPT
44 /* Current environement */
45 typedef struct emacs_env_25 emacs_env
;
47 /* Opaque structure pointer representing an Emacs Lisp value */
48 typedef struct emacs_value_tag
* emacs_value
;
51 emacs_variadic_function
= -2
54 /* Struct passed to a module init function (emacs_module_init) */
55 struct emacs_runtime
{
56 /* Structure size (for version checking) */
59 /* Private data; users should not touch this */
60 struct emacs_runtime_private
*private_members
;
62 /* Returns an environment pointer. */
63 emacs_env
* (*get_environment
)(struct emacs_runtime
*ert
);
67 /* Function prototype for the module init function */
68 typedef int (*emacs_init_function
)(struct emacs_runtime
*ert
);
70 /* Function prototype for the module Lisp functions */
71 typedef emacs_value (*emacs_subr
)(emacs_env
*env
,
76 /* Function prototype for module user-pointer finalizers */
77 typedef void (*emacs_finalizer_function
)(void*);
79 /* Possible Emacs function call outcomes. */
80 enum emacs_funcall_exit
{
81 /* Function has returned normally. */
82 emacs_funcall_exit_return
= 0,
83 /* Function has signaled an error using `signal'. */
84 emacs_funcall_exit_signal
= 1,
85 /* Function has exit using `throw'. */
86 emacs_funcall_exit_throw
= 2,
91 * Structure size (for version checking)
96 /* Private data; users should not touch this */
97 struct emacs_env_private
*private_members
;
104 emacs_value (*make_global_ref
)(emacs_env
*env
,
105 emacs_value any_reference
);
107 void (*free_global_ref
)(emacs_env
*env
,
108 emacs_value global_reference
);
111 * Non-local exit handling
114 enum emacs_funcall_exit (*non_local_exit_check
)(emacs_env
*env
);
116 void (*non_local_exit_clear
)(emacs_env
*env
);
118 enum emacs_funcall_exit (*non_local_exit_get
)(emacs_env
*env
,
119 emacs_value
*non_local_exit_symbol_out
,
120 emacs_value
*non_local_exit_data_out
);
122 void (*non_local_exit_signal
)(emacs_env
*env
,
123 emacs_value non_local_exit_symbol
,
124 emacs_value non_local_exit_data
);
126 void (*non_local_exit_throw
)(emacs_env
*env
,
131 * Function registration
134 emacs_value (*make_function
)(emacs_env
*env
,
137 emacs_value (*function
)(emacs_env
*, int, emacs_value
*, void*) EMACS_NOEXCEPT
,
138 const char *documentation
,
141 emacs_value (*funcall
)(emacs_env
*env
,
142 emacs_value function
,
146 emacs_value (*intern
)(emacs_env
*env
,
147 const char *symbol_name
);
153 emacs_value (*type_of
)(emacs_env
*env
,
156 bool (*is_not_nil
)(emacs_env
*env
, emacs_value value
);
158 bool (*eq
)(emacs_env
*env
, emacs_value a
, emacs_value b
);
160 int64_t (*extract_integer
)(emacs_env
*env
,
163 emacs_value (*make_integer
)(emacs_env
*env
,
166 double (*extract_float
)(emacs_env
*env
,
169 emacs_value (*make_float
)(emacs_env
*env
,
173 * Copy the content of the lisp string VALUE to BUFFER as an utf8
174 * null-terminated string.
176 * SIZE must point to the total size of the buffer. If BUFFER is
177 * NULL or if SIZE is not big enough, write the required buffer size
178 * to SIZE and return false.
180 * Note that SIZE must include the last null byte (e.g. "abc" needs
181 * a buffer of size 4).
183 * Returns true if the string was successfully copied.
186 bool (*copy_string_contents
)(emacs_env
*env
,
192 * Create a lisp string from a utf8 encoded string.
194 emacs_value (*make_string
)(emacs_env
*env
,
195 const char *contents
, size_t length
);
198 * Embedded pointer type
200 emacs_value (*make_user_ptr
)(emacs_env
*env
,
201 void (*fin
)(void *) EMACS_NOEXCEPT
,
204 void* (*get_user_ptr
)(emacs_env
*env
, emacs_value uptr
);
205 void (*set_user_ptr
)(emacs_env
*env
, emacs_value uptr
, void *ptr
);
207 void (*(*get_user_finalizer
)(emacs_env
*env
, emacs_value uptr
))(void *) EMACS_NOEXCEPT
;
208 void (*set_user_finalizer
)(emacs_env
*env
,
210 void (*fin
)(void *) EMACS_NOEXCEPT
);
215 emacs_value (*vec_get
) (emacs_env
*env
,
219 void (*vec_set
) (emacs_env
*env
,
224 size_t (*vec_size
) (emacs_env
*env
,
230 #endif /* EMACS_MODULE_H */