forked from public/fvtt-cthulhu-eternal
Initial import with skill sheet working
This commit is contained in:
21
node_modules/napi-macros/LICENSE
generated
vendored
Normal file
21
node_modules/napi-macros/LICENSE
generated
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2018 Mathias Buus
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
277
node_modules/napi-macros/README.md
generated
vendored
Normal file
277
node_modules/napi-macros/README.md
generated
vendored
Normal file
@ -0,0 +1,277 @@
|
||||
# napi-macros
|
||||
|
||||
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.
|
||||
|
||||
```
|
||||
npm install napi-macros
|
||||
```
|
||||
|
||||
Then add the following to your target in your binding.gyp file
|
||||
|
||||
```
|
||||
"include_dirs": [
|
||||
"<!(node -e \"require('napi-macros')\")"
|
||||
],
|
||||
```
|
||||
|
||||
These patterns mostly reflect how I use N-API so far. Feel free
|
||||
to PR more.
|
||||
|
||||
## Usage
|
||||
|
||||
``` c
|
||||
#include <node_api.h>
|
||||
#include <napi-macros.h>
|
||||
|
||||
NAPI_METHOD(times_two) {
|
||||
NAPI_ARGV(1)
|
||||
NAPI_ARGV_INT32(number, 0)
|
||||
|
||||
number *= 2;
|
||||
|
||||
NAPI_RETURN_INT32(number)
|
||||
}
|
||||
|
||||
NAPI_INIT() {
|
||||
NAPI_EXPORT_FUNCTION(times_two)
|
||||
}
|
||||
```
|
||||
|
||||
Full working example can be found in the [example/](https://github.com/mafintosh/napi-macros/tree/master/example) folder.
|
||||
|
||||
## API
|
||||
|
||||
#### `NAPI_INIT()`
|
||||
|
||||
Setup init boilerplate. Pass the function body after.
|
||||
|
||||
``` c
|
||||
static char *my_string = "hello";
|
||||
|
||||
NAPI_INIT() {
|
||||
EXPORT_STRING(my_string)
|
||||
}
|
||||
```
|
||||
|
||||
#### `NAPI_METHOD(name)`
|
||||
|
||||
Setup method boilerplate. Pass the function body after.
|
||||
|
||||
``` c
|
||||
NAPI_METHOD(add) {
|
||||
NAPI_ARGV(2)
|
||||
NAPI_ARGV_INT32(a, 0)
|
||||
NAPI_ARGV_INT32(b, 1)
|
||||
|
||||
a = a + b
|
||||
|
||||
NAPI_RETURN_INT32(a)
|
||||
}
|
||||
```
|
||||
|
||||
#### `NAPI_ARGV(n)`
|
||||
|
||||
Setup up argv boilerplate. `n` is how many arguments you are expecting.
|
||||
Expects the `napi_env` to be in scope as `env` and the `napi_callback_info` to be in scope as `info`.
|
||||
|
||||
#### `NAPI_ARGV_BUFFER(name, index)`
|
||||
|
||||
Get a buffer out of the arguments at the corresponding index.
|
||||
Sets `char *name` and `size_t name_len` with the buffer and buffer length.
|
||||
|
||||
#### `NAPI_ARGV_BUFFER_CAST(type, name, index)`
|
||||
|
||||
Get a buffer out and cast the pointer to the specified type.
|
||||
Note that the type should include the pointer star, i.e.
|
||||
|
||||
``` c
|
||||
NAPI_ARGV_BUFFER_CAST(uv_udp_t *, handle, 0)
|
||||
```
|
||||
|
||||
Will cast the 1st argument as `uv_udp_t` pointer.
|
||||
|
||||
#### `NAPI_ARGV_UINT32(name, index)`
|
||||
|
||||
Get an argument as a uint32.
|
||||
Will throw if argument is not the right type.
|
||||
|
||||
#### `NAPI_ARGV_INT32(name, index)`
|
||||
|
||||
Get an argument as an int32.
|
||||
Will throw if argument is not the right type.
|
||||
|
||||
#### `NAPI_ARGV_UTF8(name, length, index)`
|
||||
|
||||
Get an argument as a utf8 string.
|
||||
|
||||
`name` will be a `char[length]` array.
|
||||
|
||||
Will throw if argument is not the right type.
|
||||
|
||||
#### `NAPI_ARGV_UTF8_MALLOC(name, index)`
|
||||
|
||||
Get an argument as a utf8 string.
|
||||
|
||||
`name` will be a `char*`.
|
||||
|
||||
Like `NAPI_ARGV_UTF8()` but allocates `name` on the heap using `malloc()`, which should be `free()`'d after usage.
|
||||
|
||||
#### `NAPI_BUFFER_CAST(type, name, var)`
|
||||
|
||||
Same as `NAPI_ARGV_BUFFER_CAST` but takes a generic `napi_value` variable instead of an argv index.
|
||||
|
||||
#### `NAPI_BUFFER(name, var)`
|
||||
|
||||
Same as `NAPI_ARGV_BUFFER` but takes a generic `napi_value` variable instead of an argv index.
|
||||
|
||||
#### `NAPI_UTF8(name, size, var)`
|
||||
|
||||
Same as `NAPI_ARGV_UTF8` but takes a generic `napi_value` variable instead of an argv index.
|
||||
|
||||
#### `NAPI_UTF8_MALLOC(name, var)`
|
||||
|
||||
Same as `NAPI_ARGV_UTF8_MALLOC` but takes a generic `napi_value` variable instead of an argv index.
|
||||
|
||||
#### `NAPI_UINT32(name, var)`
|
||||
|
||||
Same as `NAPI_ARGV_UINT32` but takes a generic `napi_value` variable instead of an argv index.
|
||||
|
||||
#### `NAPI_INT32(name, var)`
|
||||
|
||||
Same as `NAPI_ARGV_INT32` but takes a generic `napi_value` variable instead of an argv index.
|
||||
|
||||
#### `NAPI_EXPORT_FUNCTION(fn)`
|
||||
|
||||
Will export a function in the Init method. Expects the env and `exports` to be in scope.
|
||||
The name of the exported function is the same name as the c function.
|
||||
|
||||
#### `NAPI_EXPORT_SIZEOF(struct)`
|
||||
|
||||
Export the size of a strict. The exported name is `sizeof_{struct-name}`.
|
||||
|
||||
#### `NAPI_EXPORT_UINT32(name)`
|
||||
|
||||
Export a uint32.
|
||||
The name of the exported number is the same name as the c variable.
|
||||
|
||||
#### `NAPI_EXPORT_INT32(name)`
|
||||
|
||||
Export an int32.
|
||||
The name of the exported number is the same name as the c variable.
|
||||
|
||||
#### `NAPI_EXPORT_UTF8(name, len)`
|
||||
|
||||
Export a utf8 string. `len` should be the length of the string.
|
||||
The name of the exported string is the same name as the c variable.
|
||||
|
||||
#### `NAPI_EXPORT_STRING(name)`
|
||||
|
||||
Export a null terminated string.
|
||||
The name of the exported string is the same name as the c variable.
|
||||
|
||||
#### `NAPI_EXPORT_SIZEOF(type)`
|
||||
|
||||
Exports `sizeof(type)`.
|
||||
The name of the exported number is the same name as the c variable.
|
||||
|
||||
#### `NAPI_EXPORT_SIZEOF_STRUCT(structName)`
|
||||
|
||||
Exports `sizeof(struct structName)`.
|
||||
The name of the exported number is the same name as the c variable.
|
||||
|
||||
#### `NAPI_EXPORT_ALIGNMENTOF(type)`
|
||||
|
||||
Exports the byte alignment of `type`.
|
||||
The name of the exported number is the same name as the c variable.
|
||||
|
||||
#### `NAPI_EXPORT_ALIGNMENTOF_STRUCT(structName)`
|
||||
|
||||
Exports the byte alignment of `struct structName`.
|
||||
The name of the exported number is the same name as the c variable.
|
||||
|
||||
#### `NAPI_EXPORT_OFFSETOF(type, name)`
|
||||
|
||||
Exports the byte offset of `name` within `type`.
|
||||
The name of the exported number is the same name as the c variables.
|
||||
|
||||
#### `NAPI_EXPORT_OFFSETOF_STRUCT(structName, name)`
|
||||
|
||||
Exports the byte offset of `name` within `struct structName`.
|
||||
The name of the exported number is the same name as the c variables.
|
||||
|
||||
#### `NAPI_FOR_EACH(array, element)`
|
||||
|
||||
Iterate over an array. `array` should be a `napi_value` containing a javascript array
|
||||
and `element` is the variable name an element will be exposed as. Expects the loop body
|
||||
to be passed after.
|
||||
|
||||
``` c
|
||||
napi_value buffers = argv[0] // first argument is a js array
|
||||
NAPI_FOR_EACH(buffers, buffer) {
|
||||
NAPI_BUFFER(cbuf, buffer)
|
||||
printf("cbuf is now a char * pointer: %s\n", cbuf);
|
||||
}
|
||||
```
|
||||
|
||||
#### `NAPI_RETURN_UINT32(name)`
|
||||
|
||||
Returns a uint32.
|
||||
|
||||
#### `NAPI_RETURN_INT32(name)`
|
||||
|
||||
Returns an int32.
|
||||
|
||||
#### `NAPI_RETURN_UTF8(name, len)`
|
||||
|
||||
Return a utf8 string. `len` should be the length of the string.
|
||||
|
||||
#### `NAPI_RETURN_STRING(name)`
|
||||
|
||||
Return a null terminated string.
|
||||
|
||||
#### `NAPI_STATUS_THROWS(call)`
|
||||
|
||||
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.
|
||||
|
||||
```c
|
||||
NAPI_STATUS_THROWS(
|
||||
napi_create_threadsafe_function(
|
||||
NULL,
|
||||
callback,
|
||||
0,
|
||||
async_resource_name,
|
||||
0,
|
||||
3,
|
||||
0,
|
||||
my_finalize,
|
||||
NULL,
|
||||
my_callback,
|
||||
&threadsafe_function
|
||||
)
|
||||
);
|
||||
```
|
||||
|
||||
Above example will fail because the first `env` parameter is `NULL` and throw the following error:
|
||||
|
||||
```
|
||||
Error: napi_create_threadsafe_function(NULL, callback, 0, async_resource_name, 0, 3, 0, my_finalize, \
|
||||
NULL, my_callback, &threadsafe_function) failed!
|
||||
```
|
||||
|
||||
#### `NAPI_UV_THROWS(err, fn)`
|
||||
|
||||
Checks if a libuv call fails and if so, throws an error.
|
||||
|
||||
``` c
|
||||
int err;
|
||||
NAPI_UV_THROWS(err, uv_ip4_addr((char *) &ip, port, &addr))
|
||||
```
|
||||
|
||||
#### `NAPI_MAKE_CALLBACK(env, async_ctx, ctx, func, argc, argv, result)`
|
||||
|
||||
Same as `napi_make_callback` except it checks if the JS function throw an exception
|
||||
and triggers a `process.on('uncaughtException')` if so.
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
1
node_modules/napi-macros/index.js
generated
vendored
Normal file
1
node_modules/napi-macros/index.js
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
console.log(require('path').relative('.', __dirname))
|
255
node_modules/napi-macros/napi-macros.h
generated
vendored
Normal file
255
node_modules/napi-macros/napi-macros.h
generated
vendored
Normal file
@ -0,0 +1,255 @@
|
||||
#ifndef NAPI_MACROS
|
||||
#define NAPI_MACROS
|
||||
|
||||
#define NAPI_INIT() \
|
||||
static void napi_macros_init(napi_env env, napi_value exports); \
|
||||
static napi_value napi_macros_init_wrap (napi_env env, napi_value exports) { \
|
||||
napi_macros_init(env, exports); \
|
||||
return exports; \
|
||||
} \
|
||||
NAPI_MODULE(NODE_GYP_MODULE_NAME, napi_macros_init_wrap) \
|
||||
static void napi_macros_init (napi_env env, napi_value exports)
|
||||
|
||||
#define NAPI_TEST_GC(env) \
|
||||
{ \
|
||||
napi_handle_scope scope; \
|
||||
napi_open_handle_scope(env, &scope); \
|
||||
napi_value s; \
|
||||
napi_value r; \
|
||||
napi_create_string_utf8(env, "try { global.gc() } catch {}", NAPI_AUTO_LENGTH, &s); \
|
||||
napi_run_script(env, s, &r); \
|
||||
napi_close_handle_scope(env, scope); \
|
||||
}
|
||||
|
||||
#define NAPI_UV_ERROR_MAP_ITER(NAME, DESC) { \
|
||||
napi_create_array(env, &entry); \
|
||||
napi_create_array(env, &val); \
|
||||
napi_value name; \
|
||||
napi_create_string_utf8(env, #NAME, NAPI_AUTO_LENGTH, &name); \
|
||||
napi_set_element(env, val, 0, name); \
|
||||
napi_value desc; \
|
||||
napi_create_string_utf8(env, DESC, NAPI_AUTO_LENGTH, &desc); \
|
||||
napi_set_element(env, val, 1, desc); \
|
||||
napi_create_int32(env, UV_ ## NAME, &key); \
|
||||
napi_set_element(env, entry, 0, key); \
|
||||
napi_set_element(env, entry, 1, val); \
|
||||
napi_set_element(env, arr, i++, entry); \
|
||||
}
|
||||
|
||||
#define NAPI_MAKE_CALLBACK(env, nil, ctx, cb, n, argv, res) \
|
||||
if (napi_make_callback(env, nil, ctx, cb, n, argv, res) == napi_pending_exception) { \
|
||||
napi_value fatal_exception; \
|
||||
napi_get_and_clear_last_exception(env, &fatal_exception); \
|
||||
napi_fatal_exception(env, fatal_exception); \
|
||||
}
|
||||
|
||||
#define NAPI_STATUS_THROWS_VOID(call) \
|
||||
if ((call) != napi_ok) { \
|
||||
napi_throw_error(env, NULL, #call " failed!"); \
|
||||
return; \
|
||||
}
|
||||
|
||||
#define NAPI_STATUS_THROWS(call) \
|
||||
if ((call) != napi_ok) { \
|
||||
napi_throw_error(env, NULL, #call " failed!"); \
|
||||
return NULL; \
|
||||
}
|
||||
|
||||
#define NAPI_METHOD(name) \
|
||||
napi_value name (napi_env env, napi_callback_info info)
|
||||
|
||||
#define NAPI_UV_THROWS(err, fn) \
|
||||
err = fn; \
|
||||
if (err < 0) { \
|
||||
napi_throw_error(env, uv_err_name(err), uv_strerror(err)); \
|
||||
return NULL; \
|
||||
}
|
||||
|
||||
#define NAPI_EXPORT_OFFSETOF(type, name) \
|
||||
{ \
|
||||
napi_value name##_offsetof; \
|
||||
type tmp; \
|
||||
void *ptr = &(tmp.name); \
|
||||
void *ptr_base = &tmp; \
|
||||
int offset = (char *) ptr - (char *) ptr_base; \
|
||||
NAPI_STATUS_THROWS_VOID(napi_create_uint32(env, offset, &name##_offsetof)) \
|
||||
NAPI_STATUS_THROWS_VOID(napi_set_named_property(env, exports, "offsetof_" #type "_" #name, name##_offsetof)) \
|
||||
}
|
||||
|
||||
#define NAPI_EXPORT_OFFSETOF_STRUCT(type, name) \
|
||||
{ \
|
||||
napi_value name##_offsetof; \
|
||||
struct type tmp; \
|
||||
void *ptr = &(tmp.name); \
|
||||
void *ptr_base = &tmp; \
|
||||
int offset = (char *) ptr - (char *) ptr_base; \
|
||||
NAPI_STATUS_THROWS_VOID(napi_create_uint32(env, offset, &name##_offsetof)) \
|
||||
NAPI_STATUS_THROWS_VOID(napi_set_named_property(env, exports, "offsetof_struct_" #type "_" #name, name##_offsetof)) \
|
||||
}
|
||||
|
||||
|
||||
#define NAPI_EXPORT_ALIGNMENTOF(name) \
|
||||
{ \
|
||||
napi_value name##_alignmentof; \
|
||||
struct tmp { \
|
||||
char a; \
|
||||
name b; \
|
||||
}; \
|
||||
NAPI_STATUS_THROWS_VOID(napi_create_uint32(env, sizeof(struct tmp) - sizeof(name), &name##_alignmentof)) \
|
||||
NAPI_STATUS_THROWS_VOID(napi_set_named_property(env, exports, "alignmentof_" #name, name##_alignmentof)) \
|
||||
}
|
||||
|
||||
#define NAPI_EXPORT_ALIGNMENTOF_STRUCT(name) \
|
||||
{ \
|
||||
napi_value name##_alignmentof; \
|
||||
struct tmp { \
|
||||
char a; \
|
||||
struct name b; \
|
||||
}; \
|
||||
NAPI_STATUS_THROWS_VOID(napi_create_uint32(env, sizeof(struct tmp) - sizeof(struct name), &name##_alignmentof)) \
|
||||
NAPI_STATUS_THROWS_VOID(napi_set_named_property(env, exports, "alignmentof_" #name, name##_alignmentof)) \
|
||||
}
|
||||
|
||||
#define NAPI_EXPORT_UV_ERROR_MAP() \
|
||||
{ \
|
||||
napi_value arr; \
|
||||
napi_value key; \
|
||||
napi_value val; \
|
||||
napi_value entry; \
|
||||
napi_create_array(env, &arr); \
|
||||
int i = 0; \
|
||||
UV_ERRNO_MAP(NAPI_UV_ERROR_MAP_ITER) \
|
||||
NAPI_STATUS_THROWS_VOID(napi_set_named_property(env, exports, "uv_error_map", arr)) \
|
||||
}
|
||||
|
||||
#define NAPI_EXPORT_SIZEOF(name) \
|
||||
{ \
|
||||
napi_value name##_sizeof; \
|
||||
NAPI_STATUS_THROWS_VOID(napi_create_uint32(env, sizeof(name), &name##_sizeof)) \
|
||||
NAPI_STATUS_THROWS_VOID(napi_set_named_property(env, exports, "sizeof_" #name, name##_sizeof)) \
|
||||
}
|
||||
|
||||
#define NAPI_EXPORT_SIZEOF_STRUCT(name) \
|
||||
{ \
|
||||
napi_value name##_sizeof; \
|
||||
NAPI_STATUS_THROWS_VOID(napi_create_uint32(env, sizeof(struct name), &name##_sizeof)) \
|
||||
NAPI_STATUS_THROWS_VOID(napi_set_named_property(env, exports, "sizeof_" #name, name##_sizeof)) \
|
||||
}
|
||||
|
||||
#define NAPI_EXPORT_UINT32(name) \
|
||||
{ \
|
||||
napi_value name##_uint32; \
|
||||
NAPI_STATUS_THROWS_VOID(napi_create_uint32(env, name, &name##_uint32)) \
|
||||
NAPI_STATUS_THROWS_VOID(napi_set_named_property(env, exports, #name, name##_uint32)) \
|
||||
}
|
||||
|
||||
#define NAPI_EXPORT_INT32(name) \
|
||||
{ \
|
||||
napi_value name##_int32; \
|
||||
NAPI_STATUS_THROWS_VOID(napi_create_int32(env, name, &name##_int32)) \
|
||||
NAPI_STATUS_THROWS_VOID(napi_set_named_property(env, exports, #name, name##_int32)) \
|
||||
}
|
||||
|
||||
#define NAPI_EXPORT_FUNCTION(name) \
|
||||
{ \
|
||||
napi_value name##_fn; \
|
||||
NAPI_STATUS_THROWS_VOID(napi_create_function(env, NULL, 0, name, NULL, &name##_fn)) \
|
||||
NAPI_STATUS_THROWS_VOID(napi_set_named_property(env, exports, #name, name##_fn)) \
|
||||
}
|
||||
|
||||
#define NAPI_EXPORT_UTF8(name, len) \
|
||||
{ \
|
||||
napi_value name##_utf8; \
|
||||
NAPI_STATUS_THROWS_VOID(napi_create_string_utf8(env, name, len, &name##_utf8)) \
|
||||
NAPI_STATUS_THROWS_VOID(napi_set_named_property(env, exports, #name, name##_utf8)) \
|
||||
}
|
||||
|
||||
#define NAPI_EXPORT_STRING(name) \
|
||||
NAPI_EXPORT_UTF8(name, NAPI_AUTO_LENGTH)
|
||||
|
||||
#define NAPI_RETURN_INT32(name) \
|
||||
napi_value return_int32; \
|
||||
NAPI_STATUS_THROWS(napi_create_int32(env, name, &return_int32)) \
|
||||
return return_int32;
|
||||
|
||||
#define NAPI_RETURN_UINT32(name) \
|
||||
napi_value return_uint32; \
|
||||
NAPI_STATUS_THROWS(napi_create_uint32(env, name, &return_uint32)) \
|
||||
return return_uint32;
|
||||
|
||||
#define NAPI_RETURN_UTF8(name, len) \
|
||||
napi_value return_utf8; \
|
||||
NAPI_STATUS_THROWS(napi_create_string_utf8(env, name, len, &return_utf8)) \
|
||||
return return_utf8;
|
||||
|
||||
#define NAPI_RETURN_STRING(name) \
|
||||
NAPI_RETURN_UTF8(name, NAPI_AUTO_LENGTH)
|
||||
|
||||
#define NAPI_UTF8(name, size, val) \
|
||||
char name[size]; \
|
||||
size_t name##_len; \
|
||||
if (napi_get_value_string_utf8(env, val, (char *) &name, size, &name##_len) != napi_ok) { \
|
||||
napi_throw_error(env, "EINVAL", "Expected string"); \
|
||||
return NULL; \
|
||||
}
|
||||
|
||||
#define NAPI_UTF8_MALLOC(name, val) \
|
||||
size_t name##_size = 0; \
|
||||
NAPI_STATUS_THROWS(napi_get_value_string_utf8(env, val, NULL, 0, &name##_size)) \
|
||||
char* name = (char*)malloc((name##_size + 1) * sizeof(char)); \
|
||||
size_t name##_len; \
|
||||
NAPI_STATUS_THROWS(napi_get_value_string_utf8(env, val, name, name##_size + 1, &name##_len)) \
|
||||
name[name##_size] = '\0';
|
||||
|
||||
#define NAPI_UINT32(name, val) \
|
||||
uint32_t name; \
|
||||
if (napi_get_value_uint32(env, val, &name) != napi_ok) { \
|
||||
napi_throw_error(env, "EINVAL", "Expected unsigned number"); \
|
||||
return NULL; \
|
||||
}
|
||||
|
||||
#define NAPI_INT32(name, val) \
|
||||
int32_t name; \
|
||||
if (napi_get_value_int32(env, val, &name) != napi_ok) { \
|
||||
napi_throw_error(env, "EINVAL", "Expected number"); \
|
||||
return NULL; \
|
||||
}
|
||||
|
||||
#define NAPI_BUFFER_CAST(type, name, val) \
|
||||
type name; \
|
||||
size_t name##_len; \
|
||||
NAPI_STATUS_THROWS(napi_get_buffer_info(env, val, (void **) &name, &name##_len))
|
||||
|
||||
#define NAPI_BUFFER(name, val) \
|
||||
NAPI_BUFFER_CAST(char *, name, val)
|
||||
|
||||
#define NAPI_FOR_EACH(arr, element) \
|
||||
uint32_t arr##_len; \
|
||||
napi_get_array_length(env, arr, &arr##_len); \
|
||||
napi_value element; \
|
||||
for (uint32_t i = 0; i < arr##_len && napi_get_element(env, arr, i, &element) == napi_ok; i++)
|
||||
|
||||
#define NAPI_ARGV(n) \
|
||||
napi_value argv[n]; \
|
||||
size_t argc = n; \
|
||||
NAPI_STATUS_THROWS(napi_get_cb_info(env, info, &argc, argv, NULL, NULL))
|
||||
|
||||
#define NAPI_ARGV_UTF8(name, size, i) \
|
||||
NAPI_UTF8(name, size, argv[i])
|
||||
|
||||
#define NAPI_ARGV_UTF8_MALLOC(name, i) \
|
||||
NAPI_UTF8_MALLOC(name, argv[i])
|
||||
|
||||
#define NAPI_ARGV_UINT32(name, i) \
|
||||
NAPI_UINT32(name, argv[i])
|
||||
|
||||
#define NAPI_ARGV_INT32(name, i) \
|
||||
NAPI_INT32(name, argv[i])
|
||||
|
||||
#define NAPI_ARGV_BUFFER_CAST(type, name, i) \
|
||||
NAPI_BUFFER_CAST(type, name, argv[i])
|
||||
|
||||
#define NAPI_ARGV_BUFFER(name, i) \
|
||||
NAPI_ARGV_BUFFER_CAST(char *, name, i)
|
||||
|
||||
#endif
|
22
node_modules/napi-macros/package.json
generated
vendored
Normal file
22
node_modules/napi-macros/package.json
generated
vendored
Normal file
@ -0,0 +1,22 @@
|
||||
{
|
||||
"name": "napi-macros",
|
||||
"version": "2.2.2",
|
||||
"description": "Set of utility macros to make writing N-API modules a little easier.",
|
||||
"main": "index.js",
|
||||
"dependencies": {},
|
||||
"devDependencies": {},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/mafintosh/napi-macros.git"
|
||||
},
|
||||
"files": [
|
||||
"napi-macros.h",
|
||||
"index.js"
|
||||
],
|
||||
"author": "Mathias Buus (@mafintosh)",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/mafintosh/napi-macros/issues"
|
||||
},
|
||||
"homepage": "https://github.com/mafintosh/napi-macros"
|
||||
}
|
Reference in New Issue
Block a user