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