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 = _project.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->executeScriptFile(playerCoreFilePath.c_str()); }
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; }
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; }
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; }