在iOS应用程序中嵌入JavaScript引擎 [英] Embed a JavaScript engine in an iOS application

查看:113
本文介绍了在iOS应用程序中嵌入JavaScript引擎的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有人成功将一个javascript引擎/解释器移植到iOS。我正在编写一款iPhone游戏,我想使用Javascript作为高级脚本语言(AI,游戏等),但要做到这一点,我需要将JS引擎编译成静态库并将其链接我的iPhone OS的objectiveC程序。我正在看一些候选JS引擎,但我找不到任何成功案例。

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.

这是我希望用于iOS的js引擎

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


  • 谷歌的V8 javascript引擎

  • mozilla的SpiderMonkey

另一种方法是使用 UIWebView的 Javascript回调接口,但需要将整个 UIWebView 加载到内存中,我听到的经验是性能通常很慢。

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!

[更新]正如Kostis所说,Apple在WWDC 2013中推出了 JavascriptCore

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

推荐答案

对于未来的观众,现在有新的iOS 7中引入的JavaScriptCore框架。它真的很神奇!从/向JS / Objective-C包装,展开值,调用函数,回调,所有内容!

For future viewers, now there is the JavaScriptCore framework, introduced in the new iOS 7. It does magic! Wrapping, unwrapping values from/to JS/Objective-C, calling functions, callbacks, everything!

不幸的是,文档目前很差。您可以在 WWDC 2013活动中找到演示文稿,并在标题文件中找到更多信息(cmd +点击标题Xcode中的文件名)。还有一些关于互联网的教程,它只是复制了WWDC演示文稿中的人。

Unfortunately, documentation is really poor at the moment. You can find a presentation from the WWDC 2013 event and some more info in the header files (cmd+click on the header file name in Xcode). There are also some tutorial around the internets which just copy what the guy in the WWDC presentation does.

我已将它用于我的一个项目,它非常强大。我不喜欢的唯一想法是它通过值将对象从JS传递给ObjC,即引用丢失了。可能有一个解决方法,但没有适当的文档我找不到任何东西。

I've used it for one of my projects, it's really powerful. The only think I didn't like is that it passed objects from JS to ObjC by value, i.e. reference was lost. There might be a workaround for this, but I couldn't find anything without proper documentation.

希望这会帮助某人:)

这篇关于在iOS应用程序中嵌入JavaScript引擎的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