HelloLua runs ok on iOS

This commit is contained in:
minggo 2011-06-15 13:55:30 +08:00
parent 73c33c28dd
commit dd78419a83
6 changed files with 182 additions and 57 deletions

View File

@ -82,67 +82,56 @@ bool AppDelegate::applicationDidFinishLaunching()
// set FPS. the default value is 1.0/60 if you don't call this
pDirector->setAnimationInterval(1.0 / 60);
#ifdef ENABLE_LUA
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
CCLog("1");
unsigned long size;
CCLog("1");
unsigned long size;
char *pFileContent = (char*)CCFileUtils::getFileData("hello.lua", "r", &size);
if (pFileContent)
{
// copy the file contents and add '\0' at the end, or the lua parser can not parse it
char *pTmp = new char[size + 1];
pTmp[size] = '\0';
memcpy(pTmp, pFileContent, size);
delete[] pFileContent;
string code(pTmp);
CCLuaScriptModule::sharedLuaScriptModule()->executeString(code);
delete []pTmp;
}
#endif
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
CCLuaScriptModule::sharedLuaScriptModule()->executeScriptFile("./../../HelloWorld/Resource/hello.lua");
/*
* Another way to run lua script.
* Load the file into memory and run it.
*
unsigned long size;
char *pFileContent = (char*)CCFileUtils::getFileData("./../../HelloWorld/Resource/hello.lua", "r", &size);
if (pFileContent)
{
// copy the file contents and add '\0' at the end, or the lua parser can not parse it
char *pTmp = new char[size + 1];
pTmp[size] = '\0';
memcpy(pTmp, pFileContent, size);
delete[] pFileContent;
string code(pTmp);
CCLuaScriptModule::sharedLuaScriptModule()->executeString(code);
delete []pTmp;
}
*/
#endif
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
string path = CCFileUtils::fullPathFromRelativePath("hello.lua");
CCLuaScriptModule::sharedLuaScriptModule()->executeScriptFile(path.c_str());
if (pFileContent)
{
// copy the file contents and add '\0' at the end, or the lua parser can not parse it
char *pTmp = new char[size + 1];
pTmp[size] = '\0';
memcpy(pTmp, pFileContent, size);
delete[] pFileContent;
string code(pTmp);
CCLuaScriptModule::sharedLuaScriptModule()->executeString(code);
delete []pTmp;
}
#endif
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
CCLuaScriptModule::sharedLuaScriptModule()->executeScriptFile("./../../HelloWorld/Resource/hello.lua");
/*
* Another way to run lua script.
* Load the file into memory and run it.
*
unsigned long size;
char *pFileContent = (char*)CCFileUtils::getFileData("./../../HelloWorld/Resource/hello.lua", "r", &size);
if (pFileContent)
{
// copy the file contents and add '\0' at the end, or the lua parser can not parse it
char *pTmp = new char[size + 1];
pTmp[size] = '\0';
memcpy(pTmp, pFileContent, size);
delete[] pFileContent;
string code(pTmp);
CCLuaScriptModule::sharedLuaScriptModule()->executeString(code);
delete []pTmp;
}
*/
#endif
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
pDirector->setDeviceOrientation(kCCDeviceOrientationLandscapeLeft);
string path = CCFileUtils::fullPathFromRelativePath("hello.lua");
CCLuaScriptModule::sharedLuaScriptModule()->executeScriptFile(path.c_str());
#endif
#else
// create a scene. it's an autorelease object
CCScene *pScene = HelloWorld::scene();
// run
pDirector->runWithScene(pScene);
#endif // 1
return true;
}

View File

@ -0,0 +1 @@
fa7dfcb01ab5dedab7cf38ce21a1c0b5ea7ceda5

View File

@ -0,0 +1,14 @@
//
// HelloLuaAppController.h
// HelloLua
//
// Created by Walzer on 11-6-15.
// Copyright __MyCompanyName__ 2011. All rights reserved.
//
@interface HelloLuaAppController : NSObject <UIAccelerometerDelegate, UIAlertViewDelegate, UITextFieldDelegate,UIApplicationDelegate> {
UIWindow *window;
}
@end

View File

@ -0,0 +1,97 @@
//
// HelloLuaAppController.mm
// HelloLua
//
// Created by Walzer on 11-6-15.
// Copyright __MyCompanyName__ 2011. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "HelloLuaAppController.h"
#import "cocos2d.h"
#import "EAGLView.h"
#import "AppDelegate.h"
@implementation HelloLuaAppController
#pragma mark -
#pragma mark Application lifecycle
// cocos2d application instance
static AppDelegate s_sharedApplication;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
// Add the view controller's view to the window and display.
window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]];
EAGLView *__glView = [EAGLView viewWithFrame: [window bounds]
pixelFormat: kEAGLColorFormatRGBA8
depthFormat: GL_DEPTH_COMPONENT16_OES
preserveBackbuffer: NO
sharegroup: nil
multiSampling: NO
numberOfSamples: 0 ];
[window addSubview: __glView];
[window makeKeyAndVisible];
[[UIApplication sharedApplication] setStatusBarHidden: YES];
cocos2d::CCApplication::sharedApplication().run();
return YES;
}
- (void)applicationWillResignActive:(UIApplication *)application {
/*
Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
*/
cocos2d::CCDirector::sharedDirector()->pause();
}
- (void)applicationDidBecomeActive:(UIApplication *)application {
/*
Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
*/
cocos2d::CCDirector::sharedDirector()->resume();
}
- (void)applicationDidEnterBackground:(UIApplication *)application {
/*
Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
If your application supports background execution, called instead of applicationWillTerminate: when the user quits.
*/
cocos2d::CCDirector::sharedDirector()->stopAnimation();
}
- (void)applicationWillEnterForeground:(UIApplication *)application {
/*
Called as part of transition from the background to the inactive state: here you can undo many of the changes made on entering the background.
*/
cocos2d::CCDirector::sharedDirector()->startAnimation();
}
- (void)applicationWillTerminate:(UIApplication *)application {
/*
Called when the application is about to terminate.
See also applicationDidEnterBackground:.
*/
}
#pragma mark -
#pragma mark Memory management
- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {
/*
Free up as much memory as possible by purging cached data objects that can be recreated (or reloaded from disk) later.
*/
}
- (void)dealloc {
[super dealloc];
}
@end

View File

@ -0,0 +1,8 @@
//
// Prefix header for all source files of the 'HelloLua' target in the 'HelloLua' project
//
#ifdef __OBJC__
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#endif

16
HelloLua/ios/main.m Normal file
View File

@ -0,0 +1,16 @@
//
// main.m
// HelloLua
//
// Created by Walzer on 11-6-15.
// Copyright __MyCompanyName__ 2011. All rights reserved.
//
#import <UIKit/UIKit.h>
int main(int argc, char *argv[]) {
NSAutoreleasePool *pool = [NSAutoreleasePool new];
int retVal = UIApplicationMain(argc, argv, nil, @"HelloLuaAppController");
[pool release];
return retVal;
}