node-addon-examples icon indicating copy to clipboard operation
node-addon-examples copied to clipboard

adding example for wrapping pre-created objects

Open IngwiePhoenix opened this issue 12 years ago • 2 comments

Hey! This is more like something I am stuck at.

I have a library with header files, and I want to make bindings for that library. Yet, I can not change the already existing classes. So, I am looking for a way to wrap these existing classes into a nodejs module.

Currently, I am waiting for some peeps to respond. But it would still be awesome if that would be added here, as it is quite a usual case.

Kind regards, Ingwie! ^^

IngwiePhoenix avatar Jan 15 '14 10:01 IngwiePhoenix

generally the way you have to approach this is write completely new wrappers for the classes with explicit accessors, I don't believe there's a generic way to just wrap an object other than writing the whole wrapper yourself. I probably wouldn't bother subclassing either because your exposed methods need their own signatures for V8 so just keep a private instance of the class you're wrapping and write accessors for it.

Check out https://github.com/justmoon/node-bignum/blob/master/bignum.cc for some intensive wrapping of existing methods on existing classes.

rvagg avatar Jan 20 '14 02:01 rvagg

Should this issue remain open? Moreover, is this repository something that should be archived?

Trott avatar Mar 18 '18 04:03 Trott