-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnative.cpp
More file actions
29 lines (22 loc) · 769 Bytes
/
native.cpp
File metadata and controls
29 lines (22 loc) · 769 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
#include <napi.h>
#include "dsjin.h"
using namespace Napi;
using namespace DSJIN;
Number AddNumber(const CallbackInfo& info) {
Env env = info.Env();
if (info.Length() < 2 || !info[0].IsNumber() || !info[1].IsNumber()) {
TypeError::New(env, "Number expected").ThrowAsJavaScriptException();
}
Number first = info[0].As<Napi::Number>();
Number second = info[1].As<Napi::Number>();
return Number::New(info.Env(), Add(first.Int32Value(), second.Int32Value()));
}
String Hello(const CallbackInfo& info) {
return String::New(info.Env(), HelloWorld());
}
Object Init(Env env, Object exports) {
exports.Set("hello", Function::New(env, Hello));
exports.Set("addNumber", Function::New(env, AddNumber));
return exports;
}
NODE_API_MODULE(hello, Init)