22 May '13 - 06:58 *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
 
   Home   Help Search Login Register  
Pages: [1]
  Reply  |  Print  
Author Topic: Binding non-static c++ procs?  (Read 530 times)
AndroidMediaPlayer
Posts: 13


« on: 28 Jul '12 - 17:11 »
Reply with quoteQuote

Hi!

I have a new problem binding BASS to Node.js. I already have bound some functions, and everything works fine. Now i'm trying to implement the proc functionality, and here i stuck now. While Bass is written in C, Node.js extensions are going to be written in c++. Additionaly i need to wrap all javascript callbacks in my own class to get methods with single parameteres instead of args arrays (that are used to call the javascript callbacks in c++).

But now, how can i use c++ non-static class methods from object instances as callback procs for BASS? I already have tried std::function and std::bind, but my compiler won't cast from function<...> to (*ptr). Is there a special way to do this?

Ian, do you maybe have information about how the .NET Bindings solve this problem?

Thank you! Smiley
Logged
Ian @ un4seen
Administrator
Posts: 15259


« Reply #1 on: 30 Jul '12 - 16:55 »
Reply with quoteQuote

I'm not a .Net user myself (or Node.js for that matter), so I'm afraid I can't advise on that, but in C++, you would need to make the callback function "static" and pass the class instance (eg. "this") in the sync's "user" parameter. The callback function can then call the class's non-static methods. Here's a thread on the subject from way back (the code would be slightly different today)...

   www.un4seen.com/forum/?topic=1184
Logged
AndroidMediaPlayer
Posts: 13


« Reply #2 on: 30 Jul '12 - 18:29 »
Reply with quoteQuote

Hi Ian,

the node.js bindings are written in c++, (like JAVA VM bindings too, in .NET i forgot you can bind directly from .NET without extra c++ code), so i need to find a solution in c++. I have tried a similar solution like in topic 1184 without an extra class, i just gave the js callback directly to the BASS_SetSyncPRoc as the user parameter, but the call inside the syncproc crashes Node.js with a segmentation fault (memory snapsnots) error (like in your example in topic 1184 too). :/
« Last Edit: 30 Jul '12 - 18:40 by AndroidMediaPlayer » Logged
Ian @ un4seen
Administrator
Posts: 15259


« Reply #3 on: 31 Jul '12 - 14:44 »
Reply with quoteQuote

I'm not at all familiar with Node.js, so I can't really say what the problem or solution is, but if it's like .Net or Java, perhaps the problem is that the callback function/object/delegate is being garbage collected? Does the Node.js callback function get called?
Logged
AndroidMediaPlayer
Posts: 13


« Reply #4 on: 31 Jul '12 - 17:20 »
Reply with quoteQuote

D'OH!

Yes, it was garbage collected. -,-'

I had to make my callback persistent, so now all works fine. Smiley
Logged
Pages: [1]
  Reply  |  Print  
 
Jump to:  

Powered by SMF 1.1.18 | SMF © 2013, Simple Machines