-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhello.c
32 lines (25 loc) · 990 Bytes
/
hello.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <assert.h>
#include <node_api.h>
static napi_value Method(napi_env env, napi_callback_info info) {
napi_status status;
napi_value world;
status = napi_create_string_utf8(env, "world", 5, &world);
assert(status == napi_ok);
return world;
}
static napi_value ExceptionMethod(napi_env env, napi_callback_info info) {
napi_throw_type_error(env, "code1", "type exception");
return NULL;
}
#define DECLARE_NAPI_METHOD(name, func) \
{ name, 0, func, 0, 0, 0, napi_default, 0 }
static napi_value Init(napi_env env, napi_value exports) {
napi_status status;
napi_property_descriptor desc = DECLARE_NAPI_METHOD("hello", Method);
napi_property_descriptor desc2 = DECLARE_NAPI_METHOD("exception", ExceptionMethod);
status = napi_define_properties(env, exports, 1, &desc);
status = napi_define_properties(env, exports, 1, &desc2);
assert(status == napi_ok);
return exports;
}
NAPI_MODULE(NODE_GYP_MODULE_NAME, Init)