Go to the documentation of this file. 1 #ifndef NVIM_API_PRIVATE_HELPERS_H
2 #define NVIM_API_PRIVATE_HELPERS_H
12 #define OBJECT_OBJ(o) o
14 #define BOOLEAN_OBJ(b) ((Object) { \
15 .type = kObjectTypeBoolean, \
17 #define BOOL(b) BOOLEAN_OBJ(b)
19 #define INTEGER_OBJ(i) ((Object) { \
20 .type = kObjectTypeInteger, \
23 #define FLOAT_OBJ(f) ((Object) { \
24 .type = kObjectTypeFloat, \
27 #define STRING_OBJ(s) ((Object) { \
28 .type = kObjectTypeString, \
31 #define CSTR_TO_OBJ(s) STRING_OBJ(cstr_to_string(s))
33 #define BUFFER_OBJ(s) ((Object) { \
34 .type = kObjectTypeBuffer, \
37 #define WINDOW_OBJ(s) ((Object) { \
38 .type = kObjectTypeWindow, \
41 #define TABPAGE_OBJ(s) ((Object) { \
42 .type = kObjectTypeTabpage, \
45 #define ARRAY_OBJ(a) ((Object) { \
46 .type = kObjectTypeArray, \
49 #define DICTIONARY_OBJ(d) ((Object) { \
50 .type = kObjectTypeDictionary, \
51 .data.dictionary = d })
53 #define LUAREF_OBJ(r) ((Object) { \
54 .type = kObjectTypeLuaRef, \
57 #define NIL ((Object)OBJECT_INIT)
58 #define NULL_STRING ((String)STRING_INIT)
61 #define HAS_KEY(o) ((o).type != kObjectTypeNil)
63 #define PUT(dict, k, v) \
64 kv_push(dict, ((KeyValuePair) { .key = cstr_to_string(k), .value = v }))
66 #define PUT_BOOL(dict, name, condition) PUT(dict, name, BOOLEAN_OBJ(condition));
68 #define ADD(array, item) \
71 #define FIXED_TEMP_ARRAY(name, fixsize) \
72 Array name = ARRAY_DICT_INIT; \
73 Object name##__items[fixsize]; \
74 name.size = fixsize; \
75 name.items = name##__items; \
77 #define STATIC_CSTR_AS_STRING(s) ((String) { .data = s, .size = sizeof(s) - 1 })
82 #define STATIC_CSTR_TO_STRING(s) ((String){ \
83 .data = xmemdupz(s, sizeof(s) - 1), \
84 .size = sizeof(s) - 1 })
87 #define api_init_boolean
88 #define api_init_integer
89 #define api_init_float
90 #define api_init_string = STRING_INIT
91 #define api_init_buffer
92 #define api_init_window
93 #define api_init_tabpage
94 #define api_init_object = NIL
95 #define api_init_array = ARRAY_DICT_INIT
96 #define api_init_dictionary = ARRAY_DICT_INIT
98 #define api_free_boolean(value)
99 #define api_free_integer(value)
100 #define api_free_float(value)
101 #define api_free_buffer(value)
102 #define api_free_window(value)
103 #define api_free_tabpage(value)
109 #define handle_get_buffer(h) pmap_get(handle_T)(&buffer_handles, (h))
110 #define handle_get_window(h) pmap_get(handle_T)(&window_handles, (h))
111 #define handle_get_tabpage(h) pmap_get(handle_T)(&tabpage_handles, (h))
131 #define TRY_WRAP(code) \
133 struct msglist **saved_msg_list = msg_list; \
134 struct msglist *private_msg_list; \
135 msg_list = &private_msg_list; \
136 private_msg_list = NULL; \
138 msg_list = saved_msg_list; \
142 #define FOREACH_ITEM(a, __foreach_item, code) \
143 for (size_t (__foreach_item##_index) = 0; (__foreach_item##_index) < (a).size; \
144 (__foreach_item##_index)++) { \
145 Object __foreach_item = (a).items[__foreach_item##_index]; \
150 #ifdef INCLUDE_GENERATED_DECLARATIONS
151 # include "api/private/helpers.h.generated.h"
152 # include "keysets.h.generated.h"
155 #define WITH_SCRIPT_CONTEXT(channel_id, code) \
157 const sctx_T save_current_sctx = current_sctx; \
158 current_sctx.sc_sid = \
159 (channel_id) == LUA_INTERNAL_CALL ? SID_LUA : SID_API_CLIENT; \
160 current_sctx.sc_lnum = 0; \
161 current_channel_id = channel_id; \
163 current_sctx = save_current_sctx; \
167 #endif // NVIM_API_PRIVATE_HELPERS_H
int did_emsg
Definition: helpers.h:124
Definition: helpers.h:117
const struct msglist *const * msg_list
Definition: helpers.h:120
#define INIT(...)
Definition: macros.h:10
EXTERN PMap(handle_T) buffer_handles INIT(
int trylevel
Definition: helpers.h:121
struct msglist * private_msg_list
Definition: helpers.h:119
int need_rethrow
Definition: helpers.h:123
#define EXTERN
Definition: macros.h:9
#define MAP_INIT
Definition: map.h:56
int handle_T
Definition: types.h:18
int got_int
Definition: helpers.h:122
except_T * current_exception
Definition: helpers.h:118