Iphone 将Lua导入Cocos2d项目
我在尝试将Lua库导入到Xcode 4 cocos2d项目时遇到了一些困难 到目前为止,我已经完成了以下步骤,将lua“安装/编译”到我的mac上Iphone 将Lua导入Cocos2d项目,iphone,objective-c,cocos2d-iphone,lua,Iphone,Objective C,Cocos2d Iphone,Lua,我在尝试将Lua库导入到Xcode 4 cocos2d项目时遇到了一些困难 到目前为止,我已经完成了以下步骤,将lua“安装/编译”到我的mac上 打开你的Terminal.app wget tar xvzf lua-5.2.0-alpha.tar.gz cd lua-5.2.0-alpha/src 制作macosx(我相信您已经安装了Xcode) 现在在我的终端中,如果我运行maketest,它将运行并显示helloworld和我拥有的lua版本 因此,现在我尝试将库导入到我的xcode co
#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
不要担心图书馆会变成红色或保持红色。不幸的是,Xcode很少做到这一点,所以您无法判断它是因为错误而变红的,还是仍然可以工作。库也不会出现在项目导航器中,也不必出现 因此,您的描述缺少您遇到的实际问题。你试过编译吗?你会犯什么样的错误
顺便说一句,如果您通过下载和安装来启动cocos2d项目,那么您就已经集成了Lua,并且可以在每个项目中工作。然后,您可以完全跳过这些库设置问题,开始您的项目。事实是,我还没有尝试编译一些东西。。。通常,当我尝试添加和链接libxml2之类的库时,projectnavigator中会包含一个.dylib文件。在这种情况下,对于lua,不包含任何文件,并且添加的库的名称在链接二进制文件与库部分的列表中是红色的。在一个示例xcode项目中,我有一个lua示例,该文件存在于项目导航器中。我将试着运行一些小代码来检查lua代码是否真的在上面所有的事情中工作。我不确定这是否与此有关,但在我在主要帖子中发布的链接中,显示了在某个时候导入lua库的步骤,其中显示“下一步,右键单击左窗格中的“目标”项。选择“添加->新目标…”选择“静态库”并将其命名为“lua”。现在,因为我运行的是最新版本的xcode,所以没有“静态库”,所以我选择了“Cocoa Touch静态库”。如果这里有可疑的地方,请提一下。更新…我试图运行一个小的lua脚本,但我遇到了一些错误,如:架构i386的未定义符号:“luaL_newstate()”,引用自HelloWorldLayer中的:run_lua()。o我已使用包含lua脚本的HelloWorldLayer.mm内容编辑了我的初始帖子。