Closed wang70937 closed 6 years ago
How to execute callback function in js (function download_callback)?
` class CDownloadFile { public: ...
int start(const char* szUrl, const char* szPath) { CURL *curl; CURLcode res; ... //set callback function here res = curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, ProgressCallback); ... return 0; } static int ProgressCallback(void *clientp, double dltotal, double dlnow, double ultotal, double ulnow) { std::cout << "dltotal: " << (long)dltotal << " ---- dlnow:" << (long)dlnow << "---- " << nPos <<"%" << std::endl; // v8::Isolate* isolate = dd->m_isolate; v8::Handle<v8::Function> fun = v8::Function::New(isolate, v8_arg_count);// v8::Handle<v8::Value> vRet = v8pp::call_v8(isolate, fun, fun, nPos); return 0; } ...
};`
//////////////////////////////////////// `... v8pp::class_ CDownloadFile_class(isolate); CDownloadFile_class .ctor() .set("start", &CDownloadFile::start) .set("callback", &CDownloadFile::setCallback) ;
... `
////////////////////////////////////////
`var curl = require('curl');
function download_callback(p) { console.log("download_callback execute..."); }
//download file var download = curl.download(); download.callback(download_callback); download.start("http://xxxx", "xxxxx.xxx");`
You can use v8::Function as an argument for C++ function callback, see #49
v8::Function
thanks @pmed
How to execute callback function in js (function download_callback)?
` class CDownloadFile { public: ...
};`
//////////////////////////////////////// `... v8pp::class_ CDownloadFile_class(isolate);
CDownloadFile_class
.ctor()
.set("start", &CDownloadFile::start)
.set("callback", &CDownloadFile::setCallback)
;
... `
////////////////////////////////////////
`var curl = require('curl');
function download_callback(p) { console.log("download_callback execute..."); }
//download file var download = curl.download(); download.callback(download_callback); download.start("http://xxxx", "xxxxx.xxx");`