本文整理汇总了C++中CCLuaEngine::executeString方法的典型用法代码示例。如果您正苦于以下问题:C++ CCLuaEngine::executeString方法的具体用法?C++ CCLuaEngine::executeString怎么用?C++ CCLuaEngine::executeString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CCLuaEngine
的用法示例。
在下文中一共展示了CCLuaEngine::executeString方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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+"/");
}
示例2: applicationDidFinishLaunching
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);
pDirector->runWithScene( TestScene::create() );
#if 0
// 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
#endif
return true;
}
示例3: applicationDidFinishLaunching
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->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 dirPath = "luaScript";
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
CCString* pstrFileContent = CCString::createWithContentsOfFile((dirPath + "/controller.lua").c_str());
if (pstrFileContent)
{
pEngine->executeString(pstrFileContent->getCString());
}
#else
std::string path = CCFileUtils::sharedFileUtils()->fullPathFromRelativePath((dirPath + "/controller.lua").c_str());
pEngine->addSearchPath(path.substr(0, path.find_last_of("/") - dirPath.length()).c_str());
pEngine->executeScriptFile(path.c_str());
#endif
return true;
}
示例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();
// 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;
}
示例5: 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());
}
示例6: executeScriptFile
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
}
示例7: applicationDidFinishLaunching
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;
}
示例8:
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
}
示例9: applicationDidFinishLaunching
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;
}
示例10: 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;
}
示例11: 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;
}
示例12: applicationDidFinishLaunching
bool AppDelegate::applicationDidFinishLaunching()
{
// initialize director
CCDirector *pDirector = CCDirector::sharedDirector();
pDirector->setOpenGLView(CCEGLView::sharedOpenGLView());
CCEGLView::sharedOpenGLView()->setDesignResolutionSize(480, 800, kResolutionShowAll);
// turn on display FPS
pDirector->setDisplayStats(false);
// 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();
lua_State *state = pEngine->getLuaStack()->getLuaState();
tolua_MyExt_open(state);
CCScriptEngineManager::sharedManager()->setScriptEngine(pEngine);
//加载cjson
CCLuaStack *pStack = pEngine->getLuaStack();
lua_State* L = pStack->getLuaState();
luaopen_lua_extensions(L);
#if (CC_TARGET_PLATFORM != CC_PLATFORM_WIN32 && ANALYTICS_UMENG == 1)
loadAnalyticsPlugin();
g_pAnalytics->setDebugMode(false);
g_pAnalytics->startSession(s_strAppKey.c_str());
g_pAnalytics->setCaptureUncaughtException(true);
AnalyticsUmeng* pUmeng = dynamic_cast<AnalyticsUmeng*>(g_pAnalytics);
//AnalyticsFlurry* pFlurry = dynamic_cast<AnalyticsFlurry*>(g_pAnalytics);
if (pUmeng != NULL)
{
pUmeng->updateOnlineConfig();
pUmeng->setDefaultReportPolicy(AnalyticsUmeng::REALTIME);
}
/*
if (pFlurry != NULL)
{
pFlurry->setReportLocation(true);
pFlurry->logPageView();
// const char* sdkVersion = pFlurry->getSDKVersion();
pFlurry->setVersionName("1.1");
pFlurry->setAge(20);
pFlurry->setGender(AnalyticsFlurry::MALE);
pFlurry->setUserId("123456");
pFlurry->setUseHttps(false);
}*/
#endif
CCLog("before to load lua file");
CCLog("platform ");
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
CCLog("before android add search path");
//pEngine->addSearchPath((CCFileUtils::sharedFileUtils()->getWritablePath() + "script/").c_str());
//CCFileUtils::sharedFileUtils()->addSearchPath((CCFileUtils::sharedFileUtils()->getWritablePath() + "script/").c_str());
CCString* pstrFileContent = CCString::createWithContentsOfFile("Entry");
CCLOG("%s","read script from phone memory");
pEngine->executeString(pstrFileContent->getCString());
#elif (CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_MAC)
CCLuaStack *pStack = pEngine->getLuaStack();
lua_State *tolua_s = pStack->getLuaState();
tolua_AppstorePurchase_open(tolua_s);
std::string path = CCFileUtils::sharedFileUtils()->fullPathForFilename("Entry");
pEngine->addSearchPath(path.substr(0, path.find_last_of("/")).c_str());
CCString* pstrFileContent = CCString::createWithContentsOfFile("Entry");
pEngine->executeString(pstrFileContent->getCString());
#else
std::string path = CCFileUtils::sharedFileUtils()->fullPathForFilename("Entry");
pEngine->addSearchPath(path.substr(0, path.find_last_of("/")).c_str());
CCString* pstrFileContent = CCString::createWithContentsOfFile("Entry");
const char * res = pstrFileContent->getCString();
int len = strlen(res);
int remain_len = len % 8;
int desSize = len+1;
if(remain_len>0){
desSize += 8 - remain_len;
}
unsigned char* des = (unsigned char*)malloc(desSize*sizeof(unsigned char));
//加密脚本
file_encrypt(res,des,desSize);
pEngine->executeString(file_decrypt(des,desSize));//解密脚本
//unsigned long desSize = 0;
//unsigned char * enc = CCFileUtils::sharedFileUtils()->getFileData(path.c_str(), "rb", &desSize);
//char * res = file_decrypt(enc,desSize);
//.........这里部分代码省略.........