在 Android 应用程序中嵌入脚本解释器

发布于 2024-11-04 19:43:12 字数 525 浏览 5 评论 0原文

我正在尝试构建一个 Android 应用程序,它读取用 Java 语法编写的 txt 文件并通过其他语言对其进行编译。

跳过 java->script,我想知道如何嵌入脚本解释器或可以编译脚本代码的东西。

所以基本功能是:读取脚本代码,编译它,给出结果。例如显示 Hello World 屏幕。

我知道有“官方”sl4a 应用程序,但我只想从中获取编译片段并将其嵌入到我自己的应用程序中。是否可以?

顺便问一下,有没有解析器可以将 java 代码转换为 Python 代码或其他脚本语言?如果是这样,我应该如何读取java代码,作为来自txt或html的字符串?

多谢。


感谢大家帮忙! 抱歉,我不知道应该如何编辑自己的帖子,所以就这样做。

我在下面对 Femi 的回复中详细解释了为什么我要尝试这样做,以便您可以查看。

简而言之,我只想让我的应用程序读取 java 代码并编译它。由于Android下没有java解释器或编译器,我必须使用其他语言。不知道怎么办。

谢谢你!

I am trying to build an Android app which read a txt file written in Java syntax and compile it via other language.

Skip java->script, I want to know how I can embed a script interpreter or something that would compile the script code.

So the basic functionality is: read the script code, compile it, give the result. e.g. show a Hello World screen.

I know there is "official" sl4a app, but I just want the compiling piece from it and embedded in my own app. Is it possible?

Btw is there any parser that translate the java code to a Python code or other script language? If so how should i read in the java code, as a string from txt or html or?

Thanks a lot.


Thanks to everyone helps!
Sorry I don't know how I should edit my own post so just do it like this.

I explained in details why I am trying to do this in my response to Femi below so you can check that out.

Briefly I just want my app to read in java code and compile it. Since there is no java interpreter or compiler under Android i have to use other language. Don't know how.

Thank you!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

暮年慕年 2024-11-11 19:43:12

嗯,这是一个奇怪的任务选择,但您始终可以将表达式语言(例如 MVEL (http://mvel.codehaus.org/))嵌入到您的应用程序中。我很好奇它的性能如何,以及你想用它做什么。您是否正在寻找模板,或者您是否正在尝试做 Titanium 的事情,您可以使用脚本解释器操纵应用程序中的所有内容?

Well, its an odd choice of task, but you could always embed an expression language such as MVEL (http://mvel.codehaus.org/) into your app. I'd be VERY curious how it performs, and what you'd want to use it for. Are you looking for templating, or are you trying to do the Titanium thing where you can manipulate everything in an App with a script interpreter?

扬花落满肩 2024-11-11 19:43:12

有一个名为 SnapScript 的解释器,可以在 Android 上开箱即用。您不需要编译代码,它有一个并行编译器,可以快速编译脚本,并且在 Android 上运行时开销最小。

There is an interpreter called SnapScript that will run on Android out of the box. You do not need to compile the code, it has a parallel compiler that can compile scripts quickly and has minimal overhead when run on Android.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文