tags:

views:

367

answers:

8

Hi, does anybody know how to call C++ functions or methods via JavaScript. Need scripting like Lua/Python-C++ but with JavaScript.

Thanks in advance.

+1  A: 

Javascript instructions are interpreted by the browser, and I don't think there is a C++ layer for JS (not that it would make much sense anyway). What are you trying to achieve?

Pekka
He wants to use JavaScript as an extension language for his C++ application.
Kinopiko
+3  A: 

You can try Google's V8

http://code.google.com/p/v8/

artemb
+2  A: 

Mozilla's Spidermonkey:

https://developer.mozilla.org/en/JavaScript%5FC%5FEngine%5FEmbedder%27s%5FGuide

yk4ever
The question is how to access C++ objects from javascript...not how to access Javascript from within C++.
Bamerza
A: 

What about calling a server-side script via a Javascript XHR, that executes your C-program on system level?

Alex
A: 

JavaScript have different realisation (in different browsers) On Windows platform you can use C++ code in form of COM-objects

+2  A: 

I'm not aware of any cross-browser solution, but for Firefox I'd suggest XPCOM.

tstenner
+1  A: 

There are several different JavaScript engines you could use. I don't think they have a common programming interface so you'd have to pick one and work with it. Google Chrome uses V8 and Mozilla uses spidermonkey. Both V8 and spidermonkey are open source. I'd guess that spidermonkey is more mature since it's been around for a while. There is also WebKit JavaScript engine from Apple, also open source.

Wikipedia also has a list of JavaScript engines.

Kinopiko
A: 

Thanks guys for answers! Seems easy way will be using Lua for scripting.

Alex Ivasyuv
Good choice. Lua is better organized and easier to use, but lacks built-in Unicode support.
yk4ever