I have this template:
template <class T>
v8::Handle<v8::Value> jsFunctionTemplate(const v8::Arguments &args)
{
T *t = static_cast<T*>(args.This()->GetPointerFromInternalField(0));
if (t != NULL) t->volume(args[0]->NumberValue());
return args.This();
}
I want to make it 100% dynamic, so I’m hoping to replace t->volume with a pointer (std::mem_fn?). The thing is, I can’t figure out from similar examples/questions how to retain the jsFunctionTemplate’s current type (it must be a v8::InvocationCallback)
typedef Handle<Value> (*InvocationCallback)(const Arguments& args);
So that it’s usage can still be:
audio->PrototypeTemplate()->Set("Volume", v8::FunctionTemplate::New(&jsFunctionTemplate<Audio>));
I am not opposed to using even C++11 syntax.
I don’t claim to fully understand the limitations which the v8 API imposes here, but if a template argument for the type is all right, then I hope you can use a pointer-to-member template argument for what you want to achieve here. The following self-contained and tested example, although without v8, should demonstrate how this can be done:
Applied to your situation, and assuming
NumberTypeto be the return value of thatNumberValuecall, or more importantly the type of the first argument of the functions you want to call, it would look something like this:In contrast to the example above, this here is untested, but on the other hand closer to your code. Together they should make the idea crystal clear, I hope.