Impact JavaScript Game Engine for iOS
phoboslab.org
phoboslab.org
This is true. You can compile Javascript Core and include it in your app. I have done this previously as an experiment.
However, there is one HUGE drawback in doing so: no compiled/jitted javascript code is possible.
This is because iOS applications are not allowed to create executable code in the heap or on the stack, so there is no way for JavaScriptCore to compile to native code when it is running as part of a third party application.
So unfortunately there is no good way to get this going at the same speed that you get when linking against the private framework.
Sad. This is also a major problem for other scripting languages. They all can only run in interpreted mode. Which might be good enough but is never the best you can get.
I wonder how feasible it would be to pre-compile the Javascript to machine code before distributing it? Maybe someone determined enough could probably hack one of the existing JIT engines to emit executable machine code to a file?
I'm not sure that solves the iphone problem though - I don't think it's kosher to use non c/c++/objc code. A Javascript to C compiler would work fine, though. That would be quite a bit more work, though.
[Edit]As pointed out below, it might well be ok. I guess you'd have to somehow get the generated machine code into a static library and link it with your application. That might work.
• The Javascript interpreter interface used is considered private and thus the app can not be distributed in the store.
• There is a history of private to public interface transitions, so perhaps…
• It suggests you could have all the game code be common between a web and a higher performance app version of a game.
• No word in the article about what percent speedup this represents.
Running in the browser, I had about 10 frames per second as noted in my previous blog post: http://www.phoboslab.org/log/2010/09/biolab-disaster
It sounds like this is basically a Canvas to OpenGL translation layer.
Can only the Canvas object be leveraged when creating games/apps with this? Or could a "account creation" screen be created leveraging HTML elements like forms (I would assume not since its sounds like its executed outside of Safari, and the translation provided is from Canvas > OpenGL)
What I mean by "reimplement", is providing a .drawImage function for JavaScript that works in the same way as it does in the browser, but uses OpenGL-ES behind the scenes. This reimplementation is done in native Objective C.
The changes I had to make to Impact (the "HTML5" engine) are concerned with the loading of images, scaling, input and getting a reference to the canvas element and its drawing context. But I guess I could provide a dummy "document" and "getElementById" function, so that you can just write some JavaScript using Canvas and run it in the browser and on the iPhone unchanged.
Note that this whole idea isn't exactly new: http://www.youtube.com/watch?v=0UN2iYrZmEY