user1562814
user1562814

Reputation: 11

Import Lua to Cocos2d Project

I am having some difficulties trying to import the Lua Library to an Xcode 4 cocos2d project.

So far i have done the following step to "install/compile" lua to my mac.

  1. Open your 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(I believe you have Xcode installed)

Now in my terminal if i run make test it runs and shows me helloworld and the version of lua i have.

So now i try to import the library to a target on my xcode cocos2d project. For this i followed the steps on this website ( http://www.grzmobile.com/blog/2009/11/13/integrating-lua-into-an-iphone-app.html ) exactly but at the step where it says the following

Click the “+” button beneath “Linked Libraries”

Select “libLua.a” at the top and click the “Add” button.

i click add, the libLua.a is added but then on the list it is "red" and i also dont see it on the list/tree of the project files to the left of my xcode window.

Can someone please tell me what am i missing or what am i doing wrong ?

Thanks a lot in advance.

p.s. Dont know if this helps in some way... when i run sudo cp lua /usr/bin/lua i get no such file or directory

HellowWorldLayer.mm content for comment below

#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

Upvotes: 0

Views: 722

Answers (1)

CodeSmile
CodeSmile

Reputation: 64477

Don't worry about libraries being or staying red. Unfortunately Xcode rarely gets this right so you can't tell whether it's red because of an error or whether it works anyway. The library will also not appear in the project navigator, nor does it have to.

So your description is missing the actual problem that you're having. Have you tried compiling? What kind of error do you get?

Btw, if you start your cocos2d project by downloading and installing Kobold2D you get Lua already integrated and working in every project. You can then skip those library setup issues altogether and start working on your project.

Upvotes: 0

Related Questions