Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
240 views
in Technique[技术] by (71.8m points)

Embed a JavaScript engine in an iOS application

I wonder if anyone has successfully ported a javascript engine/interpreter to iOS. I'm writing an iPhone game that I would like to use Javascript as the high-level scripting language (AI, gameplay, etc.), but to do that, I need to compile the JS engine into a static library and link it against my objectiveC program for iPhone OS. There are some candidate JS engine I'm looking at but I couldn't find any successful cases for doing that.

Here're the js engine I was hoping to use for iOS

  • google's V8 javascript engine
  • mozilla's SpiderMonkey

The alternative is to use UIWebView's Javascript callback interface, but that requires loading the entire UIWebView into memory and the experiences I heard is that it is usually slow in performance.

Appreciate if anyone had similar experiences of do this or know any references for that!

[UPDATED] as Kostis mentioned, Apple introduced JavascriptCore in WWDC 2013

question from:https://stackoverflow.com/questions/5317776/embed-a-javascript-engine-in-an-ios-application

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

There are two projects you might be interested in:

  1. JavaScriptCore-iOS
  2. iMonkey

It is absolutely possible to build and ship a JavaScript engine with your iOS app, see http://www.phoboslab.org/log/2011/04/ios-and-javascript-for-real-this-time. Titanium does that, too: https://github.com/appcelerator/webkit_titanium/tree/master/Source/JavaScriptCore. Also see http://www.phoboslab.org/log/2011/06/javascriptcore-project-files-for-ios.

I've also made a small app that shows how to use JSC on iOS: https://github.com/jfahrenkrug/AddressBookSpy

Enjoy.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...