本文整理汇总了C++中CCLuaStack::addSearchPath方法的典型用法代码示例。如果您正苦于以下问题:C++ CCLuaStack::addSearchPath方法的具体用法?C++ CCLuaStack::addSearchPath怎么用?C++ CCLuaStack::addSearchPath使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CCLuaStack
的用法示例。
在下文中一共展示了CCLuaStack::addSearchPath方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例2: 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());
}
示例3: initLuaGlobalVariables
void initLuaGlobalVariables(const std::string& entry)
{
//GLOBAL_ROOT_DIR
CCLuaEngine* pEngine = CCLuaEngine::defaultEngine();
CCLuaStack* pStack = pEngine->getLuaStack();
CCFileUtils* pFileUtils = CCFileUtils::sharedFileUtils();
using namespace std;
string path = pFileUtils->fullPathForFilename(entry.c_str());
// replace "\" with "/", normalize the path
int pos = string::npos;
while ((pos = path.find_first_of("\\")) != string::npos)
{
path.replace(pos, 1, "/");
}
string script_dir = path.substr(0, path.find_last_of("/"));
string root_dir = script_dir.substr(0, script_dir.find_last_of("/"));
CCLOG("RootDir: %s\nScriptDir: %s \n",root_dir.c_str(), script_dir.c_str());
std::string env = "GLOBAL_ROOT_DIR=\""; env.append(root_dir); env.append("\"");
pEngine->executeString(env.c_str());
env = "__LUA_STARTUP_FILE__=\"";env.append(path);env.append("\"");
pEngine->executeString(env.c_str());
pStack->addSearchPath(script_dir.c_str());
pFileUtils->addSearchPath(root_dir.c_str());
pFileUtils->addSearchPath(script_dir.c_str());
ScutExt::Init(root_dir+"/");
}
示例4: 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();
lua_State* L = pStack->getLuaState();
// load lua extensions
luaopen_lua_extensions(L);
// load cocos2dx_extensions luabinding
luaopen_cocos2dx_extensions_luabinding(L);
// load cocos2dx_extra luabinding
luaopen_cocos2dx_extra_luabinding(L);
// load precompiled framework
luaopen_framework_precompiled(L);
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
string path = CCFileUtils::sharedFileUtils()->fullPathForFilename("scripts/main.lua");
#else
string path = CCFileUtils::sharedFileUtils()->fullPathForFilename(getStartupScriptFilename().c_str());
#endif
int 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;
}
示例5: run
int UiPlayer::run(void)
{
const char *QUICK_COCOS2DX_ROOT = getenv("QUICK_COCOS2DX_ROOT");
SimulatorConfig::sharedDefaults()->setQuickCocos2dxRootPath(QUICK_COCOS2DX_ROOT);
loadProjectConfig();
HWND hwndConsole = NULL;
if (m_project.isShowConsole())
{
AllocConsole();
freopen("CONOUT$", "wt", stdout);
freopen("CONOUT$", "wt", stderr);
// disable close console
hwndConsole = GetConsoleWindow();
if (hwndConsole != NULL)
{
HMENU hMenu = GetSystemMenu(hwndConsole, FALSE);
if (hMenu != NULL) DeleteMenu(hMenu, SC_CLOSE, MF_BYCOMMAND);
ShowWindow(hwndConsole, SW_SHOW);
BringWindowToTop(hwndConsole);
}
}
if (m_project.isWriteDebugLogToFile())
{
const string debugLogFilePath = m_project.getDebugLogFilePath();
m_writeDebugLogFile = fopen(debugLogFilePath.c_str(), "w");
if (!m_writeDebugLogFile)
{
CCLOG("Cannot create debug log file %s", debugLogFilePath.c_str());
}
}
do
{
m_exit = TRUE;
// create the application instance
m_app = new AppDelegate();
m_app->setProjectConfig(m_project);
// set environments
SetCurrentDirectoryA(m_project.getProjectDir().c_str());
CCFileUtils::sharedFileUtils()->setSearchRootPath(m_project.getProjectDir().c_str());
CCFileUtils::sharedFileUtils()->setWritablePath(m_project.getWritableRealPath().c_str());
// create opengl view
CCEGLView* eglView = CCEGLView::sharedOpenGLView();
eglView->setMenuResource(MAKEINTRESOURCE(IDC_LUAHOSTWIN32));
eglView->setWndProc(WindowProc);
eglView->setFrameSize(m_project.getFrameSize().width, m_project.getFrameSize().height);
eglView->setFrameZoomFactor(m_project.getFrameScale());
// make window actived
m_hwnd = eglView->getHWnd();
BringWindowToTop(m_hwnd);
SetWindowTextA(m_hwnd, "ui-player");
// restore window position
const CCPoint windowOffset = m_project.getWindowOffset();
if (windowOffset.x != 0 || windowOffset.y != 0)
{
eglView->moveWindow(windowOffset.x, windowOffset.y);
}
// set icon
HICON icon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_LUAHOSTWIN32));
SendMessage(m_hwnd, WM_SETICON, ICON_BIG, (LPARAM)icon);
if (hwndConsole)
{
SendMessage(hwndConsole, WM_SETICON, ICON_BIG, (LPARAM)icon);
}
// update menu
createViewMenu();
updateMenu();
// run game
CCLuaStack *stack = CCLuaEngine::defaultEngine()->getLuaStack();
const vector<string> arr = m_project.getPackagePathArray();
for (vector<string>::const_iterator it = arr.begin(); it != arr.end(); ++it)
{
stack->addSearchPath(it->c_str());
}
m_app->run();
// cleanup
CCScriptEngineManager::sharedManager()->removeScriptEngine();
CCScriptEngineManager::purgeSharedManager();
CocosDenshion::SimpleAudioEngine::end();
delete m_app;
m_app = NULL;
} while (!m_exit);
//.........这里部分代码省略.........
示例6: 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();
lua_State* L = pStack->getLuaState();
luaopen_MapRuntimeC_luabinding(L);
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
// load framework
// pStack->loadChunksFromZIP("res/framework_precompiled.zip");
// 如果设置了 -e 和 -ek 要加上下面这句
// pStack->setXXTEAKeyAndSign("aaa", 3);
// 如果设置了 -e 和 -ek -es 则要加上下面这句
pStack->setXXTEAKeyAndSign("aaa", 3, "XT", 2);
// load framework
pStack->loadChunksFromZIP("res/script/framework_precompiled.zip");
pStack->loadChunksFromZIP("res/script/game.zip");
pStack->executeString("require 'main'");
// set script path
//string path = CCFileUtils::sharedFileUtils()->fullPathForFilename("scripts/main.lua");
string path = CCFileUtils::sharedFileUtils()->fullPathForFilename("scripts/main.lua");
#else
// load framework
if (m_projectConfig.isLoadPrecompiledFramework())
{
const string precompiledFrameworkPath = SimulatorConfig::sharedDefaults()->getPrecompiledFrameworkPath();
const string precompiledGamePath = SimulatorConfig::sharedDefaults()->getPrecompiledGamePath();
pStack->setXXTEAKeyAndSign("aaa", 3, "XT", 2);//加密操作
pStack->loadChunksFromZIP(precompiledFrameworkPath.c_str());
pStack->loadChunksFromZIP(precompiledGamePath.c_str());
pStack->executeString("require 'main'");
}
// set script path
string path = CCFileUtils::sharedFileUtils()->fullPathForFilename(m_projectConfig.getScriptFileRealPath().c_str());
#endif
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("==",env.c_str());
CCLOG("------------------------------------------------");
CCLOG("LOAD LUA FILE: %s", path.c_str());
CCLOG("------------------------------------------------");
//pEngine->executeScriptFile(path.c_str());
//pEngine->executeScriptFile("main.lua");
return true;
}
示例7: applicationDidFinishLaunching
bool AppDelegate::applicationDidFinishLaunching()
{
//#if CC_TARGET_PLATFORM == CC_PLATFORM_IOS
// //Lua版本、JS版本请参考并在lua侧或js侧调用,同时请在该applicationFinishLaunching接口调用dataeye.h中的接口注入接口
// //添加DataEye需要配置的appID和channelId
// //APPID 是一组32位的代码,可以在g.dataeye.com创建游戏后获得.
// //“937042C1192B1833CD8DF4895B281674”的部分要按照实际情况设置,一定要记得替换哦
// //DC_AFTER_LOGIN模式适用于有账号体系的游戏,后面必须要调用DCAccount login,否则不会上报数据。
// //DEFAULT模式适用于不存在账号体系的游戏(如单机),SDK会用设备ID作为用户的ID
// //请选择合适于自己游戏的上报模式
// DCAgent::setReportMode(DC_AFTER_LOGIN);
// DCAgent::setDebugMode(true);
// DCAgent::onStart("937042C1192B1833CD8DF4895B281674", "DataEye");
//#endif
// initialize director
CCDirector *pDirector = CCDirector::sharedDirector();
pDirector->setOpenGLView(CCEGLView::sharedOpenGLView());
pDirector->setProjection(kCCDirectorProjection2D);
/////.........COPY 3 FILES FIRST. //////////////////
string Srcfile = CCFileUtils::sharedFileUtils()->getSearchPaths()[0] + "res_phone/";//game.dat"; //game.dat
string cachePath = CCFileUtils::sharedFileUtils()->getWritablePath() + "res_iphone/";
string lockPath = cachePath + ".lock";
fstream _file;
_file.open(lockPath.c_str(),ios::in);
CCLog("Srcfile:%s",Srcfile.c_str());
CCLog("cachePath:%s",cachePath.c_str());
CCLog("lockPath:%s",lockPath.c_str());
if (!_file)
{
if ( CheckDir(cachePath.c_str()) )
{
CCLog("create :%s success!",cachePath.c_str());
MyCopyFile(Srcfile + "game.dat",cachePath + "game.dat");
MyCopyFile(Srcfile + "framework_precompiled.zip",cachePath + "framework_precompiled.zip");
ofstream fout;
fout.open(cachePath+".lock",ios::app);
fout<<" "<<endl;
}
else
{
CCLog("create :%s failed!",cachePath.c_str());
}
}
else
{
CCLog(".lock exists!");
}
// 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();
#if CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
lua_State *tolua_s = pStack->getLuaState();
#endif
#if defined(ENCRYPT_RESOURCE_ENABLED) && ENCRYPT_RESOURCE_ENABLED == 1
std::string pathBase = "res_phone/";
#else
std::string pathBase = "res/";
#endif
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
// load framework
pathBase = "res_phone/";
std::string pre_zip = "framework_precompiled.zip";
pre_zip = pathBase+pre_zip;
CCLog("cpp loadChunksFromZIP begin-- ");
pStack->loadChunksFromZIP(pre_zip.c_str());
CCLog("cpp loadChunksFromZIP end-- ");
// set script path
string path = CCFileUtils::sharedFileUtils()->fullPathForFilename("scripts/main.lua");
#endif
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());
//.........这里部分代码省略.........
示例8: loadProjectConfig
int LuaHostWin32::run(void)
{
loadProjectConfig();
AllocConsole();
freopen("CONOUT$", "wt", stdout);
freopen("CONOUT$", "wt", stderr);
// disable close console
HWND hwndConsole = GetConsoleWindow();
if (hwndConsole != NULL)
{
HMENU hMenu = GetSystemMenu(hwndConsole, FALSE);
if (hMenu != NULL) DeleteMenu(hMenu, SC_CLOSE, MF_BYCOMMAND);
}
do
{
m_exit = TRUE;
if (m_project.isShowConsole())
{
ShowWindow(hwndConsole, SW_SHOW);
BringWindowToTop(hwndConsole);
}
else
{
ShowWindow(hwndConsole, SW_HIDE);
}
// create the application instance
m_app = new AppDelegate();
m_app->setStartupScriptFilename(m_project.getScriptFilePath());
// set environments
SetCurrentDirectoryA(m_project.getProjectDir().c_str());
vector<string> searchPaths;
searchPaths.push_back(m_project.getProjectDir());
CCFileUtils::sharedFileUtils()->setSearchPaths(searchPaths);
// create opengl view
CCEGLView* eglView = CCEGLView::sharedOpenGLView();
eglView->setMenuResource(MAKEINTRESOURCE(IDC_LUAHOSTWIN32));
eglView->setWndProc(WindowProc);
eglView->setFrameSize(m_project.getFrameSize().width, m_project.getFrameSize().height);
eglView->setFrameZoomFactor(m_project.getFrameScale());
// make window actived
m_hwnd = eglView->getHWnd();
BringWindowToTop(m_hwnd);
// restore window position
const CCPoint windowOffset = m_project.getWindowOffset();
if (windowOffset.x >= 0 || windowOffset.y >= 0)
{
eglView->moveWindow(windowOffset.x, windowOffset.y);
}
// set icon
HICON icon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_LUAHOSTWIN32));
SendMessage(m_hwnd, WM_SETICON, ICON_BIG, (LPARAM)icon);
SendMessage(hwndConsole, WM_SETICON, ICON_BIG, (LPARAM)icon);
// run game
CCLuaStack *stack = CCLuaEngine::defaultEngine()->getLuaStack();
const vector<string> arr = m_project.getPackagePathArray();
for (vector<string>::const_iterator it = arr.begin(); it != arr.end(); ++it)
{
stack->addSearchPath(it->c_str());
}
m_app->run();
// cleanup
CCScriptEngineManager::sharedManager()->removeScriptEngine();
CCScriptEngineManager::purgeSharedManager();
CocosDenshion::SimpleAudioEngine::end();
delete m_app;
m_app = NULL;
} while (!m_exit);
FreeConsole();
return 0;
}