本文整理汇总了C++中CCLuaEngine类的典型用法代码示例。如果您正苦于以下问题:C++ CCLuaEngine类的具体用法?C++ CCLuaEngine怎么用?C++ CCLuaEngine使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CCLuaEngine类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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);
// 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
return true;
}
示例2: if
bool AppDelegate::applicationDidFinishLaunching()
{
// initialize director
CCDirector *pDirector = CCDirector::sharedDirector();
CCEGLView* pEGLView = CCEGLView::sharedOpenGLView();
pDirector->setOpenGLView(pEGLView);
CCSize frameSize = pEGLView->getFrameSize();
pEGLView->setDesignResolutionSize(designResolutionSize.width, designResolutionSize.height, kResolutionExactFit);
if (frameSize.height > mediumResource.size.height)
{
pDirector->setContentScaleFactor(MIN(smallResource.size.height/designResolutionSize.height, smallResource.size.width/designResolutionSize.width));
}
// if the frame's height is larger than the height of small resource size, select medium resource.
else if (frameSize.height > smallResource.size.height)
{
pDirector->setContentScaleFactor(MIN(smallResource.size.height/designResolutionSize.height, smallResource.size.width/designResolutionSize.width));
}
// if the frame's height is smaller than the height of medium resource size, select small resource.
else
{
pDirector->setContentScaleFactor(MIN(smallResource.size.height/designResolutionSize.height, smallResource.size.width/designResolutionSize.width));
}
// 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);
CCLuaStack *pStack = pEngine->getLuaStack();
lua_State *tolua_s = pStack->getLuaState();
tolua_extensions_ccb_open(tolua_s);
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
pStack = pEngine->getLuaStack();
tolua_s = pStack->getLuaState();
tolua_web_socket_open(tolua_s);
#endif
#if (CC_TARGET_PLATFORM == CC_PLATFORM_BLACKBERRY)
CCFileUtils::sharedFileUtils()->addSearchPath("script");
#endif
std::string path = CCFileUtils::sharedFileUtils()->fullPathForFilename("scripts/main.lua");
pEngine->addSearchPath(path.substr(0, path.find_last_of('/')).c_str());
pEngine->executeScriptFile(path.c_str());
return true;
}
示例3: setPackagePath
void LuaUtil::setPackagePath(const std::string &path)
{
CCLuaEngine* pEngine = CCLuaEngine::defaultEngine();
lua_State* m_state=pEngine->getLuaStack()->getLuaState();
lua_getglobal(m_state, "package"); /* L: package */
lua_pushstring(m_state, path.c_str()); /* L: package newpath */
lua_setfield(m_state, -2, "path"); /* package.path = newpath, L: package */
lua_pop(m_state, 1); /* L: - */
}
示例4: API_LoadLuaFile
// 加载LUA脚本
void API_LoadLuaFile( char *szLUAFileName)
{
CCLOG("API_LoadLuaFile = %s",szLUAFileName);
CCLuaEngine* pEngine = CCLuaEngine::defaultEngine();
std::string path = CCFileUtils::sharedFileUtils()->fullPathForFilename(szLUAFileName);
pEngine->executeScriptFile(path.c_str());
}
示例5: getPackagePath
const char* LuaUtil::getPackagePath()
{
CCLuaEngine* pEngine = CCLuaEngine::defaultEngine();
lua_State* m_state=pEngine->getLuaStack()->getLuaState();
lua_getglobal(m_state, "package"); /* L: package */
lua_getfield(m_state, -1, "path"); /* get package.path, L: package path */
std::string path = lua_tostring(m_state, -1);
lua_pop(m_state, 1);
return CCString::create(path)->getCString();
}
示例6: executeLua
int LuaEngineUtils::executeLua(const char *luaFileName)
{
CCLuaEngine* pEngine = CCLuaEngine::defaultEngine();
if(!sm_bInited){
sm_bInited = true;
// register lua engine
CCScriptEngineManager::sharedManager()->setScriptEngine(pEngine);
}
return pEngine->executeScriptFile(luaFileName);
}
示例7: 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;
}
示例8: eventCallbackFunc
void LuaCocoStudioEventListener::eventCallbackFunc(CCObject* sender,int eventType)
{
if (0 != m_lHandler)
{
CCLuaEngine* pEngine = CCLuaEngine::defaultEngine();
CCLuaStack* pStack = pEngine->getLuaStack();
pStack->pushCCObject(sender, "CCObject");
pStack->pushInt(eventType);
pStack->executeFunctionByHandler(m_lHandler, 2);
pStack->clean();
}
}
示例9: addArmatureFileInfoAsyncCallback
void LuaArmatureWrapper::addArmatureFileInfoAsyncCallback(float percent)
{
if (0 != m_lHandler)
{
CCLuaEngine* pEngine = CCLuaEngine::defaultEngine();
CCLuaStack* pStack = pEngine->getLuaStack();
pStack->pushFloat(percent);
pStack->executeFunctionByHandler(m_lHandler, 1);
pStack->clean();
}
}
示例10: CCLog
bool CCWebView::shouldLoadUrl(const char *url){
if(this->m_luaHandler != 0){
CCLog("load url");
CCLuaEngine *engine = CCLuaEngine::defaultEngine();
engine->getLuaStack()->clean();
engine->getLuaStack()->pushString(url);
int ret = engine->getLuaStack()->executeFunctionByHandler(this->m_luaHandler, 1);
CCLog("check url finish");
return ret==1;
}
return true;
}
示例11: 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());
}
示例12: 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
}
示例13: movementEventCallback
void LuaArmatureWrapper::movementEventCallback(CCArmature* armature, MovementEventType type,const char* movementID)
{
if (0 != m_lHandler)
{
CCLuaEngine* pEngine = CCLuaEngine::defaultEngine();
CCLuaStack* pStack = pEngine->getLuaStack();
pStack->pushCCObject(armature, "CCArmature");
pStack->pushInt(type);
pStack->pushString(movementID);
pStack->executeFunctionByHandler(m_lHandler, 3);
pStack->clean();
}
}
示例14: if
CWidgetTouchModel CWidget::executeTouchBeganHandler(CCTouch* pTouch)
{
m_bTouchInterrupt = false;
if( m_pTouchBeganListener && m_pTouchBeganHandler )
{
CWidgetTouchModel eUserTouchModel = (m_pTouchBeganListener->*m_pTouchBeganHandler)(m_pThisObject, pTouch);
if( eUserTouchModel == eWidgetTouchNone )
{
return eWidgetTouchNone;
}
else
{
this->onTouchBegan(pTouch);
return eUserTouchModel;
}
}
#if USING_LUA
else if( m_nTouchBeganScriptHandler != 0 )
{
CCLuaEngine* pEngine = CCLuaEngine::defaultEngine();
CCLuaStack* pStack = pEngine->getLuaStack();
pStack->pushCCObject(m_pThisObject, "CCObject");
pStack->pushCCObject(pTouch, "CCTouch");
CCArray* pRetArray = new CCArray();
pRetArray->initWithCapacity(1);
int nRet = pStack->executeFunctionReturnArray(m_nTouchBeganScriptHandler, 2, 1, pRetArray);
CCAssert(pRetArray->count() > 0, "return count = 0");
CCDouble* pIntModel = (CCDouble*) pRetArray->objectAtIndex(0);
CWidgetTouchModel eUserTouchModel = (CWidgetTouchModel) ( (int)pIntModel->getValue() );
delete pRetArray;
pStack->clean();
if( eUserTouchModel == eWidgetTouchNone )
{
return eWidgetTouchNone;
}
else
{
this->onTouchBegan(pTouch);
return eUserTouchModel;
}
}
#endif
return this->onTouchBegan(pTouch);
}
示例15: CCLOG
bool AppDelegate::applicationDidFinishLaunching()
{
// initialize director
CCDirector *pDirector = CCDirector::sharedDirector();
pDirector->setOpenGLView(CCEGLView::sharedOpenGLView());
// CCEGLView::sharedOpenGLView()->setDesignResolutionSize(480, 320, kResolutionNoBorder);
// 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 / GAME_FPS);
StringVector kSearchPaths;
StringVector kOrders;
if (!initSearchPaths(kSearchPaths))
{
CCLOG("Initialise searching path failed!");
return false;
}
if (false == autoSizeMachineResolutions(kOrders))
{
return false;
}
CCFileUtils::sharedFileUtils()->setSearchResolutionsOrder(kOrders);
pDirector->setContentScaleFactor(
m_kResourceSize.width / m_kDesignSize.width);
// register lua engine
CCLuaEngine* pEngine = CCLuaEngine::defaultEngine();
CCLuaStack *pStack = pEngine->getLuaStack();
lua_State *tolua_s = pStack->getLuaState();
tolua_extensions_ccb_open(tolua_s);
CCScriptEngineManager::sharedManager()->setScriptEngine(pEngine);
CCFileUtils::sharedFileUtils()->setSearchPaths(kSearchPaths);
std::string strLuaPath = CCFileUtils::sharedFileUtils()->fullPathForFilename(
ENTRY_LUA_FUNC);
CCLOG("Will exceute %s\n",strLuaPath.c_str());
pEngine->executeScriptFile(strLuaPath.c_str());
return true;
}