├── .gitignore ├── LICENSE ├── README.md ├── example ├── binding.gyp ├── example.js ├── index.c └── package.json ├── index.js ├── napi-macros.h └── package.json /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | example/build 3 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2018 Mathias Buus 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # napi-macros 2 | 3 | Set of utility macros to make writing [N-API](https://nodejs.org/dist/latest-v9.x/docs/api/n-api.html) modules a little easier. 4 | 5 | ``` 6 | npm install napi-macros 7 | ``` 8 | 9 | Then add the following to your target in your binding.gyp file 10 | 11 | ``` 12 | "include_dirs": [ 13 | " 24 | #include 25 | 26 | NAPI_METHOD(times_two) { 27 | NAPI_ARGV(1) 28 | NAPI_ARGV_INT32(number, 0) 29 | 30 | number *= 2; 31 | 32 | NAPI_RETURN_INT32(number) 33 | } 34 | 35 | NAPI_INIT() { 36 | NAPI_EXPORT_FUNCTION(times_two) 37 | } 38 | ``` 39 | 40 | Full working example can be found in the [example/](https://github.com/mafintosh/napi-macros/tree/master/example) folder. 41 | 42 | ## API 43 | 44 | #### `NAPI_INIT()` 45 | 46 | Setup init boilerplate. Pass the function body after. 47 | 48 | ``` c 49 | static char *my_string = "hello"; 50 | 51 | NAPI_INIT() { 52 | EXPORT_STRING(my_string) 53 | } 54 | ``` 55 | 56 | #### `NAPI_METHOD(name)` 57 | 58 | Setup method boilerplate. Pass the function body after. 59 | 60 | ``` c 61 | NAPI_METHOD(add) { 62 | NAPI_ARGV(2) 63 | NAPI_ARGV_INT32(a, 0) 64 | NAPI_ARGV_INT32(b, 1) 65 | 66 | a = a + b 67 | 68 | NAPI_RETURN_INT32(a) 69 | } 70 | ``` 71 | 72 | #### `NAPI_ARGV(n)` 73 | 74 | Setup up argv boilerplate. `n` is how many arguments you are expecting. 75 | Expects the `napi_env` to be in scope as `env` and the `napi_callback_info` to be in scope as `info`. 76 | 77 | #### `NAPI_ARGV_BUFFER(name, index)` 78 | 79 | Get a buffer out of the arguments at the corresponding index. 80 | Sets `char *name` and `size_t name_len` with the buffer and buffer length. 81 | 82 | #### `NAPI_ARGV_BUFFER_CAST(type, name, index)` 83 | 84 | Get a buffer out and cast the pointer to the specified type. 85 | Note that the type should include the pointer star, i.e. 86 | 87 | ``` c 88 | NAPI_ARGV_BUFFER_CAST(uv_udp_t *, handle, 0) 89 | ``` 90 | 91 | Will cast the 1st argument as `uv_udp_t` pointer. 92 | 93 | #### `NAPI_ARGV_UINT32(name, index)` 94 | 95 | Get an argument as a uint32. 96 | Will throw if argument is not the right type. 97 | 98 | #### `NAPI_ARGV_INT32(name, index)` 99 | 100 | Get an argument as an int32. 101 | Will throw if argument is not the right type. 102 | 103 | #### `NAPI_ARGV_UTF8(name, length, index)` 104 | 105 | Get an argument as a utf8 string. 106 | 107 | `name` will be a `char[length]` array. 108 | 109 | Will throw if argument is not the right type. 110 | 111 | #### `NAPI_ARGV_UTF8_MALLOC(name, index)` 112 | 113 | Get an argument as a utf8 string. 114 | 115 | `name` will be a `char*`. 116 | 117 | Like `NAPI_ARGV_UTF8()` but allocates `name` on the heap using `malloc()`, which should be `free()`'d after usage. 118 | 119 | #### `NAPI_BUFFER_CAST(type, name, var)` 120 | 121 | Same as `NAPI_ARGV_BUFFER_CAST` but takes a generic `napi_value` variable instead of an argv index. 122 | 123 | #### `NAPI_BUFFER(name, var)` 124 | 125 | Same as `NAPI_ARGV_BUFFER` but takes a generic `napi_value` variable instead of an argv index. 126 | 127 | #### `NAPI_UTF8(name, size, var)` 128 | 129 | Same as `NAPI_ARGV_UTF8` but takes a generic `napi_value` variable instead of an argv index. 130 | 131 | #### `NAPI_UTF8_MALLOC(name, var)` 132 | 133 | Same as `NAPI_ARGV_UTF8_MALLOC` but takes a generic `napi_value` variable instead of an argv index. 134 | 135 | #### `NAPI_UINT32(name, var)` 136 | 137 | Same as `NAPI_ARGV_UINT32` but takes a generic `napi_value` variable instead of an argv index. 138 | 139 | #### `NAPI_INT32(name, var)` 140 | 141 | Same as `NAPI_ARGV_INT32` but takes a generic `napi_value` variable instead of an argv index. 142 | 143 | #### `NAPI_EXPORT_FUNCTION(fn)` 144 | 145 | Will export a function in the Init method. Expects the env and `exports` to be in scope. 146 | The name of the exported function is the same name as the c function. 147 | 148 | #### `NAPI_EXPORT_SIZEOF(struct)` 149 | 150 | Export the size of a strict. The exported name is `sizeof_{struct-name}`. 151 | 152 | #### `NAPI_EXPORT_UINT32(name)` 153 | 154 | Export a uint32. 155 | The name of the exported number is the same name as the c variable. 156 | 157 | #### `NAPI_EXPORT_INT32(name)` 158 | 159 | Export an int32. 160 | The name of the exported number is the same name as the c variable. 161 | 162 | #### `NAPI_EXPORT_UTF8(name, len)` 163 | 164 | Export a utf8 string. `len` should be the length of the string. 165 | The name of the exported string is the same name as the c variable. 166 | 167 | #### `NAPI_EXPORT_STRING(name)` 168 | 169 | Export a null terminated string. 170 | The name of the exported string is the same name as the c variable. 171 | 172 | #### `NAPI_EXPORT_SIZEOF(type)` 173 | 174 | Exports `sizeof(type)`. 175 | The name of the exported number is the same name as the c variable. 176 | 177 | #### `NAPI_EXPORT_SIZEOF_STRUCT(structName)` 178 | 179 | Exports `sizeof(struct structName)`. 180 | The name of the exported number is the same name as the c variable. 181 | 182 | #### `NAPI_EXPORT_ALIGNMENTOF(type)` 183 | 184 | Exports the byte alignment of `type`. 185 | The name of the exported number is the same name as the c variable. 186 | 187 | #### `NAPI_EXPORT_ALIGNMENTOF_STRUCT(structName)` 188 | 189 | Exports the byte alignment of `struct structName`. 190 | The name of the exported number is the same name as the c variable. 191 | 192 | #### `NAPI_EXPORT_OFFSETOF(type, name)` 193 | 194 | Exports the byte offset of `name` within `type`. 195 | The name of the exported number is the same name as the c variables. 196 | 197 | #### `NAPI_EXPORT_OFFSETOF_STRUCT(structName, name)` 198 | 199 | Exports the byte offset of `name` within `struct structName`. 200 | The name of the exported number is the same name as the c variables. 201 | 202 | #### `NAPI_FOR_EACH(array, element)` 203 | 204 | Iterate over an array. `array` should be a `napi_value` containing a javascript array 205 | and `element` is the variable name an element will be exposed as. Expects the loop body 206 | to be passed after. 207 | 208 | ``` c 209 | napi_value buffers = argv[0] // first argument is a js array 210 | NAPI_FOR_EACH(buffers, buffer) { 211 | NAPI_BUFFER(cbuf, buffer) 212 | printf("cbuf is now a char * pointer: %s\n", cbuf); 213 | } 214 | ``` 215 | 216 | #### `NAPI_RETURN_UINT32(name)` 217 | 218 | Returns a uint32. 219 | 220 | #### `NAPI_RETURN_INT32(name)` 221 | 222 | Returns an int32. 223 | 224 | #### `NAPI_RETURN_UTF8(name, len)` 225 | 226 | Return a utf8 string. `len` should be the length of the string. 227 | 228 | #### `NAPI_RETURN_STRING(name)` 229 | 230 | Return a null terminated string. 231 | 232 | #### `NAPI_STATUS_THROWS(call)` 233 | 234 | Checks the return status of any `napi_*` function returning a `napi_status` type. This simplifies using a `napi_status` variable and comparing the result with `napi_ok`. It's used internally but can be used stand alone as well. 235 | 236 | ```c 237 | NAPI_STATUS_THROWS( 238 | napi_create_threadsafe_function( 239 | NULL, 240 | callback, 241 | 0, 242 | async_resource_name, 243 | 0, 244 | 3, 245 | 0, 246 | my_finalize, 247 | NULL, 248 | my_callback, 249 | &threadsafe_function 250 | ) 251 | ); 252 | ``` 253 | 254 | Above example will fail because the first `env` parameter is `NULL` and throw the following error: 255 | 256 | ``` 257 | Error: napi_create_threadsafe_function(NULL, callback, 0, async_resource_name, 0, 3, 0, my_finalize, \ 258 | NULL, my_callback, &threadsafe_function) failed! 259 | ``` 260 | 261 | #### `NAPI_UV_THROWS(err, fn)` 262 | 263 | Checks if a libuv call fails and if so, throws an error. 264 | 265 | ``` c 266 | int err; 267 | NAPI_UV_THROWS(err, uv_ip4_addr((char *) &ip, port, &addr)) 268 | ``` 269 | 270 | #### `NAPI_MAKE_CALLBACK(env, async_ctx, ctx, func, argc, argv, result)` 271 | 272 | Same as `napi_make_callback` except it checks if the JS function throw an exception 273 | and triggers a `process.on('uncaughtException')` if so. 274 | 275 | ## License 276 | 277 | MIT 278 | -------------------------------------------------------------------------------- /example/binding.gyp: -------------------------------------------------------------------------------- 1 | { 2 | "targets": [{ 3 | "target_name": "napi_macros_example", 4 | "include_dirs": [ 5 | " 2 | #include 3 | 4 | NAPI_METHOD(times_two) { 5 | NAPI_ARGV(1) 6 | NAPI_ARGV_INT32(number, 0) 7 | 8 | number *= 2; 9 | 10 | NAPI_RETURN_INT32(number) 11 | } 12 | 13 | NAPI_INIT() { 14 | NAPI_EXPORT_FUNCTION(times_two) 15 | } 16 | -------------------------------------------------------------------------------- /example/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "napi-macros-example", 3 | "version": "0.0.0", 4 | "description": "an example using napi-macros", 5 | "dependencies": { 6 | "node-gyp-build": "^3.2.2" 7 | }, 8 | "scripts": { 9 | "install": "node-gyp-build" 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | console.log(require('path').relative('.', __dirname)) 2 | -------------------------------------------------------------------------------- /napi-macros.h: -------------------------------------------------------------------------------- 1 | #ifndef NAPI_MACROS 2 | #define NAPI_MACROS 3 | 4 | #define NAPI_INIT() \ 5 | static void napi_macros_init(napi_env env, napi_value exports); \ 6 | static napi_value napi_macros_init_wrap (napi_env env, napi_value exports) { \ 7 | napi_macros_init(env, exports); \ 8 | return exports; \ 9 | } \ 10 | NAPI_MODULE(NODE_GYP_MODULE_NAME, napi_macros_init_wrap) \ 11 | static void napi_macros_init (napi_env env, napi_value exports) 12 | 13 | #define NAPI_TEST_GC(env) \ 14 | { \ 15 | napi_handle_scope scope; \ 16 | napi_open_handle_scope(env, &scope); \ 17 | napi_value s; \ 18 | napi_value r; \ 19 | napi_create_string_utf8(env, "try { global.gc() } catch {}", NAPI_AUTO_LENGTH, &s); \ 20 | napi_run_script(env, s, &r); \ 21 | napi_close_handle_scope(env, scope); \ 22 | } 23 | 24 | #define NAPI_UV_ERROR_MAP_ITER(NAME, DESC) { \ 25 | napi_create_array(env, &entry); \ 26 | napi_create_array(env, &val); \ 27 | napi_value name; \ 28 | napi_create_string_utf8(env, #NAME, NAPI_AUTO_LENGTH, &name); \ 29 | napi_set_element(env, val, 0, name); \ 30 | napi_value desc; \ 31 | napi_create_string_utf8(env, DESC, NAPI_AUTO_LENGTH, &desc); \ 32 | napi_set_element(env, val, 1, desc); \ 33 | napi_create_int32(env, UV_ ## NAME, &key); \ 34 | napi_set_element(env, entry, 0, key); \ 35 | napi_set_element(env, entry, 1, val); \ 36 | napi_set_element(env, arr, i++, entry); \ 37 | } 38 | 39 | #define NAPI_MAKE_CALLBACK(env, nil, ctx, cb, n, argv, res) \ 40 | if (napi_make_callback(env, nil, ctx, cb, n, argv, res) == napi_pending_exception) { \ 41 | napi_value fatal_exception; \ 42 | napi_get_and_clear_last_exception(env, &fatal_exception); \ 43 | napi_fatal_exception(env, fatal_exception); \ 44 | } 45 | 46 | #define NAPI_STATUS_THROWS_VOID(call) \ 47 | if ((call) != napi_ok) { \ 48 | napi_throw_error(env, NULL, #call " failed!"); \ 49 | return; \ 50 | } 51 | 52 | #define NAPI_STATUS_THROWS(call) \ 53 | if ((call) != napi_ok) { \ 54 | napi_throw_error(env, NULL, #call " failed!"); \ 55 | return NULL; \ 56 | } 57 | 58 | #define NAPI_METHOD(name) \ 59 | napi_value name (napi_env env, napi_callback_info info) 60 | 61 | #define NAPI_UV_THROWS(err, fn) \ 62 | err = fn; \ 63 | if (err < 0) { \ 64 | napi_throw_error(env, uv_err_name(err), uv_strerror(err)); \ 65 | return NULL; \ 66 | } 67 | 68 | #define NAPI_EXPORT_OFFSETOF(type, name) \ 69 | { \ 70 | napi_value name##_offsetof; \ 71 | type tmp; \ 72 | void *ptr = &(tmp.name); \ 73 | void *ptr_base = &tmp; \ 74 | int offset = (char *) ptr - (char *) ptr_base; \ 75 | NAPI_STATUS_THROWS_VOID(napi_create_uint32(env, offset, &name##_offsetof)) \ 76 | NAPI_STATUS_THROWS_VOID(napi_set_named_property(env, exports, "offsetof_" #type "_" #name, name##_offsetof)) \ 77 | } 78 | 79 | #define NAPI_EXPORT_OFFSETOF_STRUCT(type, name) \ 80 | { \ 81 | napi_value name##_offsetof; \ 82 | struct type tmp; \ 83 | void *ptr = &(tmp.name); \ 84 | void *ptr_base = &tmp; \ 85 | int offset = (char *) ptr - (char *) ptr_base; \ 86 | NAPI_STATUS_THROWS_VOID(napi_create_uint32(env, offset, &name##_offsetof)) \ 87 | NAPI_STATUS_THROWS_VOID(napi_set_named_property(env, exports, "offsetof_struct_" #type "_" #name, name##_offsetof)) \ 88 | } 89 | 90 | 91 | #define NAPI_EXPORT_ALIGNMENTOF(name) \ 92 | { \ 93 | napi_value name##_alignmentof; \ 94 | struct tmp { \ 95 | char a; \ 96 | name b; \ 97 | }; \ 98 | NAPI_STATUS_THROWS_VOID(napi_create_uint32(env, sizeof(struct tmp) - sizeof(name), &name##_alignmentof)) \ 99 | NAPI_STATUS_THROWS_VOID(napi_set_named_property(env, exports, "alignmentof_" #name, name##_alignmentof)) \ 100 | } 101 | 102 | #define NAPI_EXPORT_ALIGNMENTOF_STRUCT(name) \ 103 | { \ 104 | napi_value name##_alignmentof; \ 105 | struct tmp { \ 106 | char a; \ 107 | struct name b; \ 108 | }; \ 109 | NAPI_STATUS_THROWS_VOID(napi_create_uint32(env, sizeof(struct tmp) - sizeof(struct name), &name##_alignmentof)) \ 110 | NAPI_STATUS_THROWS_VOID(napi_set_named_property(env, exports, "alignmentof_" #name, name##_alignmentof)) \ 111 | } 112 | 113 | #define NAPI_EXPORT_UV_ERROR_MAP() \ 114 | { \ 115 | napi_value arr; \ 116 | napi_value key; \ 117 | napi_value val; \ 118 | napi_value entry; \ 119 | napi_create_array(env, &arr); \ 120 | int i = 0; \ 121 | UV_ERRNO_MAP(NAPI_UV_ERROR_MAP_ITER) \ 122 | NAPI_STATUS_THROWS_VOID(napi_set_named_property(env, exports, "uv_error_map", arr)) \ 123 | } 124 | 125 | #define NAPI_EXPORT_SIZEOF(name) \ 126 | { \ 127 | napi_value name##_sizeof; \ 128 | NAPI_STATUS_THROWS_VOID(napi_create_uint32(env, sizeof(name), &name##_sizeof)) \ 129 | NAPI_STATUS_THROWS_VOID(napi_set_named_property(env, exports, "sizeof_" #name, name##_sizeof)) \ 130 | } 131 | 132 | #define NAPI_EXPORT_SIZEOF_STRUCT(name) \ 133 | { \ 134 | napi_value name##_sizeof; \ 135 | NAPI_STATUS_THROWS_VOID(napi_create_uint32(env, sizeof(struct name), &name##_sizeof)) \ 136 | NAPI_STATUS_THROWS_VOID(napi_set_named_property(env, exports, "sizeof_" #name, name##_sizeof)) \ 137 | } 138 | 139 | #define NAPI_EXPORT_UINT32(name) \ 140 | { \ 141 | napi_value name##_uint32; \ 142 | NAPI_STATUS_THROWS_VOID(napi_create_uint32(env, name, &name##_uint32)) \ 143 | NAPI_STATUS_THROWS_VOID(napi_set_named_property(env, exports, #name, name##_uint32)) \ 144 | } 145 | 146 | #define NAPI_EXPORT_INT32(name) \ 147 | { \ 148 | napi_value name##_int32; \ 149 | NAPI_STATUS_THROWS_VOID(napi_create_int32(env, name, &name##_int32)) \ 150 | NAPI_STATUS_THROWS_VOID(napi_set_named_property(env, exports, #name, name##_int32)) \ 151 | } 152 | 153 | #define NAPI_EXPORT_FUNCTION(name) \ 154 | { \ 155 | napi_value name##_fn; \ 156 | NAPI_STATUS_THROWS_VOID(napi_create_function(env, NULL, 0, name, NULL, &name##_fn)) \ 157 | NAPI_STATUS_THROWS_VOID(napi_set_named_property(env, exports, #name, name##_fn)) \ 158 | } 159 | 160 | #define NAPI_EXPORT_UTF8(name, len) \ 161 | { \ 162 | napi_value name##_utf8; \ 163 | NAPI_STATUS_THROWS_VOID(napi_create_string_utf8(env, name, len, &name##_utf8)) \ 164 | NAPI_STATUS_THROWS_VOID(napi_set_named_property(env, exports, #name, name##_utf8)) \ 165 | } 166 | 167 | #define NAPI_EXPORT_STRING(name) \ 168 | NAPI_EXPORT_UTF8(name, NAPI_AUTO_LENGTH) 169 | 170 | #define NAPI_RETURN_INT32(name) \ 171 | napi_value return_int32; \ 172 | NAPI_STATUS_THROWS(napi_create_int32(env, name, &return_int32)) \ 173 | return return_int32; 174 | 175 | #define NAPI_RETURN_UINT32(name) \ 176 | napi_value return_uint32; \ 177 | NAPI_STATUS_THROWS(napi_create_uint32(env, name, &return_uint32)) \ 178 | return return_uint32; 179 | 180 | #define NAPI_RETURN_UTF8(name, len) \ 181 | napi_value return_utf8; \ 182 | NAPI_STATUS_THROWS(napi_create_string_utf8(env, name, len, &return_utf8)) \ 183 | return return_utf8; 184 | 185 | #define NAPI_RETURN_STRING(name) \ 186 | NAPI_RETURN_UTF8(name, NAPI_AUTO_LENGTH) 187 | 188 | #define NAPI_UTF8(name, size, val) \ 189 | char name[size]; \ 190 | size_t name##_len; \ 191 | if (napi_get_value_string_utf8(env, val, (char *) &name, size, &name##_len) != napi_ok) { \ 192 | napi_throw_error(env, "EINVAL", "Expected string"); \ 193 | return NULL; \ 194 | } 195 | 196 | #define NAPI_UTF8_MALLOC(name, val) \ 197 | size_t name##_size = 0; \ 198 | NAPI_STATUS_THROWS(napi_get_value_string_utf8(env, val, NULL, 0, &name##_size)) \ 199 | char* name = (char*)malloc((name##_size + 1) * sizeof(char)); \ 200 | size_t name##_len; \ 201 | NAPI_STATUS_THROWS(napi_get_value_string_utf8(env, val, name, name##_size + 1, &name##_len)) \ 202 | name[name##_size] = '\0'; 203 | 204 | #define NAPI_UINT32(name, val) \ 205 | uint32_t name; \ 206 | if (napi_get_value_uint32(env, val, &name) != napi_ok) { \ 207 | napi_throw_error(env, "EINVAL", "Expected unsigned number"); \ 208 | return NULL; \ 209 | } 210 | 211 | #define NAPI_INT32(name, val) \ 212 | int32_t name; \ 213 | if (napi_get_value_int32(env, val, &name) != napi_ok) { \ 214 | napi_throw_error(env, "EINVAL", "Expected number"); \ 215 | return NULL; \ 216 | } 217 | 218 | #define NAPI_BUFFER_CAST(type, name, val) \ 219 | type name; \ 220 | size_t name##_len; \ 221 | NAPI_STATUS_THROWS(napi_get_buffer_info(env, val, (void **) &name, &name##_len)) 222 | 223 | #define NAPI_BUFFER(name, val) \ 224 | NAPI_BUFFER_CAST(char *, name, val) 225 | 226 | #define NAPI_FOR_EACH(arr, element) \ 227 | uint32_t arr##_len; \ 228 | napi_get_array_length(env, arr, &arr##_len); \ 229 | napi_value element; \ 230 | for (uint32_t i = 0; i < arr##_len && napi_get_element(env, arr, i, &element) == napi_ok; i++) 231 | 232 | #define NAPI_ARGV(n) \ 233 | napi_value argv[n]; \ 234 | size_t argc = n; \ 235 | NAPI_STATUS_THROWS(napi_get_cb_info(env, info, &argc, argv, NULL, NULL)) 236 | 237 | #define NAPI_ARGV_UTF8(name, size, i) \ 238 | NAPI_UTF8(name, size, argv[i]) 239 | 240 | #define NAPI_ARGV_UTF8_MALLOC(name, i) \ 241 | NAPI_UTF8_MALLOC(name, argv[i]) 242 | 243 | #define NAPI_ARGV_UINT32(name, i) \ 244 | NAPI_UINT32(name, argv[i]) 245 | 246 | #define NAPI_ARGV_INT32(name, i) \ 247 | NAPI_INT32(name, argv[i]) 248 | 249 | #define NAPI_ARGV_BUFFER_CAST(type, name, i) \ 250 | NAPI_BUFFER_CAST(type, name, argv[i]) 251 | 252 | #define NAPI_ARGV_BUFFER(name, i) \ 253 | NAPI_ARGV_BUFFER_CAST(char *, name, i) 254 | 255 | #endif 256 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "napi-macros", 3 | "version": "2.2.2", 4 | "description": "Set of utility macros to make writing N-API modules a little easier.", 5 | "main": "index.js", 6 | "dependencies": {}, 7 | "devDependencies": {}, 8 | "repository": { 9 | "type": "git", 10 | "url": "https://github.com/mafintosh/napi-macros.git" 11 | }, 12 | "files": [ 13 | "napi-macros.h", 14 | "index.js" 15 | ], 16 | "author": "Mathias Buus (@mafintosh)", 17 | "license": "MIT", 18 | "bugs": { 19 | "url": "https://github.com/mafintosh/napi-macros/issues" 20 | }, 21 | "homepage": "https://github.com/mafintosh/napi-macros" 22 | } 23 | --------------------------------------------------------------------------------