itomas
itomas

Reputation: 11

Spidermonkey - Call javascript function from C# or C++ ( VIsual Studio 2010 )

I would like to embed spidermonkey engine calls in my C# (or C++) console app using VS2010, so I can send some values from C# code to the javascript functions and get the result back, but I don't know where and how to start.

Till now I have downloaded the spidermonkey source code and compiled it using mozilla-build tools. Now I am able to start js shell, load my .js file, run javascript functions inside it and get correct results.Than I created win32 C++ console app in VS2010, added js.lib and header files from my dist/include folder to project. Tried with simple example to start it up and really it builds with no errors (after only 3 days of trying) but on Run it throws system error - "Can't start because js.exe is missing from your computer."

Upvotes: 1

Views: 1714

Answers (1)

JavaMan
JavaMan

Reputation: 5034

If you would like to embed spidermonkey into your own C++ application, you should just treat the spidermonkey as a static or DLL library and link it to your own code.

I recommend not to bother with the js shell except, say, in my opinion, to test your spidermonkey build or test run some Javascript scripts in a standalone shell. You can also study the js shell source code to get a feel of how to use the JSAPI function calls properly. But for embedding spidermonkey into your own C++ application, js shell offers no special API. It is just another console application that USES the JSAPI exposed by spidermonkey.

Check out jsapi.h in your build directory. These are the function calls that your own application should use. In particular, I think you would normally create many JSNative functions exposed as Javascript functions.

Upvotes: 1

Related Questions