views:

401

answers:

2

I am embedding SpiderMonkey to make my C++ library scriptable. To make it extendable, I need it possible to define a new class (JavaScript) inheriting one C++ base class of the library.

Is there an example showing me how to do that using SpiderMonkey?

+1  A: 

I don't know it's possible, but a feeling says you're better off writing a wrapper class in JavaScript for the class in the C++ library.

Gorkem Pacaci
+3  A: 

I'd think you cannot subclass a C++ class in SpiderMonkey/JavaScript and use it transparently in the rest of your C++ code. However, you could create a wrapping class in C++ that delegates its work to a couple of JavaScript classes/functions. If you make your C++ class configurable enough that should work for your situation. Both calling JavaScript code from C and C code from JavaScript is explaind in the JSAPI User Guide page (I think you've already read that one).

Simon Groenewolt