Calling C ++ from JavaScript?

7

I have a C ++ simulation. I passed this simulation to JavaScript so that the user could play with it in the browser, but it was much slower. If possible, therefore, I would call the function itself in C ++ within JavaScript and do this on the client side. Is it possible?

    
asked by anonymous 07.08.2014 / 00:30

2 answers

2

Before departing for NaCl, which is unique to Chrome, try using Emscripten , an LLVM-based compiler which transforms C and C ++ code into asm.js . Asm.js is a subset of JavaScript that modern engines can optimize well and run with near-native performance.

The installation is quite easy . The site also has a little tutorial .

    
07.08.2014 / 03:31
1

In addition to the above options, you could also use Node-Webkit which ships the node.js + chrome engine.

Performs as a normal program, but looks like a Browser, limited only to the application you want to display.

This way you can control both the javascript client when backend in C ++ and package everything as one application only. The only limitation is that your user would have to install the executable, but if that's not a problem, I think it's the option that gives you the most flexibility with the least possible headache compared to Nacl (learning overhead) or Emscripten (runtime overhead)

    
07.08.2014 / 04:12