void PlayerWin::loadLuaConfig() { LuaEngine* pEngine = LuaEngine::getInstance(); ScriptEngineManager::getInstance()->setScriptEngine(pEngine); // load player lua core luaopen_PlayerLuaCore(pEngine->getLuaStack()->getLuaState()); luaopen_PlayerLuaCore_Manual(pEngine->getLuaStack()->getLuaState()); // set env string quickRootPath = SimulatorConfig::getInstance()->getQuickCocos2dxRootPath(); quickRootPath = convertPathFormatToUnixStyle(quickRootPath); string env = "__G_QUICK_V3_ROOT__=\""; env.append(quickRootPath); env.append("\""); pEngine->executeString(env.c_str()); // set user home dir lua_pushstring(pEngine->getLuaStack()->getLuaState(), getUserDocumentPath().c_str()); lua_setglobal(pEngine->getLuaStack()->getLuaState(), "__USER_HOME__"); // // ugly: Add the opening project to the "Open Recents" list // lua_pushstring(pEngine->getLuaStack()->getLuaState(), _project.getProjectDir().c_str()); lua_setglobal(pEngine->getLuaStack()->getLuaState(), "__PLAYER_OPEN_TITLE__"); lua_pushstring(pEngine->getLuaStack()->getLuaState(), _project.makeCommandLine().c_str()); lua_setglobal(pEngine->getLuaStack()->getLuaState(), "__PLAYER_OPEN_COMMAND__"); // load player.lua string playerCoreFilePath = quickRootPath + "quick/welcome/src/player.lua"; pEngine->getLuaStack()->executeScriptFile(playerCoreFilePath.c_str()); }
bool AppDelegate::applicationDidFinishLaunching() { // register lua engine LuaEngine* pEngine = LuaEngine::getInstance(); ScriptEngineManager::getInstance()->setScriptEngine(pEngine); LuaStack* stack = pEngine->getLuaStack(); stack->setXXTEAKeyAndSign("2dxLua", strlen("2dxLua"), "XXTEA", strlen("XXTEA")); lua_State* L = stack->getLuaState(); lua_module_register(L); lua_getglobal(L, "_G"); if (lua_istable(L,-1))//stack:...,_G, { #if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 || CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID ||CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_MAC) register_assetsmanager_test_sample(L); #endif register_test_binding(L); } lua_pop(L, 1); pEngine->executeScriptFile("src/controller.lua"); return true; }
bool AppDelegate::applicationDidFinishLaunching() { // initialize director auto pDirector = Director::getInstance(); pDirector->setOpenGLView(EGLView::getInstance()); // 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); auto screenSize = EGLView::getInstance()->getFrameSize(); auto designSize = Size(480, 320); auto pFileUtils = FileUtils::getInstance(); if (screenSize.height > 320) { auto resourceSize = Size(960, 640); std::vector<std::string> searchPaths; searchPaths.push_back("hd"); pFileUtils->setSearchPaths(searchPaths); pDirector->setContentScaleFactor(resourceSize.height/designSize.height); } EGLView::getInstance()->setDesignResolutionSize(designSize.width, designSize.height, ResolutionPolicy::FIXED_HEIGHT); // register lua engine LuaEngine* pEngine = LuaEngine::getInstance(); ScriptEngineManager::getInstance()->setScriptEngine(pEngine); #if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 || CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID ||CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_MAC) LuaStack* stack = pEngine->getLuaStack(); register_assetsmanager_test_sample(stack->getLuaState()); #endif std::vector<std::string> searchPaths = pFileUtils->getSearchPaths(); searchPaths.insert(searchPaths.begin(), "Images"); searchPaths.insert(searchPaths.begin(), "cocosbuilderRes"); if (screenSize.height > 320) { searchPaths.insert(searchPaths.begin(), "hd/scenetest/LoadSceneEdtiorFileTest"); } else { searchPaths.insert(searchPaths.begin(), "scenetest/LoadSceneEdtiorFileTest"); } #if CC_TARGET_PLATFORM == CC_PLATFORM_BLACKBERRY searchPaths.push_back("TestCppResources"); searchPaths.push_back("script"); #endif FileUtils::getInstance()->setSearchPaths(searchPaths); pEngine->executeScriptFile("luaScript/controller.lua"); return true; }
void MovieView::executeCallBack(int nHandle) { LuaEngine* pEngine = LuaEngine::getInstance(); LuaStack* pStack = pEngine->getLuaStack(); int nRet = pStack->executeFunctionByHandler(nHandle, 0); pStack->clean(); }
bool AppDelegate::applicationDidFinishLaunching() { // initialize director auto director = Director::getInstance(); auto glview = director->getOpenGLView(); if (!glview) { glview = GLViewImpl::createWithRect("CocosWeb", Rect(0, 0, 6400, 9600)); director->setOpenGLView(glview); } #if ISTEST director->getOpenGLView()->setFrameSize(320, 480); #else director->getOpenGLView()->setFrameSize(glview->getVisibleRect().size.width, glview->getVisibleRect().size.height); #endif director->getOpenGLView()->setDesignResolutionSize(640, 960, ResolutionPolicy::SHOW_ALL); // turn on display FPS director->setDisplayStats(true); // set FPS. the default value is 1.0/60 if you don't call this director->setAnimationInterval(1.0 / 30); LuaEngine* pEngine = LuaEngine::getInstance(); ScriptEngineManager::getInstance()->setScriptEngine(pEngine); lua_State* L = pEngine->getLuaStack()->getLuaState(); lua_module_register(L); #if ISTEST AllocConsole(); HWND _hwndConsole = GetConsoleWindow(); if (_hwndConsole != NULL) { ShowWindow(_hwndConsole, SW_SHOW); BringWindowToTop(_hwndConsole); freopen("CONOUT$", "wt", stdout); freopen("CONOUT$", "wt", stderr); HMENU hmenu = GetSystemMenu(_hwndConsole, FALSE); if (hmenu != NULL) { DeleteMenu(hmenu, SC_CLOSE, MF_BYCOMMAND); } } pEngine->executeString("print=release_print"); FileUtils::getInstance()->addSearchPath("../../Resources/res"); #else FileUtils::getInstance()->addSearchPath("res"); FileUtils::getInstance()->addSearchPath("LuaScript"); pEngine->getInstance()->addLuaLoader(decode_lua_loader); #endif pEngine->executeScriptFile("main.lua"); new GameInitiali(); SceneManager::instance()->showScene("mainScene"); return true; }
void CNetDelegate::executeOnExceptionCaughtScriptHandler(CCSocketStatus eStatus) { if (m_nExceptionCaughtScriptHandler != 0) { LuaEngine* pEngine = LuaEngine::getInstance(); LuaStack* pStack = pEngine->getLuaStack(); pStack->pushInt((int)eStatus); pStack->executeFunctionByHandler(m_nExceptionCaughtScriptHandler, 1); pStack->clean(); } }
void CNetDelegate::executeOnMessageReceivedScriptHandler(CBuffer *oBuffer) { if (m_nMessageReceivedScriptHandler != 0) { LuaEngine* pEngine = LuaEngine::getInstance(); LuaStack* pStack = pEngine->getLuaStack(); pStack->pushObject(oBuffer, "CBuffer"); pStack->executeFunctionByHandler(m_nMessageReceivedScriptHandler, 1); pStack->clean(); } }
void CCMsgDelegate::executeOnMessageScriptHandler(unsigned int uMsg, Ref* pMsgObj) { if (m_nMessageScriptHandler != 0) { LuaEngine* pEngine = LuaEngine::getInstance(); LuaStack* pStack = pEngine->getLuaStack(); pStack->pushInt(uMsg); pStack->pushObject(pMsgObj, "Ref"); pStack->executeFunctionByHandler(m_nMessageScriptHandler, 2); pStack->clean(); } }
bool AppDelegate::applicationDidFinishLaunching() { auto theFileUtils = FileUtils::getInstance(); auto paths = theFileUtils->getSearchPaths(); auto rootDirectory = paths[0]; // set working directory #if defined(_WIN32) char buffer[512] = { 0 }; _getcwd(buffer, sizeof(buffer)); std::string workingDirectory = buffer; auto index = workingDirectory.find_last_of('\\'); rootDirectory = workingDirectory.substr(0, index); #endif paths.clear(); paths.push_back(rootDirectory + "/data"); paths.push_back(theFileUtils->getWritablePath()); theFileUtils->setSearchPaths(paths); // register lua engine LuaEngine* engine = LuaEngine::getInstance(); std::string scriptsPath = rootDirectory + "/scripts"; engine->addSearchPath(scriptsPath.c_str()); ScriptEngineManager::getInstance()->setScriptEngine(engine); lua_State* L = engine->getLuaStack()->getLuaState(); lua_module_register(L); for (auto& arg : args) { if (arg == "-debug") { engine->executeString("debugEnabled = true"); } } engine->executeString("require 'main.lua'"); setIcon(); return true; }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); QStackedWidget *stackedWidget = this->findChild<QStackedWidget *>(tr("stackedWidget")); if (stackedWidget) { stackedWidget->setCurrentIndex(0); } LuaEngine *pEngine = LuaEngine::getInstance(); L = pEngine->getLuaStack()->getLuaState(); tabWidget = this->findChild<QTabWidget *>(tr("tabWidget")); setValidator(); }
void ComponentLua::initClass() { static bool run = true; if (run) { // LUA_REGISTRYINDEX["component"] = new table LuaEngine* engine = LuaEngine::getInstance(); lua_State* l = engine->getLuaStack()->getLuaState(); lua_pushstring(l, KEY_COMPONENT); // stack: "component" lua_newtable(l); // stack: "component" table lua_rawset(l, LUA_REGISTRYINDEX); // stack: - run = false; } }
CSceneExtension* CSceneManager::loadScene(const char* pSceneName) { CCAssert(pSceneName && strlen(pSceneName), "should not null"); map<string, CSceneExtension*>::iterator mitr = m_mSceneCachePool.find(pSceneName); if( mitr != m_mSceneCachePool.end() ) { return mitr->second; } #if USING_LUA map<string,int>::iterator itr = m_mFnSceneCreateScriptFunc.find(pSceneName); if(itr!=m_mFnSceneCreateScriptFunc.end()) { LuaEngine* pEngine = LuaEngine::getInstance(); LuaStack* pStack = pEngine->getLuaStack(); __Array pRetArray; pRetArray.initWithCapacity(1); int nRet = pStack->executeFunctionReturnArray(itr->second, 0, 1, pRetArray); CCAssert(pRetArray.count() > 0, "return num = 0"); Ref* pReturnObject = pRetArray.getObjectAtIndex(0); pStack->clean(); CSceneExtension* pSceneExt = dynamic_cast<CSceneExtension*>(pReturnObject); pSceneExt->setClassName(pSceneName); return pSceneExt; } #else map<string, Fn_CreateSceneExtension>::iterator itr = m_mFnSceneCreatePointers.find(pSceneName); if( itr != m_mFnSceneCreatePointers.end() ) { CSceneExtension* pScene = (*itr->second)(); pScene->setClassName(pSceneName); pScene->init(); pScene->autorelease(); return pScene; } #endif return NULL; }
void CWidgetWindow::executeTouchCancelledAfterLongClickHandler(Ref* pSender, Touch *pTouch, float fDuration) { if( m_pTouchCancelledAfterLongClickListener && m_pTouchCancelledAfterLongClickHandler ) { (m_pTouchCancelledAfterLongClickListener->*m_pTouchCancelledAfterLongClickHandler)(pSender, pTouch, fDuration); } #if USING_LUA else if( m_pTouchCancelledAfterLongClickScriptHandler != 0 ) { LuaEngine* pEngine = LuaEngine::getInstance(); LuaStack* pStack = pEngine->getLuaStack(); pStack->pushObject(pSender, "Ref"); pStack->pushObject(pTouch, "Touch"); pStack->pushFloat(fDuration); int nRet = pStack->executeFunctionByHandler(m_pTouchCancelledAfterLongClickScriptHandler, 3); pStack->clean(); } #endif }
static LuaStack * initExecParam(Node *node, int phase) { if (!node) return nullptr; int id = node->_luaID; if (id<1) { return nullptr; } LuaEngine* engine = LuaEngine::getInstance(); auto stack = engine->getLuaStack(); stack->clean(); auto L = stack->getLuaState(); luaL_getmetatable(L, "cc.Node"); /* stack: mt */ lua_pushliteral(L, "EventDispatcher"); lua_rawget(L, -2); /* stack: mt func */ lua_pushstring(L, "tolua_ubox"); /* stack: mt func key */ lua_rawget(L, -3); /* stack: mt func ubox */ if (lua_isnil(L, -1)) { // use global ubox lua_pop(L, 1); /* stack: mt func */ lua_pushstring(L, "tolua_ubox"); /* stack: mt func key */ lua_rawget(L, LUA_REGISTRYINDEX); /* stack: mt func ubox */ }; lua_pushlightuserdata(L, node); /* stack: mt func ubox ptr */ lua_rawget(L,-2); /* stack: mt func ubox ud */ if (lua_isnil(L, -1)) { stack->clean(); return nullptr; } int etype = (phase == NODE_TOUCH_CAPTURING_PHASE) ? NODE_TOUCH_CAPTURE_EVENT : NODE_TOUCH_EVENT; lua_pushnumber(L, etype); /* stack: mt func ubox ud etype */ lua_remove(L, -3); /* stack: mt func ud etype */ return stack; }
bool AppDelegate::applicationDidFinishLaunching() { #if CC_TARGET_PLATFORM == CC_PLATFORM_MAC if (_projectConfig.getDebuggerType() == kCCLuaDebuggerCodeIDE) { initRuntime(_projectConfig.getProjectDir()); if (!ConfigParser::getInstance()->isInit()) { ConfigParser::getInstance()->readConfig(); } } #endif //CC_TARGET_PLATFORM == CC_PLATFORM_MAC // initialize director auto director = Director::getInstance(); auto glview = director->getOpenGLView(); if(!glview) { #if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 || CC_TARGET_PLATFORM == CC_PLATFORM_MAC || CC_TARGET_PLATFORM == CC_PLATFORM_WP8) #else Size viewSize = _projectConfig.getFrameSize(); glview = GLView::createWithRect("simpleui", Rect(0,0,viewSize.width,viewSize.height)); director->setOpenGLView(glview); #endif } // turn on display FPS director->setDisplayStats(true); // set FPS. the default value is 1.0/60 if you don't call this director->setAnimationInterval(1.0 / 60); // register lua engine LuaEngine* pEngine = LuaEngine::getInstance(); ScriptEngineManager::getInstance()->setScriptEngine(pEngine); LuaStack *pStack = pEngine->getLuaStack(); #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) // load framework pStack->loadChunksFromZIP("res/framework_precompiled.zip"); // set script path string path = FileUtils::getInstance()->fullPathForFilename("src/main.lua"); #elif (CC_TARGET_PLATFORM == CC_PLATFORM_WP8 || CC_TARGET_PLATFORM == CC_PLATFORM_WINRT) // load framework pStack->loadChunksFromZIP("res/framework_precompiled_wp8.zip"); // set script path string path = FileUtils::getInstance()->fullPathForFilename("src/main.lua"); #else // load framework if (_projectConfig.isLoadPrecompiledFramework()) { const string precompiledFrameworkPath = SimulatorConfig::getInstance()->getPrecompiledFrameworkPath(); pStack->loadChunksFromZIP(precompiledFrameworkPath.c_str()); } // set script path string path = FileUtils::getInstance()->fullPathForFilename(_projectConfig.getScriptFileRealPath().c_str()); #endif #if CC_TARGET_PLATFORM == CC_PLATFORM_MAC // Code IDE if (_projectConfig.getDebuggerType() == kCCLuaDebuggerCodeIDE) { if (startRuntime()) return true; } #endif //CC_TARGET_PLATFORM == CC_PLATFORM_MAC 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; }
bool AppDelegate::applicationDidFinishLaunching() { auto director = Director::getInstance(); auto glview = director->getOpenGLView(); if(!glview) { glview = GLView::createWithRect("Test Lua", Rect(0,0,900,640)); director->setOpenGLView(glview); } // turn on display FPS director->setDisplayStats(true); // set FPS. the default value is 1.0/60 if you don't call this director->setAnimationInterval(1.0 / 60); auto screenSize = glview->getFrameSize(); auto designSize = Size(480, 320); auto pFileUtils = FileUtils::getInstance(); if (screenSize.height > 320) { auto resourceSize = Size(960, 640); std::vector<std::string> searchPaths; searchPaths.push_back("hd"); pFileUtils->setSearchPaths(searchPaths); director->setContentScaleFactor(resourceSize.height/designSize.height); } glview->setDesignResolutionSize(designSize.width, designSize.height, ResolutionPolicy::FIXED_HEIGHT); // register lua engine LuaEngine* pEngine = LuaEngine::getInstance(); ScriptEngineManager::getInstance()->setScriptEngine(pEngine); #if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 || CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID ||CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_MAC) LuaStack* stack = pEngine->getLuaStack(); register_assetsmanager_test_sample(stack->getLuaState()); #endif std::string resPrefix("res/"); std::vector<std::string> searchPaths = pFileUtils->getSearchPaths(); searchPaths.insert(searchPaths.begin(), resPrefix); searchPaths.insert(searchPaths.begin(), resPrefix + "Images"); searchPaths.insert(searchPaths.begin(), resPrefix + "cocosbuilderRes"); if (screenSize.height > 320) { searchPaths.insert(searchPaths.begin(), resPrefix + "hd"); searchPaths.insert(searchPaths.begin(), resPrefix + "hd/Images"); searchPaths.insert(searchPaths.begin(), resPrefix + "hd/scenetest/ArmatureComponentTest"); searchPaths.insert(searchPaths.begin(), resPrefix + "hd/scenetest/AttributeComponentTest"); searchPaths.insert(searchPaths.begin(), resPrefix + "hd/scenetest/BackgroundComponentTest"); searchPaths.insert(searchPaths.begin(), resPrefix + "hd/scenetest/EffectComponentTest"); searchPaths.insert(searchPaths.begin(), resPrefix + "hd/scenetest/LoadSceneEdtiorFileTest"); searchPaths.insert(searchPaths.begin(), resPrefix + "hd/scenetest/ParticleComponentTest"); searchPaths.insert(searchPaths.begin(), resPrefix + "hd/scenetest/SpriteComponentTest"); searchPaths.insert(searchPaths.begin(), resPrefix + "hd/scenetest/TmxMapComponentTest"); searchPaths.insert(searchPaths.begin(), resPrefix + "hd/scenetest/UIComponentTest"); searchPaths.insert(searchPaths.begin(), resPrefix + "hd/scenetest/TriggerTest"); } else { searchPaths.insert(searchPaths.begin(), resPrefix + "scenetest/ArmatureComponentTest"); searchPaths.insert(searchPaths.begin(), resPrefix + "scenetest/AttributeComponentTest"); searchPaths.insert(searchPaths.begin(), resPrefix + "scenetest/BackgroundComponentTest"); searchPaths.insert(searchPaths.begin(), resPrefix + "scenetest/EffectComponentTest"); searchPaths.insert(searchPaths.begin(), resPrefix + "scenetest/LoadSceneEdtiorFileTest"); searchPaths.insert(searchPaths.begin(), resPrefix + "scenetest/ParticleComponentTest"); searchPaths.insert(searchPaths.begin(), resPrefix + "scenetest/SpriteComponentTest"); searchPaths.insert(searchPaths.begin(), resPrefix + "scenetest/TmxMapComponentTest"); searchPaths.insert(searchPaths.begin(), resPrefix + "scenetest/UIComponentTest"); searchPaths.insert(searchPaths.begin(), resPrefix + "scenetest/TriggerTest"); } FileUtils::getInstance()->setSearchPaths(searchPaths); pEngine->executeScriptFile("src/controller.lua"); return true; }