3 ms·
Getting your C++ to the Web with Node.js
- vvanders 11y agoKinda surprised there's not a mention of emscripten in the options.
- nice_byte 11y agoI guess Emscripten is the less reliable route. I think one can't reasonably expect any C++ code to be readily compileable with emscripten with no modifications whatsoever
- Ace17 11y agoYou might be surprised when you try it. Emscripten probably is the most reliable route, and also the most secure (Javascript VM sandboxing, which you don't have with native CGIs). If your C++ code doesn't directly use system APIs (CreateFileA, execvp(), etc.) or extra I/O libraries (OpenGL1.0, SDL2), Emscripten will compile it just fine.
- nice_byte 11y ago> If your C++ code doesn't directly use system APIs or extra I/O libraries That's exactly the case I had in mind. Most C++ code hasn't really been written with Emscripten in mind
- kartan 11y agoWe are using Emscripten for compiling C++ to to Javascript and use it on the browser. And it works well. So at this moment we can use the same code base for Android(JNI)/iOS/Facebook. It works perfectly well. Why do you think that it is not reliable?
- nice_byte 11y agoI assume you wrote your code while keeping in mind that it will be compiled by ES. But we're talking about porting legacy code. ES may be reliable, but you have to have the source code for all of your dependencies and not rely on platform-specific functions at all.
- azakai 11y agoIn general there is no need to write code in mind for compiling with Emscripten. The codebase just needs to be reasonably portable C++ or C. For example, if the codebase runs on both x86 desktop and ARM Android, then it will almost certainly run properly using Emscripten. For APIs, you also need to use something portable and standard, like SDL for example.
- kartan 11y agoWe are using Emscripten for compiling C++ to to Javascript and use it on the browser. And it works well. So at this moment we can use the same code base for Android(JNI)/iOS/Facebook. It works perfectly well. Why do you think that it is not reliable?
- nice_byte 11y agoIf you're feeling adventurous and don't mind the performance penalty, I guess you could try compiling the C++ source into asm.js with Emscripten for the added bonus of having it work in modern browsers.
- panic 11y agoThe simplicity and ease of use of C++ combined with the blazing performance of JavaScript. Truly the best of both worlds!
- keithwhor 11y agoI recognize how tongue-in-cheek this is (I laughed), but in all fairness, V8 is... really, really fast. Not really fair to the team to be mocking it anymore. :)
- such_a_casual 11y agoThe real answer is to reprogram the whole thing in JavaScript. C++ just doesn't have the amazing frameworks that make JavaScript a developer's dream. I have even heard rumors that if you use the right ones, JavaScript becomes a programming language!
- therein 11y agoWhat's next, a turing complete Javascript? We'll all get downvoted if someone misses the sarcasm. :)
- nice_byte 11y agoIf you just want to reuse some logic that you already havein C++ and don't care about the performance that much - why not :)
- Ace17 11y agoSo I have this big chunk of legacy C++ code, I don't want to rewrite it, because it's a huge horrible mess and I don't have the source code of all its dependencies anyway. So I'm gonna compile it to native code and run it as a CGI. What could possibly go wrong?