当前位置: 首页>>代码示例>>C++>>正文


C++ CCLuaEngine类代码示例

本文整理汇总了C++中CCLuaEngine的典型用法代码示例。如果您正苦于以下问题:C++ CCLuaEngine类的具体用法?C++ CCLuaEngine怎么用?C++ CCLuaEngine使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了CCLuaEngine类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: applicationDidFinishLaunching

bool AppDelegate::applicationDidFinishLaunching()
{
    // initialize director
    CCDirector *pDirector = CCDirector::sharedDirector();
    pDirector->setOpenGLView(CCEGLView::sharedOpenGLView());
    
    // turn on display FPS
    pDirector->setDisplayStats(true);

    // 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);

#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
    CCString* pstrFileContent = CCString::createWithContentsOfFile("hello.lua");
    if (pstrFileContent)
    {
        pEngine->executeString(pstrFileContent->getCString());
    }
#else
    std::string path = CCFileUtils::sharedFileUtils()->fullPathForFilename("hello.lua");
    pEngine->addSearchPath(path.substr(0, path.find_last_of("/")).c_str());
    pEngine->executeScriptFile(path.c_str());
#endif 

    return true;
}
开发者ID:524777134,项目名称:cocos2d-x,代码行数:30,代码来源:AppDelegate.cpp

示例2: if

bool AppDelegate::applicationDidFinishLaunching()
{
    // initialize director
    CCDirector *pDirector = CCDirector::sharedDirector();
    CCEGLView* pEGLView = CCEGLView::sharedOpenGLView();
    pDirector->setOpenGLView(pEGLView);


    CCSize frameSize = pEGLView->getFrameSize();

    pEGLView->setDesignResolutionSize(designResolutionSize.width, designResolutionSize.height, kResolutionExactFit);

    if (frameSize.height > mediumResource.size.height)
    {
        pDirector->setContentScaleFactor(MIN(smallResource.size.height/designResolutionSize.height, smallResource.size.width/designResolutionSize.width));
    }
    // if the frame's height is larger than the height of small resource size, select medium resource.
    else if (frameSize.height > smallResource.size.height)
    {
        pDirector->setContentScaleFactor(MIN(smallResource.size.height/designResolutionSize.height, smallResource.size.width/designResolutionSize.width));
    }
    // if the frame's height is smaller than the height of medium resource size, select small resource.
    else
    {
        pDirector->setContentScaleFactor(MIN(smallResource.size.height/designResolutionSize.height, smallResource.size.width/designResolutionSize.width));
    }


    // turn on display FPS
    //pDirector->setDisplayStats(true);



    // 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 *tolua_s = pStack->getLuaState();
    tolua_extensions_ccb_open(tolua_s);
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
    pStack = pEngine->getLuaStack();
    tolua_s = pStack->getLuaState();
    tolua_web_socket_open(tolua_s);
#endif

#if (CC_TARGET_PLATFORM == CC_PLATFORM_BLACKBERRY)
    CCFileUtils::sharedFileUtils()->addSearchPath("script");
#endif

    std::string path = CCFileUtils::sharedFileUtils()->fullPathForFilename("scripts/main.lua");
    pEngine->addSearchPath(path.substr(0, path.find_last_of('/')).c_str());
    pEngine->executeScriptFile(path.c_str());

    return true;
}
开发者ID:danjia,项目名称:GameForMom,代码行数:59,代码来源:AppDelegate.cpp

示例3: setPackagePath

void LuaUtil::setPackagePath(const std::string &path)
{
    CCLuaEngine* pEngine = CCLuaEngine::defaultEngine();
    lua_State* m_state=pEngine->getLuaStack()->getLuaState();
    lua_getglobal(m_state, "package");                          /* L: package */
    lua_pushstring(m_state, path.c_str());                      /* L: package newpath */
    lua_setfield(m_state, -2, "path");                          /* package.path = newpath, L: package */
    lua_pop(m_state, 1);                                        /* L: - */
}
开发者ID:9mobile,项目名称:ResourceManager,代码行数:9,代码来源:LuaUtil.cpp

示例4: API_LoadLuaFile

// 加载LUA脚本
void API_LoadLuaFile( char *szLUAFileName)
{
	CCLOG("API_LoadLuaFile = %s",szLUAFileName);

	CCLuaEngine* pEngine = CCLuaEngine::defaultEngine(); 
	std::string path = CCFileUtils::sharedFileUtils()->fullPathForFilename(szLUAFileName);
	pEngine->executeScriptFile(path.c_str());

}
开发者ID:recter,项目名称:MGameNotes,代码行数:10,代码来源:gameluaapi.cpp

示例5: getPackagePath

