mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
api: Add helper macros for dealing with API type casts
This commit is contained in:
parent
caf2fb8480
commit
a7d027c8ab
@ -6,6 +6,7 @@
|
||||
#include "nvim/api/private/defs.h"
|
||||
#include "nvim/vim.h"
|
||||
#include "nvim/memory.h"
|
||||
#include "nvim/lib/kvec.h"
|
||||
|
||||
#define set_api_error(message, err) \
|
||||
do { \
|
||||
@ -13,6 +14,48 @@
|
||||
err->set = true; \
|
||||
} while (0)
|
||||
|
||||
#define BOOL_OBJ(b) ((Object) { \
|
||||
.type = kObjectTypeBoolean, \
|
||||
.data.boolean = b \
|
||||
})
|
||||
|
||||
#define INTEGER_OBJ(i) ((Object) { \
|
||||
.type = kObjectTypeInteger, \
|
||||
.data.integer = i \
|
||||
})
|
||||
|
||||
#define STRING_OBJ(s) ((Object) { \
|
||||
.type = kObjectTypeString, \
|
||||
.data.string = cstr_to_string(s) \
|
||||
})
|
||||
|
||||
#define STRINGL_OBJ(d, s) ((Object) { \
|
||||
.type = kObjectTypeString, \
|
||||
.data.string = (String) { \
|
||||
.size = s, \
|
||||
.data = xmemdup(d, s) \
|
||||
}})
|
||||
|
||||
#define ARRAY_OBJ(a) ((Object) { \
|
||||
.type = kObjectTypeArray, \
|
||||
.data.array = a \
|
||||
})
|
||||
|
||||
#define DICTIONARY_OBJ(d) ((Object) { \
|
||||
.type = kObjectTypeDictionary, \
|
||||
.data.dictionary = d \
|
||||
})
|
||||
|
||||
#define NIL ((Object) {.type = kObjectTypeNil})
|
||||
|
||||
#define PUT(dict, k, v) \
|
||||
kv_push(KeyValuePair, \
|
||||
dict, \
|
||||
((KeyValuePair) {.key = cstr_to_string(k), .value = v}))
|
||||
|
||||
#define ADD(array, item) \
|
||||
kv_push(Object, array, item)
|
||||
|
||||
#ifdef INCLUDE_GENERATED_DECLARATIONS
|
||||
# include "api/private/helpers.h.generated.h"
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user