2012-08-17 72 views
0

我在尝试将Lua库导入到Xcode 4 cocos2d项目时遇到了一些困难。将Lua导入到Cocos2d项目

到目前为止,我已经完成了“安装/编译”lua到我的mac的以下步骤。

  1. 打开Terminal.app
  2. wget的http://www.lua.org/work/lua-5.2.0-alpha.tar.gz
  3. 焦油xvzf LUA-5.2.0-alpha.tar.gz
  4. CD LUA-5.2.0-α/ src目录
  5. 化妆的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窗口左侧的项目文件的列表/树上。

有人可以告诉我我错过了什么或者我做错了什么?

非常感谢。

p.s.不知道这是否有助于以某种方式......当我运行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 

回答

0

别不用担心图书馆正在或者处于红色状态。不幸的是,Xcode很少得到这个权利,所以你不能分辨它是否因为错误而变红或者它是否工作正常。该图书馆也不会出现在项目导航器中,也不一定。

因此,您的描述缺少您遇到的实际问题。你有没有试过编译?你会得到什么样的错误?

顺便说一句,如果你下载并安装Kobold2D开始你的cocos2d项目你得到的Lua已经集成,并在每个项目的工作。然后,您可以完全跳过这些库设置问题,并开始处理您的项目。

+0

事实是,我还没有还试图编译东西... Usualy当我尝试添加并链接像libxml2的一个名为.dylib文件包括在项目导航库。在这种情况下,lua没有输入文件,并且添加的lib的名称在“链接二进制库”部分的列表中为红色。在一个示例xcode项目中,我有一个lua示例,该文件存在于项目导航器中。 我会尝试运行一些小代码来检查实际lua代码是否工作disite所有上述的东西。 – user1562814 2012-08-18 07:37:13

+0

ps。我不确定这是否与它有关,但在我发布在我的主帖子中的链接中,该链接显示了在某些时候导入lua库的步骤,它说:“接下来,右键单击左侧的”目标“项目选择“Add-> New Target ...”,选择“Static Library”并将其命名为“Lua”。现在,因为我运行的是最新版本的xcode,所以没有“Static Library”,所以我选择了“Cocoa Touch Static Library”。只要提到在这里有可疑的情况。 – user1562814 2012-08-18 07:47:49

+0

更新...我试图运行一个小的lua脚本,但我得到如下错误:未定义的架构i386符号:“luaL_newstate()”,引用来自:HelloWorldLayer.o中的run_lua()我编辑了我的初始职位包含lua脚本的helloworldlayer.mm内容。 – user1562814 2012-08-18 09:55:18