forked from nodejs/node-addon-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaddon.cc
More file actions
36 lines (28 loc) · 861 Bytes
/
addon.cc
File metadata and controls
36 lines (28 loc) · 861 Bytes
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
32
33
34
35
36
#if (NAPI_VERSION > 5)
#include <stdio.h>
#include "napi.h"
namespace {
class TestAddon : public Napi::Addon<TestAddon> {
public:
inline TestAddon(Napi::Env env, Napi::Object exports) {
DefineAddon(exports, {
InstanceMethod("increment", &TestAddon::Increment),
InstanceValue("subObject", DefineProperties(Napi::Object::New(env), {
InstanceMethod("decrement", &TestAddon::Decrement)
}))
});
}
private:
Napi::Value Increment(const Napi::CallbackInfo& info) {
return Napi::Number::New(info.Env(), ++value);
}
Napi::Value Decrement(const Napi::CallbackInfo& info) {
return Napi::Number::New(info.Env(), --value);
}
uint32_t value = 42;
};
} // end of anonymous namespace
Napi::Object InitAddon(Napi::Env env) {
return TestAddon::Init(env, Napi::Object::New(env));
}
#endif // (NAPI_VERSION > 5)