How to convert int to string in nan, C++?

417 views Asked by At

So, I got that:

void Method(const Nan::FunctionCallbackInfo<v8::Value>& info) {
    v8::Local<v8::Context> context = info.GetIsolate()->GetCurrentContext();
    int last_number = info[0]->NumberValue(context).FromJust();
    info.GetReturnValue().Set(Nan::New<(fib(last_number)));
}

https://github.com/nodejs/nan is used here I need to return a string value from this function. Function fib returns an int value. Any way to convert int to string here gives me different errors.

1

There are 1 answers

0
Criminal_Affair_At_SO On

If s is a const char *, then:

if (!s) {
  info.GetReturnValue().Set(Nan::Null());
} else {
  info.GetReturnValue().Set(Nan::New<v8::String>(s).ToLocalChecked());
}