我正在集成一些使用 void * 作为上下文对象(在本例中为 v8 函数)的代码,我希望将其转换回函数,但这会导致编译错误。您如何看待这种情况?
void callback(void* context) {
Local<Function> func = static_cast<Local<Function> *>(context);
func->Call(Context::GetCurrent()->Global(), 1, 0);
}
这是注册回调的代码。请注意,fn 作为 void * 传递给“回调”。
Persistent<Function> fn = Persistent<Function>::New(Handle<Function>::Cast(args[0]));
registerEvent(&callback, /* context*/ &fn);
最佳答案
为了使其正常工作,您需要转换 context
并将其分配给这样的指针值:
Local<Function> *func = static_cast<Local<Function> *>(context);
关于c++ - 从 void * 转换为 Local<Function>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13809262/