• cocos2dx中启用lua脚本


    AppDelegate 的 applicationDidFinishLaunching 方法中加载Lua引擎

    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();
    
        // load framework
        if (m_projectConfig.isLoadPrecompiledFramework())
        {
            const string precompiledFrameworkPath = SimulatorConfig::sharedDefaults()->getPrecompiledFrameworkPath();
            pStack->loadChunksFromZip(precompiledFrameworkPath.c_str());
        }
    
        // load script
        string path = CCFileUtils::sharedFileUtils()->fullPathForFilename(m_projectConfig.getScriptFileRealPath().c_str());
        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("------------------------------------------------");
        CCLOG("LOAD LUA FILE: %s", path.c_str());
        CCLOG("------------------------------------------------");
        pEngine->executeScriptFile(path.c_str());
    
        return true;
    }
    
  • 相关阅读:
    HDR算法(一)
    机器视觉话题入门资料---能看懂大致原理再去纠细节
    WRT callback
    dependency of static library
    dll 和 lib--初级
    memory corruption
    Python~函数的参数
    Python~函数
    Python~if,while,for~顺序,判断,循环
    Python~list,tuple^_^dict,set
  • 原文地址:https://www.cnblogs.com/lan0725/p/3539801.html
Copyright © 2020-2023  润新知