diff options
author | Thiago de Arruda <tpadilha84@gmail.com> | 2014-06-18 11:31:50 -0300 |
---|---|---|
committer | Thiago de Arruda <tpadilha84@gmail.com> | 2014-06-18 11:36:08 -0300 |
commit | a7d027c8ab289d76eda91b6afe3be63a165d4adf (patch) | |
tree | 28b5852d5c6ed9ebc415209d9c42bafa651b53b3 /src/nvim/api/private/helpers.h | |
parent | caf2fb84808add8edf204c8a46abedd5aa26ab29 (diff) | |
download | rneovim-a7d027c8ab289d76eda91b6afe3be63a165d4adf.tar.gz rneovim-a7d027c8ab289d76eda91b6afe3be63a165d4adf.tar.bz2 rneovim-a7d027c8ab289d76eda91b6afe3be63a165d4adf.zip |
api: Add helper macros for dealing with API type casts
Diffstat (limited to 'src/nvim/api/private/helpers.h')
-rw-r--r-- | src/nvim/api/private/helpers.h | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src/nvim/api/private/helpers.h b/src/nvim/api/private/helpers.h index 68ab4ff614..e1e1a35490 100644 --- a/src/nvim/api/private/helpers.h +++ b/src/nvim/api/private/helpers.h @@ -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 |