Alex Ivasyuv
Alex Ivasyuv

Reputation: 8824

How to call C++ functions/methods via 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.

Upvotes: 22

Views: 27320

Answers (8)

artemb
artemb

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

Keshan
Keshan

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

user181548
user181548

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

tstenner
tstenner

Reputation: 10291

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

Upvotes: 2

user204724
user204724

Reputation: 160

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

Upvotes: 0

Alex
Alex

Reputation: 12433

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

Upvotes: 0

Pekka
Pekka

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

Related Questions