I'm doing a addon
for nodejs
in c++
, I'm new mu% in c++
by the way, what I try to do is a function in javascript
that receives an object and this convert it to a std::string
in c++
, until now after researching in google, I have managed to convert the object that is passed from javascript
to an object Nan::MaybeLocal<v8::String>
using the example that is in the documentation of Nan
.
My c++
function is like this:
void ParseJSONToJSONString(const Nan::FunctionCallbackInfo<v8::Value>& info){
v8::Isolate* isolate = info.GetIsolate();
if(info.Length() != 1){
isolate->ThrowException(v8::Exception::TypeError(
v8::String::NewFromUtf8(isolate, "Se esperaba 1 argumento.")));
return;
}
//Usando el ejemplo
v8::Local<v8::Object> obj = Nan::To<v8::Object>( info[0] ).ToLocalChecked();
Nan::JSON NanJSON;
Nan::MaybeLocal<v8::String> result = NanJSON.Stringify( obj );
//Y ahora quisiera convertir la variable "result" que se supone que contiene el objeto que se paso desde javascript ya convertido en string, en un "std::string"
}
Since javascript
the function is called like this:
var dbm = require('./dbm');
//El modulo que estoy haciendo se llama 'dbm' por cierto.
dbm.saveJSONString({
uno: 1,
dos: "dos"
});
What I would like is to convert this variable from type Nan::MaybeLocal<v8::String>
to% std::string
to be able to treat it as std::string
.
Thank you very much in advance.