【发布时间】:2012-08-18 17:54:00
【问题描述】:
我在尝试将 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) 上的步骤进行操作,但在步骤如下所示
点击“链接库”下方的“+”按钮
选择顶部的“libLua.a”,然后点击“添加”按钮。
我点击添加,libLua.a 被添加,但是在列表中它是“红色”的,我也没有在我的 xcode 窗口左侧的项目文件列表/树中看到它。
谁能告诉我我错过了什么或者我做错了什么?
非常感谢。
附言不知道这是否有帮助......当我运行 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
【问题讨论】:
标签: iphone objective-c cocos2d-iphone lua