Thanks. Here is a more complete set of #defines: #ifdef NEWAPI #define BUFFER_TYPE Local<Value> #define BUFFER_TO_HANDLE(ARG) (ARG) #define RETURN_TYPE void #define RETURN(v) { args.GetReturnValue().Set(v); return; } #define ARGUMENTS v8::FunctionCallbackInfo<Value> #define LOCAL_VALUE(h) (h) #define FUNCTION_TO_PERSIST(pfn, fn) pfn.Reset(Isolate::GetCurrent(), fn) #define FUNCTION_TO_HANDLE(pfn) Local<Function>::New(Isolate::GetCurrent(), pfn) #else #define BUFFER_TYPE Buffer* #define BUFFER_TO_HANDLE(ARG) Local<Value>::New((ARG)->handle_) #define RETURN_TYPE Handle<Value> #define RETURN(v) return scope.Close(v) #define ARGUMENTS Arguments #define LOCAL_VALUE(h) Local<Value>(*h) #define FUNCTION_TO_PERSIST(pfn, fn) pfn = Persistent<Function>::New(fn) #define FUNCTION_TO_HANDLE(pfn) Local<Function>::New(pfn) #endif
On Monday, July 15, 2013 10:48:53 AM UTC+2, Floby wrote: > > This will help for sure. I'll have to migrate node-libspotify soon. Thanks > for sharing ! > > On Saturday, 13 July 2013 22:46:57 UTC+2, Bruno Jouhier wrote: >> >> OK. I managed to get my first addon converted (and it passes basic >> tests). Unfortunately it is not public so I cannot give it as example >> >> I did it with some silly macros that let me support both the old and new >> APIs: >> >> #ifdef NEWAPI >> #define BUFFER Local<Value> >> #define BUFFERCONV(ARG) (ARG) >> #define RETURNTYPE void >> #define RETURN args.GetReturnValue().Set >> #define ARGUMENTS v8::FunctionCallbackInfo<Value> >> #else >> #define BUFFER Buffer* >> #define BUFFERCONV(ARG) Local<Value>::New((ARG)->handle_) >> #define RETURNTYPE Handle<Value> >> #define RETURN return scope.Close >> #define ARGUMENTS Arguments >> #endif >> >> Note: this assumes that the scope and args variables are named scope and >> args. >> >> I also had to convert a Persistent<Function> to a handle. I did it with: >> >> Local<Function> fn = Local<Function>::New(Isolate::GetCurrent(), >> persistent_fn) >> >> If this can help others... >> >> Bruno >> >> On Saturday, July 13, 2013 9:26:14 PM UTC+2, Bruno Jouhier wrote: >>> >>> The main things I'm having trouble with are Persistent<T> (an example >>> would be helpful) and Buffer (the class is gone, there is just a namespace). >>> >>> On Saturday, July 13, 2013 9:20:29 PM UTC+2, Bruno Jouhier wrote: >>>> >>>> The API has changed a lot because of the V8 changes. I'm trying to dig >>>> through the header files and the node diff ( >>>> https://github.com/bnoordhuis/node/commit/eb3a6c909dbd5086e7bc28013b61acbfcbefdc8d) >>>> >>>> but I'm a bit lost. >>>> >>>> Does anyone have some kind of cheat sheet that gives the most common >>>> rewriting patterns? Or just an addon that has been upgraded: the git diff >>>> could be a starting point for others. >>>> >>>> Bruno >>>> >>> -- -- Job Board: http://jobs.nodejs.org/ Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines You received this message because you are subscribed to the Google Groups "nodejs" group. To post to this group, send email to nodejs@googlegroups.com To unsubscribe from this group, send email to nodejs+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/nodejs?hl=en?hl=en --- You received this message because you are subscribed to the Google Groups "nodejs" group. To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.