I have a v8::Persistent<v8::Function>
that I need to turn into a void(__cdecl*)
function. I was suggested to use a wrapper, but I'm unsure of how to do this.
Asked
Active
Viewed 191 times
0

Alex
- 131
- 2
- 13
-
Check [passing-functor-as-function-pointer](https://stackoverflow.com/questions/1840029/passing-functor-as-function-pointer) – Victor Gubin Jan 30 '20 at 14:40
1 Answers
0
For example like this:
v8::Persistent<v8::Function> func = ...;
v8::Persistent<v8::Context> context = ...;
v8::Isolate* isolate = ...;
void cpp_func(...) {
v8::Local<v8::Context> ctx = v8::Local<v8::Context>::New(isolate, context);
// The "this" inside the JavaScript function:
v8::Local<v8::Object> arg_this = ctx->Global();
// Arguments to the JavaScript function, of type `v8::Local<v8::Value>[]`.
int argc = 0;
int argv = nullptr;
func->Call(ctx, arg_this, argc, argv);
}
There are many many more examples in V8's test-api.cc.

jmrk
- 34,271
- 7
- 59
- 74