commit 722db25e6cb6fd2e4e54e420594d54c332c3cc13 Author: birme Date: Sat Jun 13 00:57:57 2020 +0200 Hello world diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..dd87e2d --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +node_modules +build diff --git a/binding.gyp b/binding.gyp new file mode 100644 index 0000000..21f0ae1 --- /dev/null +++ b/binding.gyp @@ -0,0 +1,19 @@ +{ + "targets": [{ + "target_name": "node_srt", + "cflags!": [ "-fno-exceptions" ], + "cflags_cc!": [ "-fno-exceptions" ], + "sources": [ + "src/binding.cc", + "src/node-srt.cc" + ], + 'include_dirs': [ + " +#include "node-srt.h" + +Napi::Object InitAll(Napi::Env env, Napi::Object exports) { + return NodeSRT::Init(env, exports); +} + +NODE_API_MODULE(NODE_GYP_MODULE_NAME, InitAll) \ No newline at end of file diff --git a/src/node-srt.cc b/src/node-srt.cc new file mode 100644 index 0000000..b49f1a3 --- /dev/null +++ b/src/node-srt.cc @@ -0,0 +1,30 @@ +#include "node-srt.h" + +Napi::FunctionReference NodeSRT::constructor; + +Napi::Object NodeSRT::Init(Napi::Env env, Napi::Object exports) { + Napi::HandleScope scope(env); + + Napi::Function func = DefineClass(env, "NodeSRT", { + InstanceMethod("hello", &NodeSRT::Hello) + }); + + constructor = Napi::Persistent(func); + constructor.SuppressDestruct(); + + exports.Set("NodeSRT", func); + return exports; +} + +NodeSRT::NodeSRT(const Napi::CallbackInfo& info) : Napi::ObjectWrap(info) { + Napi::Env env = info.Env(); + Napi::HandleScope scope(env); +} + +Napi::Value NodeSRT::Hello(const Napi::CallbackInfo& info) { + Napi::Env env = info.Env(); + Napi::HandleScope scope(env); + + Napi::String returnValue = Napi::String::New(env, "Hello World"); + return returnValue; +} \ No newline at end of file diff --git a/src/node-srt.h b/src/node-srt.h new file mode 100644 index 0000000..d53af28 --- /dev/null +++ b/src/node-srt.h @@ -0,0 +1,11 @@ +#include + +class NodeSRT : public Napi::ObjectWrap { + public: + static Napi::Object Init(Napi::Env env, Napi::Object exports); + NodeSRT(const Napi::CallbackInfo& info); + + private: + static Napi::FunctionReference constructor; + Napi::Value Hello(const Napi::CallbackInfo& info); +}; \ No newline at end of file