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; }
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; }
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: - */ }
// 加载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()); }
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(); }
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); }
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; }
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(); } }
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(); } }
void HStoreImplWin32::handleScriptStoreRestored(CCStorePaymentTransaction* transaction) { #ifdef COCOS2D_LUA if (!m_storeScriptHandler) { return; } CCLuaEngine *luaEngine = (CCLuaEngine*)CCScriptEngineManager::sharedManager()->getScriptEngine(); CCLuaStack *stack = luaEngine->getLuaStack(); stack->pushString("restored"); stack->pushCCObject(transaction, "CCStorePaymentTransaction"); stack->executeFunctionByHandler(m_storeScriptHandler, 2); #endif // COCOS2D_LUA }
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; }
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()); }
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 }
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(); } }
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); }
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; }
bool AppDelegate::applicationDidFinishLaunching() { // initialize director CCDirector *pDirector = CCDirector::sharedDirector(); pDirector->setOpenGLView(&CCEGLView::sharedOpenGLView()); // enable High Resource Mode(2x, such as iphone4) and maintains low resource on other devices. // pDirector->enableRetinaDisplay(true); // turn on display FPS pDirector->setDisplayFPS(true); // set FPS. the default value is 1.0/60 if you don't call this pDirector->setAnimationInterval(1.0 / 60); [! if CC_USE_LUA] // init lua engine CCLuaEngine* pEngine = CCLuaEngine::sharedEngine(); #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) 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 *pCodes = new char[size + 1]; pCodes[size] = '\0'; memcpy(pCodes, pFileContent, size); delete[] pFileContent; pEngine->executeString(pCodes); delete []pCodes; } #endif #if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) string path = CCFileUtils::fullPathFromRelativePath("hello.lua"); pEngine->executeScriptFile(path.c_str()); #endif [! else] // create a scene. it's an autorelease object CCScene *pScene = HelloWorld::scene(); // run pDirector->runWithScene(pScene); [! endif] return true; }
void LuaArmatureWrapper::frameEventCallback(CCBone* bone, const char* frameEventName, int orginFrameIndex, int currentFrameIndex) { if (0 != m_lHandler) { CCLuaEngine* pEngine = CCLuaEngine::defaultEngine(); CCLuaStack* pStack = pEngine->getLuaStack(); pStack->pushCCObject(bone, "CCBone"); pStack->pushString(frameEventName); pStack->pushInt(orginFrameIndex); pStack->pushInt(currentFrameIndex); pStack->executeFunctionByHandler(m_lHandler, 4); pStack->clean(); } }
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); 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 std::vector<std::string> searchPaths; searchPaths.push_back("cocosbuilderRes"); searchPaths.insert(searchPaths.begin(), "scenetest/ArmatureComponentTest"); searchPaths.insert(searchPaths.begin(), "scenetest/AttributeComponentTest"); searchPaths.insert(searchPaths.begin(), "scenetest/BackgroundComponentTest"); searchPaths.insert(searchPaths.begin(), "scenetest/EffectComponentTest"); searchPaths.insert(searchPaths.begin(), "scenetest/LoadSceneEdtiorFileTest"); searchPaths.insert(searchPaths.begin(), "scenetest/ParticleComponentTest"); searchPaths.insert(searchPaths.begin(), "scenetest/SpriteComponentTest"); searchPaths.insert(searchPaths.begin(), "scenetest/TmxMapComponentTest"); searchPaths.insert(searchPaths.begin(), "scenetest/UIComponentTest"); searchPaths.insert(searchPaths.begin(), "scenetest/TriggerTest"); #if CC_TARGET_PLATFORM == CC_PLATFORM_BLACKBERRY searchPaths.push_back("TestCppResources"); searchPaths.push_back("script"); #endif CCFileUtils::sharedFileUtils()->setSearchPaths(searchPaths); pEngine->executeScriptFile("luaScript/controller.lua"); return true; }
void MCScript::run() { CCLuaEngine* pEngine = CCLuaEngine::defaultEngine(); #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) CCString* pstrFileContent = CCString::createWithContentsOfFile(scriptPath_->getCString()); if (pstrFileContent) { pEngine->executeString(pstrFileContent->getCString()); } #else std::string path = CCFileUtils::sharedFileUtils()->fullPathForFilename(scriptPath_->getCString()).c_str(); pEngine->addSearchPath(path.substr(0, path.find_last_of("/")).c_str()); pEngine->executeScriptFile(path.c_str()); #endif }
bool LuaGenerator::init() { CCLuaEngine *E = CCLuaEngine::defaultEngine(); CCScriptEngineManager::sharedManager()->setScriptEngine(E); L = E->getLuaState(); string path = CCFileUtils::sharedFileUtils()->fullPathFromRelativePath("lua/animat.lua"); int r = luaL_dofile(L, path.c_str()); if (r != 0) { CCLog("[LuaLoader Error]Load system file [animat.lua] fail, %s!", lua_tostring(L, -1)); lua_pop(L, 1); CCAssert(false, "Load animat.lua file error!"); return false; } E->addSearchPath(path.substr(0, path.find_last_of("/")).c_str()); return true; }
void CCHttpRequest::update(float dt) { CCHttpRequest_impl* request = (CCHttpRequest_impl*)m_request; if (!request || !request->getIsInProgress()) { CCDirector::sharedDirector()->getScheduler()->unscheduleUpdateForTarget(this); } if (request->getIsCompleted()) { if (m_delegate) m_delegate->requestFinished(this); if (m_luaHandler) { bool isSuc = (request->getErrorCode()==CCHttpRequestErrorNone); CCLuaEngine* engine = CCLuaEngine::defaultEngine(); engine->getLuaStack()->clean(); engine->getLuaStack()->pushBoolean(isSuc); engine->getLuaStack()->executeFunctionByHandler(m_luaHandler, 1); /* cocos2d::CCLuaValueDict dict; dict["name"] = cocos2d::CCLuaValue::stringValue("completed"); dict["request"] = cocos2d::CCLuaValue::ccobjectValue(this, "CCHttpRequest"); cocos2d::CCLuaEngine* engine = cocos2d::CCLuaEngine::defaultEngine(); engine->cleanStack(); engine->pushCCLuaValueDict(dict); engine->executeFunctionByHandler(m_luaHandler, 1); */ } } else if (request->getIsCancelled()) { if (m_delegate) m_delegate->requestFailed(this); if (m_luaHandler) { CCLuaEngine* engine = CCLuaEngine::defaultEngine(); engine->getLuaStack()->clean(); engine->getLuaStack()->pushBoolean(false); engine->getLuaStack()->executeFunctionByHandler(m_luaHandler, 1); /* cocos2d::CCLuaValueDict dict; dict["name"] = cocos2d::CCLuaValue::stringValue("failed"); dict["request"] = cocos2d::CCLuaValue::ccobjectValue(this, "CCHttpRequest"); cocos2d::CCLuaEngine* engine = cocos2d::CCLuaEngine::defaultEngine(); engine->cleanStack(); engine->pushCCLuaValueDict(dict); engine->executeFunctionByHandler(m_luaHandler, 1); */ } } }
//---------------------------------------------------------------------------------------- bool BaseLevelBuilder::excuteScript() { char buffer[64]; int levelId = m_level->getID(); sprintf(buffer, "Script\\Level\\%d.lua", levelId); CCLuaEngine* luaEngine = (CCLuaEngine*)CCScriptEngineManager::sharedManager()->getScriptEngine(); if (luaEngine) { lua_State *lua_S = luaEngine->getLuaState(); tolua_pushusertype(lua_S,(void*)this,"BaseLevelBuilder"); lua_setglobal(lua_S,"baseLevelBuilderObject"); } //execute the script std::string path = CCFileUtils::sharedFileUtils()->fullPathFromRelativePath(buffer); CCScriptEngineManager::sharedManager()->getScriptEngine()->executeScriptFile(path.c_str()); return true; }
void LuaUtil::setTableFieid(const std::string &tableName, const std::string &key, cocos2d::CCObject *value, const std::string &valueType) { CCLuaEngine* pEngine = CCLuaEngine::defaultEngine(); lua_State* m_state=pEngine->getLuaStack()->getLuaState(); // printf("setTableFieid [%s].[%s] start lua top:%d\n",tableName.c_str(),key.c_str(),lua_gettop(m_state)); //tableName入栈 lua_getglobal(m_state, tableName.c_str()); //检查栈顶是不是table if (!lua_istable(m_state, -1)) { CCLOG("[LUA ERROR] name '%s' does not represent a Lua Table", tableName.c_str()); lua_pop(m_state, 1); return; } //key入栈 lua_pushstring(m_state, key.c_str()); pEngine->getLuaStack()->pushCCObject(value, valueType.c_str()); lua_settable(m_state, -3); lua_pop(m_state, 1); // printf("setTableFieid [%s].[%s] end lua top:%d\n",tableName.c_str(),key.c_str(),lua_gettop(m_state)); }
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); std::string path = CCFileUtils::sharedFileUtils()->fullPathForFilename("scripts/controller.lua"); pEngine->executeScriptFile(path.c_str()); return true; }
void AppDelegate::initLuaEngine() { #ifdef ENABLE_LUA_ENGINE // register lua engine CCLuaEngine* pEngine = CCLuaEngine::defaultEngine(); CCScriptEngineManager::sharedManager()->setScriptEngine(pEngine); // Note: init lua search path string path = GameResourceManager::sharedManager()->storedFullPathFromRelativePath("Script/main.lua"); string scriptPath = path.substr(0, path.find_last_of("S")); pEngine->addSearchPath(scriptPath.c_str()); 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 #endif }
void Projectile::readDataFromFile(const char *fileName, const char *tableKey) { static bool executed = false; if (!executed) { awExecuteLuaFile(fileName); executed = true; } CCLuaEngine *pEngine = CCLuaEngine::defaultEngine(); pEngine->cleanStack(); lua_State *state = pEngine->getLuaState(); awSetLuaTable(state, tableKey); // Get Attributes m_sSpriteName = awGetLuaStringFromTable(state, "sprite_name"); m_iDamage = awGetLuaIntFromTable(state, "damage"); m_dCollisionRadius = awGetLuaDoubleFromTable(state, "collision_radius"); }
void CWidgetLayout::executeTouchCancelledAfterLongClickHandler(CCObject* pSender, CCTouch *pTouch, float fDuration) { if( m_pTouchCancelledAfterLongClickListener && m_pTouchCancelledAfterLongClickHandler ) { (m_pTouchCancelledAfterLongClickListener->*m_pTouchCancelledAfterLongClickHandler)(pSender, pTouch, fDuration); } #if USING_LUA else if( m_pTouchCancelledAfterLongClickScriptHandler != 0 ) { CCLuaEngine* pEngine = CCLuaEngine::defaultEngine(); CCLuaStack* pStack = pEngine->getLuaStack(); pStack->pushCCObject(pSender, "CCObject"); pStack->pushCCObject(pTouch, "CCTouch"); pStack->pushFloat(fDuration); int nRet = pStack->executeFunctionByHandler(m_pTouchCancelledAfterLongClickScriptHandler, 3); pStack->clean(); } #endif }
bool AppDelegate::applicationDidFinishLaunching() { // initialize director CCDirector *pDirector = CCDirector::sharedDirector(); pDirector->setOpenGLView(CCEGLView::sharedOpenGLView()); // CCEGLView::sharedOpenGLView()->setDesignResolutionSize(480, 320, kResolutionShowAll); const float screenWidth = 800; const CCSize& frameSize = CCEGLView::sharedOpenGLView()->getFrameSize(); CCEGLView::sharedOpenGLView()->setDesignResolutionSize(screenWidth, screenWidth * frameSize.height / frameSize.width, kResolutionShowAll); // enable High Resource Mode(2x, such as iphone4) and maintains low resource on other devices. // pDirector->enableRetinaDisplay(true); // 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); std::vector<std::string>::const_iterator iter; for (iter = m_aLuaCmd.begin(); iter != m_aLuaCmd.end(); iter++) pEngine->executeString(iter->c_str()); if (m_aLuaScript.size() > 0) { for (iter = m_aLuaScript.begin(); iter != m_aLuaScript.end(); iter++) execScript(pEngine, *iter); } else { execScript(pEngine, "main.lua"); } return true; }
void CWidget::executeTouchCancelledHandler(CCTouch* pTouch, float fDuration) { if( m_pTouchCancelledListener && m_pTouchCancelledHandler ) { if( !(m_pTouchCancelledListener->*m_pTouchCancelledHandler)(m_pThisObject, pTouch, fDuration) ) { return; } } #if USING_LUA else if( m_nTouchCancelledScriptHandler != 0 ) { CCLuaEngine* pEngine = CCLuaEngine::defaultEngine(); CCLuaStack* pStack = pEngine->getLuaStack(); pStack->pushCCObject(m_pThisObject, "CCObject"); pStack->pushCCObject(pTouch, "CCTouch"); pStack->pushFloat(fDuration); CCArray* pRetArray = new CCArray(); pRetArray->initWithCapacity(1); int nRet = pStack->executeFunctionReturnArray(m_nTouchCancelledScriptHandler, 3, 1, pRetArray); CCAssert(pRetArray->count() > 0, "return count = 0"); CCBool* pBool = (CCBool*) pRetArray->objectAtIndex(0); bool bContinue = pBool->getValue(); delete pRetArray; pStack->clean(); if(!bContinue) { return; } } #endif this->onTouchCancelled(pTouch, fDuration); return; }