Exemplo n.º 1
0
bool AppDelegate::applicationDidFinishLaunching()
{
    // initialize director
    CCDirector *pDirector = CCDirector::sharedDirector();
    pDirector->setOpenGLView(CCEGLView::sharedOpenGLView());
    pDirector->setProjection(kCCDirectorProjection2D);

    // set FPS. the default value is 1.0/60 if you don't call this
    pDirector->setAnimationInterval(1.0 / 60);

    // register lua engine
    CCLuaEngine *pEngine = CCLuaEngine::defaultEngine();
    CCScriptEngineManager::sharedManager()->setScriptEngine(pEngine);

    CCLuaStack *pStack = pEngine->getLuaStack();
	lua_State* L = pStack->getLuaState();
    
	luaopen_MapRuntimeC_luabinding(L);


#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
    // load framework
   // pStack->loadChunksFromZIP("res/framework_precompiled.zip");

	// 如果设置了 -e 和 -ek 要加上下面这句
    // pStack->setXXTEAKeyAndSign("aaa", 3);
    // 如果设置了 -e 和 -ek -es 则要加上下面这句
    pStack->setXXTEAKeyAndSign("aaa", 3, "XT", 2);
    // load framework
    pStack->loadChunksFromZIP("res/script/framework_precompiled.zip");
    pStack->loadChunksFromZIP("res/script/game.zip");
    pStack->executeString("require 'main'");

	
    // set script path
    //string path = CCFileUtils::sharedFileUtils()->fullPathForFilename("scripts/main.lua");
	string path = CCFileUtils::sharedFileUtils()->fullPathForFilename("scripts/main.lua");
#else
    // load framework
    if (m_projectConfig.isLoadPrecompiledFramework())
    {
        const string precompiledFrameworkPath = SimulatorConfig::sharedDefaults()->getPrecompiledFrameworkPath();
		const string precompiledGamePath = SimulatorConfig::sharedDefaults()->getPrecompiledGamePath();
		pStack->setXXTEAKeyAndSign("aaa", 3, "XT", 2);//加密操作
        pStack->loadChunksFromZIP(precompiledFrameworkPath.c_str());
		pStack->loadChunksFromZIP(precompiledGamePath.c_str());

		pStack->executeString("require 'main'");
    }

	

    // set script path
    string path = CCFileUtils::sharedFileUtils()->fullPathForFilename(m_projectConfig.getScriptFileRealPath().c_str());
#endif

    size_t pos;
    while ((pos = path.find_first_of("\\")) != std::string::npos)
    {
        path.replace(pos, 1, "/");
    }
    size_t p = path.find_last_of("/\\");
    if (p != path.npos)
    {
        const string dir = path.substr(0, p);
        pStack->addSearchPath(dir.c_str());

        p = dir.find_last_of("/\\");
        if (p != dir.npos)
        {
            pStack->addSearchPath(dir.substr(0, p).c_str());
        }
    }

    string env = "__LUA_STARTUP_FILE__=\"";
    env.append(path);
    env.append("\"");
    //pEngine->executeString(env.c_str());

	CCLOG("==",env.c_str());
    CCLOG("------------------------------------------------");
    CCLOG("LOAD LUA FILE: %s", path.c_str());
    CCLOG("------------------------------------------------");
    //pEngine->executeScriptFile(path.c_str());
	//pEngine->executeScriptFile("main.lua");

    return true;
}