问题
I need to expose C++ classes (packed as shared libraries) to the magic world of JavaScript.
The most obvious solution is to use Node.js/v8. Problem is that it has to run on PowerPC (please no comments on this...) and - alas! - v8 doesn't run on PowerPC (the v8-powerpc project seems to be dead).
I'm trying to understand if there's any other viable solution, at the moment some possibilities are:
- emscripten, which converts LLVM bitcode into JavaScript;
- WebKit's JavaScriptCore, although I'm not sure it will work (I'll have WebKit on the PowerPC anyway)
I'm not a JavaScript expert and I actually feel quite lost, so these are my questions:
- Is emscripten a valid solution? (have you ever used it?)
- Can anyone point me to any documentation on how to expose C++ to JavaScript using JavaScriptCore?
- Is there any other option, and/or which one would you adopt?
Many thanks,
Rippel
回答1:
Qt has a port of webkit that runs on powerpc and it has a javascript engine that allows you to call C++ code.
Qt: Making Applications Scriptable
回答2:
You can use Emscripten. And I have used it and am using it. Problems are:
- The JS/C community is IMO kind of suspicious/vary about Emscripten so you might not get much support there (usually the #emscripten IRC channel is pretty helpful).
- Emscripten compiles code fairly easy/well but you need to have a decend understanding of C to get a working solution. You will probably have to rewrite certain parts of your code to get it working as expected by your JavaScript engine (stuff like using main_loop, callbacks, etc.).
- Using Node.js you could also try to use the synchronous file api (see http://nodejs.org/api/fs.html) - but I fear you would have to change the Emscripten file access emulation, as it is mostly coded for Browser usage, right now.
回答3:
JavaScriptCore has JSObjectMakeFunctionWithCallback(). It looks like this potentially involves a lot of boilerplate code to convert arguments in and exceptions out, though.
回答4:
Now Node.js DOES run on PowerPC. See this github link (I think it runs on any system with a powerpc processor that runs linux.
来源:https://stackoverflow.com/questions/11157743/alternative-to-v8-for-exposing-c-objects-to-javascript-on-powerpc