title: How to statically store and call a node.js callback function
body: <p>I have a node.js addon that I developped for node 0.10 and I need to update it for the current node. I fixed most of the api changes but I'm stuck with the issue of storing a callback pointer statically for later call. I modified 3_callback example addon to show what I did so far and the error I get during compile. This is what I have so far (the compile error is added as commented lines):</p>
  
  <pre><code>#include &lt;node.h&gt;
  
  using namespace v8;
  
  typedef Persistent&lt;Function&gt; CallBack_t;
  
  static CallBack_t MyCallBack;
  
  void CallBack( char* str ) {
    Isolate* isolate = Isolate::GetCurrent();
    HandleScope scope( isolate );
  
    const unsigned argc = 1;
    Local&lt;Value&gt; argv[ argc ] = { String::NewFromUtf8( isolate, str ) };
    Local&lt;Function&gt; cb = Local&lt;Function&gt;::New( isolate, MyCallBack );
    cb-&gt;Call( isolate-&gt;GetCurrentContext()-&gt;Global(), argc, argv );
  }
  
  void RunCallback( const FunctionCallbackInfo&lt;Value&gt;&amp; args ) {
    Isolate* isolate = Isolate::GetCurrent();
    HandleScope scope( isolate );
  
    Local&lt;Function&gt; cb = Local&lt;Function&gt;::Cast( args[ 0 ] );
    MyCallBack = CallBack_t::New( isolate, cb );
    //..\addon.cc( 24 ) : error C2664 : 'v8::Function *v8::PersistentBase&lt;T&gt;::New(v8::Isolate *,T *)' : cannot convert argument 2 from 'v8::Local&lt;v8::Function&gt;' to 'v8::Function *' [E:\SoftwareProjects\node-addon-examples\trunk\3_global_callback\node_0.12\build\addon.vcxproj]
    //   with
    //   [
    //      T = v8::Function
    //   ]
    //..\addon.cc( 24 ) : note : No user - defined - conversion operator available that can perform this conversion, or the operator cannot be called  CallBack( "JavaScriptCallBack calling" );
  }
  
  void Init( Handle&lt;Object&gt; exports, Handle&lt;Object&gt; module ) {
    NODE_SET_METHOD( module, "exports", RunCallback );
  }
  
  NODE_MODULE( addon, Init )
  </code></pre>
  
  <p>I tried different alternative but none works so far. Where is the error?</p>