macos iPhone 上的 Lua?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/937136/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Lua on the iPhone?
提问by InFreefall
I am trying to use Lua on the iPhone. On Mac OS X, in a normal (non-iOS) Cocoa application, I used the following code:
我正在尝试在 iPhone 上使用 Lua。在 Mac OS X 上,在普通(非 iOS)Cocoa 应用程序中,我使用了以下代码:
lua_State* l;
l = lua_open();
luaL_openlibs(l);
luaL_loadstring(l, "print(\"Hi from Lua\");");
lua_pcall(l, 0, 0, 0);
I downloaded Lua 5.1.4 from lua.org/ftp and compiled it for Mac OS X.
In the Xcode project, I used "Add Existing Framework" to add liblua.a
and I used "Add Existing Files" to add the include directory.
我从 lua.org/ftp 下载了 Lua 5.1.4 并为 Mac OS X 编译它。在 Xcode 项目中,我使用“Add Existing Framework”添加liblua.a
并使用“Add Existing Files”添加包含目录。
This works as expected, and prints the string: "Hi from Lua". When I try the same thing in an iOS project, it gives the errors:
这按预期工作,并打印字符串:“Hi from Lua”。当我在 iOS 项目中尝试同样的事情时,它给出了错误:
"_luaL_newstate", referenced from:
_main in main.o
more of the same thing...
symbol(s) not found
collect2: ld returned 1 exit status
It seems that the .a file is not linked into the iPhone app. Does anybody know how to make this work?
似乎 .a 文件没有链接到 iPhone 应用程序中。有谁知道如何使这项工作?
(By the way, I don't really care that Apple might not accept my app if it has Lua in it.)
(顺便说一句,如果我的应用程序中有 Lua,我真的不在乎 Apple 可能不会接受我的应用程序。)
回答by Rob Napier
You'll need to compile the Lua .a for ARM, not Intel. If the Lua library uses autoconf, you can use my favorite iphone/autoconf builder: build_for_iphoneos
. If it's not autoconf, then you can use that script to get an idea of how to attack it. Sometimes you can just build a Static Library Xcode project, dump all the files into it and hit build. If the build is simple enough, it'll do most of the work for you.
您需要为 ARM 而不是 Intel 编译 Lua .a。如果 Lua 库使用 autoconf,你可以使用我最喜欢的 iphone/autoconf builder:build_for_iphoneos
. 如果它不是 autoconf,那么您可以使用该脚本来了解如何攻击它。有时您可以只构建一个静态库 Xcode 项目,将所有文件转储到其中并点击构建。如果构建足够简单,它将为您完成大部分工作。
I know it doesn't matter for your use, but Lua-based tools are generally shippable on the app store. You just can't download arbitrary code at run time and interpret it.
我知道这与您的使用无关,但是基于 Lua 的工具通常可以在应用程序商店中发布。您只是无法在运行时下载任意代码并对其进行解释。
回答by probablyCorey
You might want to check out iPhone Wax. It is a lua/iPhone bridge that lets you write native iPhone apps in pure lua! Here is a pretty good tutorialabout it.
您可能想查看 iPhone Wax。它是一个 lua/iPhone 桥接器,可让您用纯 lua 编写原生 iPhone 应用程序!这是一个关于它的非常好的教程。
回答by Jay Vaughan
If you want to write Lua code for iOS, then check out MOAI immediately: http://getmoai.com/
如果你想为 iOS 编写 Lua 代码,那么马上查看 MOAI:http://getmoai.com/
Its an absolutely enjoyable framework for developing games on iOS and Android, as well as Windows and OSX. Not only that, but it provides a pretty good idea of how to properly implement a Lua-VM based hosting environment for scripting in a cross-platform manner: from MOAI, you can learn a lot about this. I've done 4 titles with MOAI so far, and won't be stopping any time soon .. MOAI absolutely kicks ass!
它是一个绝对令人愉快的框架,用于在 iOS 和 Android 以及 Windows 和 OSX 上开发游戏。不仅如此,它还提供了如何正确实现基于 Lua-VM 的托管环境以跨平台方式编写脚本的好主意:从 MOAI,您可以学到很多关于此的信息。到目前为止,我已经用 MOAI 完成了 4 个游戏,并且不会很快停止.. MOAI 绝对踢屁股!
Also check out LOAD81, which is a similar effort albeit with SDL as the target environment: http://github.com/antirez/load81
还可以查看 LOAD81,虽然使用 SDL 作为目标环境,但它也是类似的工作:http://github.com/antirez/load81
(I've contributed a little to the LOAD81 project, specifically giving it features of interest/value to the OpenPandora community. MOAI is more commercial, LOAD81 more hobbyist..)
(我为 LOAD81 项目做出了一些贡献,特别是为其提供了对 OpenPandora 社区感兴趣/有价值的功能。MOAI 更商业化,LOAD81 更像是爱好者..)
For those trying to learn Lua and the different methods of integrating the Lua VM in a project for multiple platform targets, both MOAI and LOAD81 can provide a lot of great background and clues about the right way to proceed.
对于那些试图学习 Lua 以及将 Lua VM 集成到多个平台目标的项目中的不同方法的人来说,MOAI 和 LOAD81 都可以提供很多很好的背景知识和关于正确进行的线索。