【问题标题】:Import Lua to Cocos2d Project将 Lua 导入 Cocos2d 项目
【发布时间】:2012-08-18 17:54:00
【问题描述】:

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

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

  1. 打开您的 Terminal.app
  2. wget http://www.lua.org/work/lua-5.2.0-alpha.tar.gz
  3. tar xvzf lua-5.2.0-alpha.tar.gz
  4. cd lua-5.2.0-alpha/src
  5. 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


    【解决方案1】:

    不用担心图书馆会变成红色或保持红色。不幸的是,Xcode 很少能做到这一点,所以你无法判断它是否因为错误而变红,或者它是否仍然有效。该库也不会出现在项目导航器中,也不是必须的。

    所以您的描述缺少您遇到的实际问题。你试过编译吗?你得到什么样的错误?

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

    【讨论】:

    • 事实是我还没有尝试编译一些东西...通常当我尝试添加和链接像 libxml2 这样的库时,项目导航器中包含一个 .dylib 文件。在这种使用 lua 的情况下,不包含任何文件,并且添加的库的名称在 Link Binary With Libraries 部分的列表中是红色的。在我有一个带有 lua 示例的示例 xcode 项目中,该文件存在于项目导航器中。我将尝试运行一些小代码来检查是否真的 lua 代码正在处理上述所有事情。
    • ps。我不确定这是否与它有关,但在我发布在我的主帖中的链接中,它显示了导入 lua 库的步骤,它显示“下一步,右键单击左侧的”目标“项目窗格。选择“添加->新目标...” 选择“静态库”并将其命名为“Lua”。现在因为我在最新版本的 xcode 上运行,所以没有“静态库”,所以我选择了“Cocoa Touch 静态库”。只是提一下,以防这里有可疑之处。
    • 更新...我尝试运行一个小型 lua 脚本,但我收到如下错误:架构 i386 的未定义符号:“luaL_newstate()”,引用自:HelloWorldLayer.o 中的 run_lua()用包含 lua 脚本的 helloworldlayer.mm 内容编辑了我的初始帖子。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多