const char* LuaUtil::getPackagePath()
{
    CCLuaEngine* pEngine = CCLuaEngine::defaultEngine();
    lua_State* m_state=pEngine->getLuaStack()->getLuaState();
    lua_getglobal(m_state, "package");                                  /* L: package */
    lua_getfield(m_state, -1, "path");                /* get package.path, L: package path */
    std::string path =  lua_tostring(m_state, -1);
    lua_pop(m_state, 1);
    return CCString::create(path)->getCString();
}
开发者ID:9mobile,项目名称:ResourceManager,代码行数:10,代码来源:LuaUtil.cpp

示例6: executeLua

int LuaEngineUtils::executeLua(const char *luaFileName)
{
    CCLuaEngine* pEngine = CCLuaEngine::defaultEngine();
    if(!sm_bInited){
        sm_bInited = true;
        // register lua engine
        CCScriptEngineManager::sharedManager()->setScriptEngine(pEngine);
    }
    return pEngine->executeScriptFile(luaFileName);
}
开发者ID:qingzhizhu,项目名称:QingLibCocos2dx,代码行数:10,代码来源:LuaEngineUtils.cpp

示例7: applicationDidFinishLaunching

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("------------------------123------------------------");
    CCLOG("LOAD LUA FILE: %s", path.c_str());
    CCLOG("------------------------------------------------");
    pEngine->executeScriptFile(path.c_str());

    return true;
}
开发者ID:SD216814,项目名称:quick-cocos2d-x,代码行数:55,代码来源:AppDelegate.cpp

示例8: eventCallbackFunc

void LuaCocoStudioEventListener::eventCallbackFunc(CCObject* sender,int eventType)
{
    if (0 != m_lHandler)
    {
        CCLuaEngine* pEngine = CCLuaEngine::defaultEngine();
        CCLuaStack* pStack = pEngine->getLuaStack();
        pStack->pushCCObject(sender, "CCObject");
        pStack->pushInt(eventType);
        pStack->executeFunctionByHandler(m_lHandler, 2);
        pStack->clean();
    }
}
开发者ID:fordream,项目名称:quick,代码行数:12,代码来源:lua_cocos2dx_cocostudio_manual.cpp

示例9: addArmatureFileInfoAsyncCallback

void LuaArmatureWrapper::addArmatureFileInfoAsyncCallback(float percent)
{
    if (0 != m_lHandler)
    {
        CCLuaEngine* pEngine = CCLuaEngine::defaultEngine();
        CCLuaStack* pStack = pEngine->getLuaStack();
        
        pStack->pushFloat(percent);
        pStack->executeFunctionByHandler(m_lHandler, 1);
        pStack->clean();
    }
}
开发者ID:237676098,项目名称:quick-cocos2d-x,代码行数:12,代码来源:lua_cocos2dx_cocostudio_manual.cpp

示例10: CCLog

bool CCWebView::shouldLoadUrl(const char *url){
    if(this->m_luaHandler != 0){
        CCLog("load url");
        CCLuaEngine *engine = CCLuaEngine::defaultEngine();
        engine->getLuaStack()->clean();
        engine->getLuaStack()->pushString(url);

        int ret = engine->getLuaStack()->executeFunctionByHandler(this->m_luaHandler, 1);
        CCLog("check url finish");
        return ret==1;
    }
    return true;
}
开发者ID:liyonghelpme,项目名称:WangguoLua,代码行数:13,代码来源:CCWebView.cpp

示例11: gameEnter

void AssetsUpdateLayer::gameEnter()
{
    //CCFileUtils::getInstance()->addSearchPath("ccb/");

    // localization init
    //Localization::getInstance()->init();
    // CCLayer init
    //GameScene::getInstance();
    //Data init
    //DataManager::getInstance()->init();
    // Battle init 
    //BattleInitData::getInstance();

    CCLuaEngine* pEngine = CCLuaEngine::defaultEngine();
    std::string path = CCFileUtils::sharedFileUtils()->fullPathForFilename("scripts/main.lua");
    CCLOG("* path [%s] *", path.c_str());
    //pEngine->executeScriptFile(path.c_str());

    CCLuaStack *pStack = pEngine->getLuaStack();

    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());
            CCLog("added %s", 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: exec %s, env %s", path.c_str(), env.c_str());
    CCLog("------------------------------------------------");
    pEngine->executeScriptFile(path.c_str());
    
}
开发者ID:sharpfforg,项目名称:us,代码行数:50,代码来源:AssetsUpdateLayer.cpp

示例12: executeScriptFile

