开发者

How to call C++ functions/methods via JavaScript

开发者 https://www.devze.com 2022-12-11 05:13 出处:网络
does anybody know开发者_开发问答 how to call C++ functions or methods via JavaScript. Need scripting like Lua/Python-C++ but with JavaScript.

does anybody know开发者_开发问答 how to call C++ functions or methods via JavaScript. Need scripting like Lua/Python-C++ but with JavaScript.

Thanks in advance.


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...


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.


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


Mozilla's Spidermonkey:

https://developer.mozilla.org/en/JavaScript_C_Engine_Embedder%27s_Guide


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.


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?


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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消