-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathObjCppClass.mm
45 lines (34 loc) · 1.15 KB
/
ObjCppClass.mm
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
37
38
39
40
41
42
43
44
#include <nan.h>
#import "ObjCppClass.h"
#import "InteropFramework-Swift.h"
using v8::FunctionTemplate;
using v8::Object;
using v8::String;
using Nan::GetFunction;
using Nan::New;
using Nan::Set;
NAN_METHOD(SayHello) {
SwiftClass *swiftClass = [[SwiftClass alloc] init];
[swiftClass sayHello];
}
NAN_METHOD(Add) {
uint32_t x = Nan::To<int32_t>(info[0]).FromJust();
uint32_t y = Nan::To<int32_t>(info[1]).FromJust();
SwiftClass *swiftClass = [[SwiftClass alloc] init];
int result = [swiftClass addXWithX:x andY:y];
info.GetReturnValue().Set(result);
}
NAN_METHOD(RunKeyCheck) {
SwiftClass *swiftClass = [[SwiftClass alloc] init];
bool result = [swiftClass runKeyCheck];
info.GetReturnValue().Set(result);
}
NAN_MODULE_INIT(InitAll) {
Set(target, New<String>("sayHello").ToLocalChecked(),
GetFunction(New<FunctionTemplate>(SayHello)).ToLocalChecked());
Set(target, New<String>("add").ToLocalChecked(),
GetFunction(New<FunctionTemplate>(Add)).ToLocalChecked());
Set(target, New<String>("runKeyCheck").ToLocalChecked(),
GetFunction(New<FunctionTemplate>(RunKeyCheck)).ToLocalChecked());
}
NODE_MODULE(InteropFramework, InitAll)