我想在C++中執行回調(其中C++作爲node.js程序的一部分運行)。回調是第三方庫,當數據通過時它將調用回調函數。C++ V8對象上下文
我似乎遇到的問題是與變量類型:
static void sensorEventCallback(const char *protocol, const char *model,
int id, int dataType, const char *value, int timestamp,
int callbackId, void *context)
{
//process the data here
}
Handle<Value> sensorEvents(const Arguments& args) {
HandleScope scope;
...
callbackId = tdRegisterSensorEvent(
reinterpret_cast<TDSensorEvent>(&telldus_v8::sensorEventCallback),
Context::GetCurrent()->Global());
}
我發現了該錯誤:
error: cannot convert ‘v8::Local<v8::Object>’ to ‘void*’ for argument ‘2’ to ‘int tdRegisterSensorEvent(void ()(const char, const char*, int, int, const char*, int, int, void*), void*)’
它似乎與參數2於上下文中掙扎。任何關於如何將V8對象轉換爲tdRegisterSensorEvent可以接受的想法?
看起來你需要傳遞對象的地址而不是對象本身。 –
@ n.m。不應該主張[貨物崇拜編程](http://en.wikipedia.org/wiki/Cargo_cult_programming)*(特別是當v8.h是公開源代碼時)*。 'Context :: GetCurrent() - > Global()'返回一個'Local'... –
HostileFork
@HostileFork:我應該說「一個對象」而不是「對象」,對此我表示歉意。如果一個C函數需要一個'void *',你通常會傳遞一個對象的地址。我沒有任何意義。 –