2016-06-10 37 views
0

我想使用舊的v8 API更新一個node.js插件。如何將node-addon持久<function>轉換爲本地<function>?

這裏是我的wrapper.cpp代碼:

std::map<int, Persistent<Function> > WrapMdUser::callback_map; 

void WrapMdUser::FunCallback(CbRtnField *data) { 
std::map<int, Persistent<Function> >::iterator cIt = callback_map.find(data->eFlag); 
Local<Number> argv[1] = Nan::New(data->nReason); 
cIt->second->Call(Nan::GetCurrentContext()->Global(), 1, argv); 
} 

如果我理解正確的話,筆者使用的地圖Persistent<function>存儲回調中(見callback_map STD),但是當node-gyp build,編譯器拋出此錯誤:

wrapper.cpp:331:19: error: base operand of ‘->’ has non-pointer type ‘v8::Persistent<v8::Function>’ 
cIt->second->Call(Nan::GetCurrentContext()->Global(), 1, argv); 

將此代碼更新到新的v8 API的最佳方法是什麼,以便我可以使用最後一個節點版本運行它?

非常感謝。

+1

很確定這個問題在這裏介紹:https://stackoverflow.com/questions/13826803/calling-javascript-function-from-a-c-callback-in-v8/28554065#28554065 –

回答

0

我找到了答案在此article,持續需要轉換到本地功能第一:

Local<Function>::New(isolate, work->callback)-> 
Call(isolate->GetCurrentContext()->Global(), 1, argv); 

感謝@Scott釋放。

相關問題