I've read the previous question here but it seems a bit unrelated. C++ lambda, when it captured nothing, is fine to be an argument of the v8::FunctionTemplate. But when it captured something I needed, compiler started to complain:
error: no matching function for call to 'v8::FunctionTemplate::New(
BaseContext::New(const v8::Arguments&)::<lambda(const v8::Arguments&)>)
And here is the test code:
int a = 3;
Local<FunctionTemplate> failed = FunctionTemplate::New(
[=, a](const Arguments& args)-> Handle<Value>
{
a = a+a;
});
Local<FunctionTemplate> success = FunctionTemplate::New(
[](const Arguments &args) -> Handle<Value>
{
int a = 3;
});
I want to use the lambda feature because it's no reason to define small static functions which will actually become callbacks in another function. But the only difference between capturing and none capturing really bothers me, and the error message seems caused by the lambda itself, no matter whether it capture things or not.