-1

In Node C++ Addon, I can return a String like this:

void Method(const FunctionCallbackInfo<Value>& args) {
  Isolate* isolate = args.GetIsolate();  
  args.GetReturnValue().Set(
    String::NewFromUtf8(isolate, "hello")
      .ToLocalChecked()
  );
}

How can I achieve the same but setting a boolean value instead of a string?

Emad Omar
  • 729
  • 9
  • 23
  • 1
    There is an overload of `Set` that accepts a `bool`: https://v8docs.nodesource.com/node-4.8/da/da7/classv8_1_1_return_value.html#abbe0803e94a0eb36d04d9bd17ecb96a0 - what's the problem with that one? Of course you will also have to change the template parameter of `args` for that – UnholySheep Sep 10 '20 at 12:49
  • @UnholySheep I wasn't aware of it, and I couldn't locate that docs site. Thanks for the answer, and for sharing the source. – Emad Omar Sep 10 '20 at 12:51

1 Answers1

0

Thanks to @UnholySheep for providing links to the V8 docs.

args.GetReturnValue().Set() has an overload the accepts a bool, so you can just pass it directly.

void Method(const FunctionCallbackInfo<Value>& args) {
  Isolate* isolate = args.GetIsolate();  
  args.GetReturnValue().Set(true);
}
Emad Omar
  • 729
  • 9
  • 23