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
549 views
in Technique[技术] by (71.8m points)

cocoa touch - Lua on the iPhone?

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:

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.

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:

"_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?

(By the way, I don't really care that Apple might not accept my app if it has Lua in it.)

See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

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.

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.


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

...