helpers.h
Go to the documentation of this file.
1 #ifndef NVIM_API_PRIVATE_HELPERS_H
2 #define NVIM_API_PRIVATE_HELPERS_H
3 
4 #include <stdbool.h>
5 
7 #include "nvim/vim.h"
8 #include "nvim/memory.h"
9 #include "nvim/ex_eval.h"
10 #include "nvim/lib/kvec.h"
11 
12 #define OBJECT_OBJ(o) o
13 
14 #define BOOLEAN_OBJ(b) ((Object) { \
15  .type = kObjectTypeBoolean, \
16  .data.boolean = b })
17 
18 #define INTEGER_OBJ(i) ((Object) { \
19  .type = kObjectTypeInteger, \
20  .data.integer = i })
21 
22 #define FLOAT_OBJ(f) ((Object) { \
23  .type = kObjectTypeFloat, \
24  .data.floating = f })
25 
26 #define STRING_OBJ(s) ((Object) { \
27  .type = kObjectTypeString, \
28  .data.string = s })
29 
30 #define BUFFER_OBJ(s) ((Object) { \
31  .type = kObjectTypeBuffer, \
32  .data.integer = s })
33 
34 #define WINDOW_OBJ(s) ((Object) { \
35  .type = kObjectTypeWindow, \
36  .data.integer = s })
37 
38 #define TABPAGE_OBJ(s) ((Object) { \
39  .type = kObjectTypeTabpage, \
40  .data.integer = s })
41 
42 #define ARRAY_OBJ(a) ((Object) { \
43  .type = kObjectTypeArray, \
44  .data.array = a })
45 
46 #define DICTIONARY_OBJ(d) ((Object) { \
47  .type = kObjectTypeDictionary, \
48  .data.dictionary = d })
49 
50 #define NIL ((Object) {.type = kObjectTypeNil})
51 
52 #define PUT(dict, k, v) \
53  kv_push(dict, ((KeyValuePair) { .key = cstr_to_string(k), .value = v }))
54 
55 #define ADD(array, item) \
56  kv_push(array, item)
57 
58 #define STATIC_CSTR_AS_STRING(s) ((String) {.data = s, .size = sizeof(s) - 1})
59 
63 #define STATIC_CSTR_TO_STRING(s) ((String){ \
64  .data = xmemdupz(s, sizeof(s) - 1), \
65  .size = sizeof(s) - 1 })
66 
67 // Helpers used by the generated msgpack-rpc api wrappers
68 #define api_init_boolean
69 #define api_init_integer
70 #define api_init_float
71 #define api_init_string = STRING_INIT
72 #define api_init_buffer
73 #define api_init_window
74 #define api_init_tabpage
75 #define api_init_object = NIL
76 #define api_init_array = ARRAY_DICT_INIT
77 #define api_init_dictionary = ARRAY_DICT_INIT
78 
79 #define api_free_boolean(value)
80 #define api_free_integer(value)
81 #define api_free_float(value)
82 #define api_free_buffer(value)
83 #define api_free_window(value)
84 #define api_free_tabpage(value)
85 
90 typedef struct {
93  const struct msglist *const *msg_list;
94  int trylevel;
95  int got_int;
97  int did_emsg;
98 } TryState;
99 
100 #ifdef INCLUDE_GENERATED_DECLARATIONS
101 # include "api/private/helpers.h.generated.h"
102 #endif
103 #endif // NVIM_API_PRIVATE_HELPERS_H
Definition: ex_eval.h:105
const struct msglist *const * msg_list
Definition: helpers.h:93
int need_rethrow
Definition: helpers.h:96
Definition: helpers.h:90
int did_emsg
Definition: helpers.h:97
int got_int
Definition: helpers.h:95
Definition: ex_eval.h:86
struct msglist * private_msg_list
Definition: helpers.h:92
except_T * current_exception
Definition: helpers.h:91
int trylevel
Definition: helpers.h:94