Sono nuovo in Javascript e nella libreria V8. Il mio requisito è chiamare una funzione C++ e restituire una struct C al modulo Javascript.come restituire una struct dalla funzione V8 C++ al modulo javascript
struct empDetails {
int empNo;
string empName;
};
v8::Handle<v8::Value> getDetails(const v8::Arguments &args) {
if ((args.Length() != 1) || !args[0]->IsUint32()) {
return v8::ThrowException(v8::Exception::Error
(v8::String::New("Invalid> arguments.")));
}
uint32_t userId = args[0]->ToUint32()->Value();
empDetails e;
company::GetEmpdetails(userId, e); // other static function in my project
return e;
}
A dichiarazione di ritorno, sto ricevendo errore. Qualcuno potrebbe dirmi come restituire una struct dalla funzione V8 C++.
Che cosa significa per restituire uno struct C a JavaScript? Non vorresti (necessario?) Per avvolgerlo in un oggetto JavaScript come '{empNo: 1, empName:" John Doe "}'? – maerics
La sezione [V8 embedder's guide about Object Templates] (https://developers.google.com/v8/embed#templates) probabilmente ti porterà sulla giusta strada. – maerics
sembra non aver letto abbastanza sui template degli oggetti v8, grazie per la tua risposta – coder