Skip to content

Commit 7ca7b6d

Browse files
authored
Add some comments (#191)
Very basic comments to help explain what the Env variable is doing and how the memory handoff is working.
1 parent 0590fba commit 7ca7b6d

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

build_with_cmake/node-addon-api/hello.cc

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
#include <napi.h>
22

3+
34
static Napi::String Method(const Napi::CallbackInfo& info) {
5+
// Napi::Env is the opaque data structure containing the environment in which the request is being run.
6+
// We will need this env when we want to create any new objects inside of the node.js environment
47
Napi::Env env = info.Env();
5-
return Napi::String::New(env, "Hello, world!");
8+
9+
// Create a C++ level variable
10+
std::string helloWorld = "Hello, world!";
11+
12+
// Return a new javascript string that we copy-construct inside of the node.js environment
13+
return Napi::String::New(env, helloWorld);
614
}
715

816
static Napi::Object Init(Napi::Env env, Napi::Object exports) {

0 commit comments

Comments
 (0)