Skip to content

Instantly share code, notes, and snippets.

@yoshoku
Created April 23, 2022 10:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yoshoku/b320fd899dcf14b0ca1707e92e7775d3 to your computer and use it in GitHub Desktop.
Save yoshoku/b320fd899dcf14b0ca1707e92e7775d3 to your computer and use it in GitHub Desktop.
console.log with node-addon-api
#include <napi.h>
class Foo : public Napi::ObjectWrap<Foo> {
public:
// ...
Napi::Value foo(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::Function consoleLog = env.Global().Get("console").As<Napi::Object>().Get("log").As<Napi::Function>();
consoleLog.Call({ Napi::String::New(env, "Hello, World.") });
// ...
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment