22

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

Thanks in advance.

2
  • 1
    On which platform, in what context? Commented Nov 6, 2009 at 13:00
  • Relevant search results for this question can be found here Commented Feb 15, 2013 at 18:02

8 Answers 8

12

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

Sign up to request clarification or add additional context in comments.

Comments

7

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.

1 Comment

Native Client is no longer supported in Chrome, but it is still possible to call C++ functions from JavaScript using Emscripten.
2

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

Comments

1

Mozilla's Spidermonkey:

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

1 Comment

The question is how to access C++ objects from javascript...not how to access Javascript from within C++.
1

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.

Comments

0

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?

2 Comments

He wants to use JavaScript as an extension language for his C++ application.
This is not really an answer, if so, it should be a comment.
0

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

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.