Reputation: 8824
does anybody know how to call C++ functions or methods via JavaScript. Need scripting like Lua/Python-C++ but with JavaScript.
Thanks in advance.
Upvotes: 22
Views: 27320
Reputation: 9371
You can try Google's V8:
open source JavaScript engine.
V8 is written in C++ and is used in Google Chrome, the open source browser from Google.
V8 implements ECMAScript as specified in ECMA-262, 3rd edition, and runs on Windows XP and Vista, Mac OS X 10.5 (Leopard), and Linux systems that use IA-32 or ARM processors.
V8 can run standalone, or can be embedded into any C++ application...
Upvotes: 12
Reputation: 14677
this is bit old question but if someone stumble upon this to find an answer i think this will be helpful https://developers.google.com/native-client/ but this works on Chrome only.
Upvotes: 7
Reputation:
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.
Upvotes: 1
Reputation: 10291
I'm not aware of any cross-browser solution, but for Firefox I'd suggest XPCOM.
Upvotes: 2
Reputation: 160
JavaScript have different realisation (in different browsers) On Windows platform you can use C++ code in form of COM-objects
Upvotes: 0
Reputation: 12433
What about calling a server-side script via a Javascript XHR, that executes your C-program on system level?
Upvotes: 0
Reputation: 840
Mozilla's Spidermonkey:
https://developer.mozilla.org/en/JavaScript_C_Engine_Embedder%27s_Guide
Upvotes: 1
Reputation: 449415
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?
Upvotes: 0