Last active
June 15, 2018 09:56
-
-
Save a7ul/da3e65e25164fdc80961406501eb0897 to your computer and use it in GitHub Desktop.
blog-on-node-addon-add-class-diff
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| diff --git a/binding.gyp b/binding.gyp | |
| index 2d188af..031bf18 100644 | |
| --- a/binding.gyp | |
| +++ b/binding.gyp | |
| @@ -5,7 +5,9 @@ | |
| "cflags_cc!": [ "-fno-exceptions" ], | |
| "sources": [ | |
| "cppsrc/main.cpp", | |
| - "cppsrc/Samples/functionexample.cpp" | |
| + "cppsrc/Samples/functionexample.cpp", | |
| + "cppsrc/Samples/actualclass.cpp", | |
| + "cppsrc/Samples/classexample.cpp" | |
| ], | |
| 'include_dirs': [ | |
| "<!@(node -p \"require('node-addon-api').include\")" | |
| diff --git a/cppsrc/main.cpp b/cppsrc/main.cpp | |
| index f62ed77..2b739d3 100644 | |
| --- a/cppsrc/main.cpp | |
| +++ b/cppsrc/main.cpp | |
| @@ -1,8 +1,10 @@ | |
| #include <napi.h> | |
| #include "Samples/functionexample.h" | |
| +#include "Samples/classexample.h" | |
| Napi::Object InitAll(Napi::Env env, Napi::Object exports) { | |
| - return functionexample::Init(env, exports); | |
| + functionexample::Init(env, exports); | |
| + return ClassExample::Init(env, exports); | |
| } | |
| -NODE_API_MODULE(testaddon, InitAll) | |
| +NODE_API_MODULE(NODE_GYP_MODULE_NAME, InitAll) | |
| diff --git a/index.js b/index.js | |
| index 72860f8..d849e0e 100644 | |
| --- a/index.js | |
| +++ b/index.js | |
| @@ -2,4 +2,9 @@ const testAddon = require('./build/Release/testaddon.node'); | |
| console.log('addon',testAddon); | |
| console.log('hello ', testAddon.hello()); | |
| console.log('add ', testAddon.add(5, 10)); | |
| + | |
| + | |
| +const classInstance = new testAddon.ClassExample(4.3); | |
| +console.log('Testing class initial value : ',classInstance.getValue()); | |
| +console.log('After adding 3.3 : ',classInstance.add(3.3)); | |
| module.exports = testAddon; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment