-
Notifications
You must be signed in to change notification settings - Fork 0
/
addon.cc
34 lines (24 loc) · 819 Bytes
/
addon.cc
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
#include <napi.h>
Napi::Value SumSyncReturn(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
if (info.Length() != 2) {
Napi::TypeError::New(env, "Invalid argument count").ThrowAsJavaScriptException();
return env.Null();
}
if (!info[0].IsNumber() || !info[1].IsNumber()) {
Napi::TypeError::New(env, "Invalid argument types").ThrowAsJavaScriptException();
return env.Null();
}
double arg0 = info[0].As<Napi::Number>().DoubleValue();
double arg1 = info[1].As<Napi::Number>().DoubleValue();
Napi::Number num = Napi::Number::New(env, arg0 + arg1);
return num;
}
Napi::Object Init(Napi::Env env, Napi::Object exports) {
exports.Set(
Napi::String::New(env, "add"),
Napi::Function::New(env, SumSyncReturn)
);
return exports;
}
NODE_API_MODULE(addon, Init)