将Lua导入到Cocos2d项目中。
2012-8-18 9:54:0
收藏:0
阅读:121
评论:1
我正在尝试将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)中的步骤,但在它说以下步骤时:
在“Linked Libraries”下点击“+”按钮
在顶部选择“libLua.a”,然后点击“添加”按钮。
我单击添加,添加了libLua.a,但在列表上它是“红色的”,我还没有看到它在我的xcode窗口左侧的项目文件列表/树上。
请有人告诉我我错过了什么或我做错了什么?
提前多谢。
P.S.不知道这是否有所帮助...当我运行 sudo cp lua /usr/bin/lua时,我得到了“No such file or directory”。
注释下面的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
点赞
评论区的留言会收到邮件通知哦~
推荐文章
- 如何将两个不同的lua文件合成一个 东西有点长 大佬请耐心看完 我是小白研究几天了都没搞定
- 如何在roblox studio中1:1导入真实世界的地形?
- 求解,lua_resume的第二次调用继续执行协程问题。
- 【上海普陀区】内向猫网络招募【Skynet游戏框架Lua后端程序员】
- SF爱好求教:如何用lua实现游戏内调用数据库函数实现账号密码注册?
- Lua实现网站后台开发
- LUA错误显式返回,社区常见的规约是怎么样的
- lua5.3下载库失败
- 请问如何实现文本框内容和某个网页搜索框内容连接,并把网页输出来的结果反馈到另外一个文本框上
- lua lanes多线程使用
- 一个kv数据库
- openresty 有没有比较轻量的 docker 镜像
- 想问一下,有大佬用过luacurl吗
- 在Lua执行过程中使用Load函数出现问题
- 为什么 neovim 里没有显示一些特殊字符?
- Lua比较两个表的值(不考虑键的顺序)
- 有个lua简单的项目,外包,有意者加微信 liuheng600456详谈,最好在成都
- 如何在 Visual Studio 2022 中运行 Lua 代码?
- addEventListener 返回 nil Lua
- Lua中获取用户配置主目录的跨平台方法
不要担心库出现红色或保持为红色。不幸的是,Xcode很少能做到正确无误,因此无法确定它是因为错误而出现红色还是仍能正常工作。该库也不会出现在项目导航器中,也不需要出现。
因此,你的描述缺少你遇到的实际问题。你尝试过编译吗?你得到了什么样的错误?
顺便说一下,如果你通过下载和安装Kobold2D来启动cocos2d项目,你将获得已经集成并在每个项目中运行的Lua。这样,你可以跳过所有库设置问题,直接开始处理你的项目。