diff options
Diffstat (limited to 'src/emacs_module.h')
| -rw-r--r-- | src/emacs_module.h | 175 |
1 files changed, 175 insertions, 0 deletions
diff --git a/src/emacs_module.h b/src/emacs_module.h new file mode 100644 index 00000000000..2dbb2a2f5ce --- /dev/null +++ b/src/emacs_module.h | |||
| @@ -0,0 +1,175 @@ | |||
| 1 | /* | ||
| 2 | emacs_module.h - Module API | ||
| 3 | Copyright (C) 2015 Free Software Foundation, Inc. | ||
| 4 | |||
| 5 | This file is part of GNU Emacs. | ||
| 6 | |||
| 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. | ||
| 11 | |||
| 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. | ||
| 16 | |||
| 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/>. | ||
| 19 | */ | ||
| 20 | |||
| 21 | #ifndef EMACS_MODULE_H | ||
| 22 | #define EMACS_MODULE_H | ||
| 23 | |||
| 24 | #include <stdint.h> | ||
| 25 | #include <stdlib.h> | ||
| 26 | #include <stdbool.h> | ||
| 27 | |||
| 28 | /* Current environment */ | ||
| 29 | typedef struct emacs_env_25 emacs_env; | ||
| 30 | |||
| 31 | /* The size of emacs_value must match EMACS_INT: | ||
| 32 | 32 bit system: 32 bits | ||
| 33 | 32 bit system with --with-wide-int: 64 bits | ||
| 34 | 64 bit system: 64 bits. | ||
| 35 | |||
| 36 | When compiling modules, define the macro EMACS_VALUE_TYPE by the | ||
| 37 | result of `module-emacs_value-type'. */ | ||
| 38 | typedef EMACS_VALUE_TYPE emacs_value; | ||
| 39 | |||
| 40 | /* Struct passed to a module init function (emacs_module_init) */ | ||
| 41 | struct emacs_runtime { | ||
| 42 | size_t size; | ||
| 43 | emacs_env* (*get_environment)(struct emacs_runtime *ert); | ||
| 44 | }; | ||
| 45 | |||
| 46 | |||
| 47 | /* Function prototype for the module init function */ | ||
| 48 | typedef int (*emacs_init_function)(struct emacs_runtime *ert); | ||
| 49 | |||
| 50 | /* Function prototype for the module Lisp functions */ | ||
| 51 | typedef emacs_value (*emacs_subr)(emacs_env *env, | ||
| 52 | int nargs, | ||
| 53 | emacs_value args[]); | ||
| 54 | struct emacs_env_25 { | ||
| 55 | /* | ||
| 56 | * Structure size (for version checking) | ||
| 57 | */ | ||
| 58 | |||
| 59 | size_t size; | ||
| 60 | |||
| 61 | /* | ||
| 62 | * Constants | ||
| 63 | */ | ||
| 64 | emacs_value Qt_value; | ||
| 65 | emacs_value Qnil_value; | ||
| 66 | |||
| 67 | /* | ||
| 68 | * Memory management | ||
| 69 | */ | ||
| 70 | |||
| 71 | emacs_value (*make_global_reference)(emacs_env *env, | ||
| 72 | emacs_value any_reference); | ||
| 73 | |||
| 74 | void (*free_global_reference)(emacs_env *env, | ||
| 75 | emacs_value global_reference); | ||
| 76 | |||
| 77 | /* | ||
| 78 | * Error handling | ||
| 79 | */ | ||
| 80 | |||
| 81 | bool (*error_check)(emacs_env *env); | ||
| 82 | |||
| 83 | void (*clear_error)(emacs_env *env); | ||
| 84 | |||
| 85 | bool (*get_error)(emacs_env *env, | ||
| 86 | emacs_value *error_symbol_out, | ||
| 87 | emacs_value *error_data_out); | ||
| 88 | |||
| 89 | void (*signal_error)(emacs_env *env, | ||
| 90 | const char* msg, | ||
| 91 | emacs_value error_data); | ||
| 92 | |||
| 93 | /* | ||
| 94 | * Function registration | ||
| 95 | */ | ||
| 96 | |||
| 97 | emacs_value (*make_function)(emacs_env *env, | ||
| 98 | int min_arity, | ||
| 99 | int max_arity, | ||
| 100 | emacs_subr function); | ||
| 101 | |||
| 102 | emacs_value (*funcall)(emacs_env *env, | ||
| 103 | emacs_value function, | ||
| 104 | int nargs, | ||
| 105 | emacs_value args[]); | ||
| 106 | |||
| 107 | emacs_value (*intern)(emacs_env *env, | ||
| 108 | const char *symbol_name); | ||
| 109 | |||
| 110 | emacs_value (*intern_soft)(emacs_env *env, | ||
| 111 | const char *symbol_name); | ||
| 112 | |||
| 113 | void (*bind_function) (emacs_env *env, | ||
| 114 | const char *name, | ||
| 115 | emacs_value definition); | ||
| 116 | |||
| 117 | /* | ||
| 118 | * Type conversion | ||
| 119 | */ | ||
| 120 | |||
| 121 | emacs_value (*type_of)(emacs_env *env, | ||
| 122 | emacs_value value); | ||
| 123 | |||
| 124 | int64_t (*fixnum_to_int)(emacs_env *env, | ||
| 125 | emacs_value value); | ||
| 126 | |||
| 127 | emacs_value (*make_fixnum)(emacs_env *env, | ||
| 128 | int64_t value); | ||
| 129 | |||
| 130 | double (*float_to_c_double)(emacs_env *env, | ||
| 131 | emacs_value value); | ||
| 132 | |||
| 133 | emacs_value (*make_float)(emacs_env *env, | ||
| 134 | double value); | ||
| 135 | |||
| 136 | bool (*copy_string_contents)(emacs_env *env, | ||
| 137 | emacs_value value, | ||
| 138 | char *buffer, | ||
| 139 | size_t* length_inout); | ||
| 140 | |||
| 141 | size_t (*buffer_byte_length)(emacs_env *env, | ||
| 142 | emacs_value start, | ||
| 143 | emacs_value end); | ||
| 144 | /* Return the size in bytes of the buffer substring in the current | ||
| 145 | buffer from START to END */ | ||
| 146 | |||
| 147 | void (*copy_buffer_substring)(emacs_env *env, | ||
| 148 | emacs_value start, | ||
| 149 | emacs_value end, | ||
| 150 | char *buffer, | ||
| 151 | size_t* length_inout); | ||
| 152 | /* Copy buffer string from current buffer, BEG to END (integers or | ||
| 153 | markers), to BUFFER. On call, LENGTH_INOUT is the size in bytes | ||
| 154 | of BUFFER; on return, it is the size in bytes of the copied | ||
| 155 | string. | ||
| 156 | |||
| 157 | If BUFFER is too small, signals an error. Use buffer_byte_length | ||
| 158 | to ensure BUFFER is not too small. */ | ||
| 159 | |||
| 160 | emacs_value (*make_string)(emacs_env *env, | ||
| 161 | const char *contents); | ||
| 162 | |||
| 163 | /* | ||
| 164 | * miscellaneous | ||
| 165 | */ | ||
| 166 | |||
| 167 | void (*message)(emacs_env *env, | ||
| 168 | emacs_value msg); | ||
| 169 | /* msg must be already formatted */ | ||
| 170 | |||
| 171 | emacs_value (*symbol_value)(emacs_env *env, | ||
| 172 | emacs_value symbol); | ||
| 173 | }; | ||
| 174 | |||
| 175 | #endif /* EMACS_MODULE_H */ | ||