本文整理汇总了C++中CCLuaStack::executeScriptFile方法的典型用法代码示例。如果您正苦于以下问题:C++ CCLuaStack::executeScriptFile方法的具体用法?C++ CCLuaStack::executeScriptFile怎么用?C++ CCLuaStack::executeScriptFile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CCLuaStack
的用法示例。
在下文中一共展示了CCLuaStack::executeScriptFile方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: applicationDidFinishLaunching
//.........这里部分代码省略.........
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());
}
}
string env = "__LUA_STARTUP_FILE__=\"";
env.append(path);
env.append("\"");
pStack->setXXTEAKeyAndSign("CFgrrwCFewrf", 12);
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
#if 0
std::string rootDir = CCFileUtils::sharedFileUtils()->getWritablePath();
#else
std::string rootDir = CCFileUtils::sharedFileUtils()->getWritablePath();
#endif
std::string dataPath = cachePath + "game.dat";
CCLog("LOAD MAIN.LUA dataPath=%s",dataPath.c_str());
CCLog("LOAD MAIN.LUA begin--");
bool runCompliedScript = true; ////////////////////////------------------USE COMPILED RESOURCE??
if (runCompliedScript) {
if(pStack->loadChunksFromZIP(dataPath.c_str()))
{
CCLog("LOAD MAIN.LUA end2--");
pEngine->executeString("require \"main\"");
CCLog("LOAD MAIN.LUA end3--");
}
}
else
{
CCLog("LOAD MAIN.LUA end5--");
pEngine->executeString("print(\"blah\")");
pEngine->executeString("CCLuaLog(\"blah\")");
std::string dataPath = rootDir+pathBase + "scripts/main.lua";
CCLog("dataPath:%s",dataPath.c_str());
if(pStack->executeScriptFile(dataPath.c_str()))
{
CCLog("LOAD MAIN.LUA end6--");
pEngine->executeString("require \"main\"");
}
}
CCLog("LOAD MAIN.LUA end7--");
pEngine->executeString(env.c_str());
CCLog("LOAD MAIN.LUA end4--");
CCLog("LOAD MAIN.LUA end4--");
#else
string dataPath = CCFileUtils::sharedFileUtils()->getWritablePath();
dataPath += "res"DIRECTORY_SEPARATOR"game2.dat";
if(pStack->loadChunksFromZip(dataPath.c_str()))
{
pEngine->executeString("require \"main\"");
}
else
{
CCLOG("------------------------------------------------");
CCLOG("LOAD LUA FILE: %s", path.c_str());
CCLOG("------------------------------------------------");
pEngine->executeScriptFile(path.c_str());
}
#endif
return true;
}