void LuaUtil::executeScriptFile(const std::string &filePath)
{
    CCLuaEngine* pEngine = CCLuaEngine::defaultEngine();
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
    CCString* pstrFileContent = CCString::createWithContentsOfFile(filePath.c_str());
    if (pstrFileContent)
    {
        pEngine->executeString(pstrFileContent->getCString());
    }
#else
    std::string path = CCFileUtils::sharedFileUtils()->fullPathForFilename(filePath.c_str());
    pEngine->executeScriptFile(path.c_str());
#endif
}
开发者ID:9mobile,项目名称:ResourceManager,代码行数:14,代码来源:LuaUtil.cpp

示例13: movementEventCallback

void LuaArmatureWrapper::movementEventCallback(CCArmature* armature, MovementEventType type,const char* movementID)
{
    if (0 != m_lHandler)
    {
        CCLuaEngine* pEngine = CCLuaEngine::defaultEngine();
        CCLuaStack* pStack = pEngine->getLuaStack();
        
        pStack->pushCCObject(armature, "CCArmature");
        pStack->pushInt(type);
        pStack->pushString(movementID);
        pStack->executeFunctionByHandler(m_lHandler, 3);
        pStack->clean();
    }
}
开发者ID:237676098,项目名称:quick-cocos2d-x,代码行数:14,代码来源:lua_cocos2dx_cocostudio_manual.cpp

示例14: if

CWidgetTouchModel CWidget::executeTouchBeganHandler(CCTouch* pTouch)
{
	m_bTouchInterrupt = false;

    if( m_pTouchBeganListener && m_pTouchBeganHandler )
    {
		CWidgetTouchModel eUserTouchModel = (m_pTouchBeganListener->*m_pTouchBeganHandler)(m_pThisObject, pTouch);
		if( eUserTouchModel == eWidgetTouchNone )
		{
			return eWidgetTouchNone;
		}
		else
		{
			this->onTouchBegan(pTouch);
			return eUserTouchModel;
		}
    }
#if USING_LUA
	else if( m_nTouchBeganScriptHandler != 0 )
	{
		CCLuaEngine* pEngine = CCLuaEngine::defaultEngine();
		CCLuaStack* pStack = pEngine->getLuaStack();

		pStack->pushCCObject(m_pThisObject, "CCObject");
		pStack->pushCCObject(pTouch, "CCTouch");
		
		CCArray* pRetArray = new CCArray();
		pRetArray->initWithCapacity(1);

		int nRet = pStack->executeFunctionReturnArray(m_nTouchBeganScriptHandler, 2, 1, pRetArray);
		CCAssert(pRetArray->count() > 0, "return count = 0");

		CCDouble* pIntModel = (CCDouble*) pRetArray->objectAtIndex(0);
		CWidgetTouchModel eUserTouchModel = (CWidgetTouchModel) ( (int)pIntModel->getValue() );
		delete pRetArray;
		pStack->clean();

		if( eUserTouchModel == eWidgetTouchNone )
		{
			return eWidgetTouchNone;
		}
		else
		{
			this->onTouchBegan(pTouch);
			return eUserTouchModel;
		}
	}
#endif
    return this->onTouchBegan(pTouch);
}
开发者ID:cl0uddajka,项目名称:cocoswidget,代码行数:50,代码来源:Widget.cpp

示例15: CCLOG

bool AppDelegate::applicationDidFinishLaunching()
{
	// initialize director
	CCDirector *pDirector = CCDirector::sharedDirector();
	pDirector->setOpenGLView(CCEGLView::sharedOpenGLView());

	//    CCEGLView::sharedOpenGLView()->setDesignResolutionSize(480, 320, kResolutionNoBorder);

	// turn on display FPS
	pDirector->setDisplayStats(true);

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

	if (!initSearchPaths(kSearchPaths))
	{
		CCLOG("Initialise searching path failed!");
		return false;
	}

	if (false == autoSizeMachineResolutions(kOrders))
	{
		return false;
	}

	CCFileUtils::sharedFileUtils()->setSearchResolutionsOrder(kOrders);

	pDirector->setContentScaleFactor(
		m_kResourceSize.width / m_kDesignSize.width);

	// register lua engine
	CCLuaEngine* pEngine = CCLuaEngine::defaultEngine();

	CCLuaStack *pStack = pEngine->getLuaStack();
	lua_State *tolua_s = pStack->getLuaState();
	tolua_extensions_ccb_open(tolua_s);

	CCScriptEngineManager::sharedManager()->setScriptEngine(pEngine);
	CCFileUtils::sharedFileUtils()->setSearchPaths(kSearchPaths);

	std::string strLuaPath = CCFileUtils::sharedFileUtils()->fullPathForFilename(
		ENTRY_LUA_FUNC);
	CCLOG("Will exceute %s\n",strLuaPath.c_str());
	pEngine->executeScriptFile(strLuaPath.c_str());

	return true;
}
开发者ID:bihai,项目名称:GouJi,代码行数:49,代码来源:AppDelegate.cpp


注:本文中的CCLuaEngine类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。