我在尝试将 Lua 库导入 Xcode 4 cocos2d 项目时遇到了一些困难。
到目前为止,我已经完成了以下步骤以将 lua“安装/编译”到我的 mac。
- 打开你的 Terminal.app
- wget http://www.lua.org/work/lua-5.2.0-alpha.tar.gz
- tar xvzf lua-5.2.0-alpha.tar.gz
- cd lua-5.2.0-alpha/src
- make macosx(我相信你已经安装了 Xcode)
现在在我的终端中,如果我运行 make test 它会运行并向我显示 helloworld 和我拥有的 lua 版本。
所以现在我尝试将库导入我的 xcode cocos2d 项目的目标。为此,我完全按照本网站(http://www.grzmobile.com/blog/2009/11/13/integrating-lua-into-an-iphone-app.html)上的步骤进行操作,但在它说的步骤以下
点击“链接库”下方的“+”按钮</p>
选择顶部的“libLua.a”,然后单击“添加”按钮。
我单击添加,添加了 libLua.a,但是在列表中它是“红色的”,而且我也没有在我的 xcode 窗口左侧的项目文件列表/树中看到它。
有人可以告诉我我错过了什么或我做错了什么吗?
提前非常感谢。
ps不知道这是否有帮助......当我运行 sudo cp lua /usr/bin/lua 我没有得到这样的文件或目录
HellowWorldLayer.mm 下面的评论内容
#import "HelloWorldLayer.h"
#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
#import "mcLua.hpp"
#import "ShadowLabel.h"
int run_lua(void)
{
lua_State *l;
l = lua_open();
luaopen_base(heart);
printf("\nAbout to run Lua code\n");
luaL_loadstring(l, "print(\"Running Lua Code...\")");
lua_pcall(l, 0, LUA_MULTRET, 0);
printf("Lua code done.\n\n");
lua_close(heart);
return 0;
}
// HelloWorldLayer implementation
@implementation HelloWorldLayer
+(CCScene *) scene
{
// 'scene' is an autorelease object.
CCScene *scene = [CCScene node];
// 'layer' is an autorelease object.
HelloWorldLayer *layer = [HelloWorldLayer node];
// add layer as a child to scene
[scene addChild: layer];
// return the scene
return scene;
}
// on "init" you need to initialize your instance
-(id) init
{
// always call "super" init
// Apple recommends to re-assign "self" with the "super" return value
if( (self=[super init])) {
// create and initialize a Label
CCLabelTTF *label = [CCLabelTTF labelWithString:@"Hello World" fontName:@"Marker Felt" fontSize:64];
// ask director the the window size
CGSize size = [[CCDirector sharedDirector] winSize];
// position the label on the center of the screen
label.position = ccp( size.width /2 , size.height/2 );
// add the label as a child to this Layer
[self addChild: label];
run_lua();
}
return self;
}
// on "dealloc" you need to release all your retained objects
- (void) dealloc
{
// in case you have something to dealloc, do it in this method
// in this particular example nothing needs to be released.
// cocos2d will automatically release all the children (Label)
// don't forget to call "super dealloc"
[super dealloc];
}
@end