cocos2d::LUA_STRING Crypto::cryptAES256Lua(bool isDecrypt, const char* input, int inputLength, const char* key, int keyLength) { LuaStack* stack = LuaEngine::getInstance()->getLuaStack(); stack->clean(); if (getAES256KeyLength() == 0) { stack->pushNil(); return 1; } int bufferSize = inputLength + getAES256KeyLength(); void* buffer = malloc(bufferSize); int dataUsed = cryptAES256(isDecrypt, (unsigned char*)input, inputLength, (unsigned char*)buffer, bufferSize, (unsigned char*)key, keyLength); if (dataUsed > 0) { stack->pushString(static_cast<const char*>(buffer), dataUsed); } else { stack->pushNil(); } free(buffer); return 1; }
LuaStack *LuaStack::attach(lua_State *L) { LuaStack *stack = new LuaStack(); stack->initWithLuaState(L); stack->autorelease(); return stack; }
bool AppDelegate::applicationDidFinishLaunching() { // initialize director auto pDirector = Director::getInstance(); pDirector->setOpenGLView(EGLView::getInstance()); // 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); auto screenSize = EGLView::getInstance()->getFrameSize(); auto designSize = Size(480, 320); auto pFileUtils = FileUtils::getInstance(); if (screenSize.height > 320) { auto resourceSize = Size(960, 640); std::vector<std::string> searchPaths; searchPaths.push_back("hd"); pFileUtils->setSearchPaths(searchPaths); pDirector->setContentScaleFactor(resourceSize.height/designSize.height); } EGLView::getInstance()->setDesignResolutionSize(designSize.width, designSize.height, ResolutionPolicy::FIXED_HEIGHT); // register lua engine LuaEngine* pEngine = LuaEngine::getInstance(); ScriptEngineManager::getInstance()->setScriptEngine(pEngine); #if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 || CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID ||CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_MAC) LuaStack* stack = pEngine->getLuaStack(); register_assetsmanager_test_sample(stack->getLuaState()); #endif std::vector<std::string> searchPaths = pFileUtils->getSearchPaths(); searchPaths.insert(searchPaths.begin(), "Images"); searchPaths.insert(searchPaths.begin(), "cocosbuilderRes"); if (screenSize.height > 320) { searchPaths.insert(searchPaths.begin(), "hd/scenetest/LoadSceneEdtiorFileTest"); } else { searchPaths.insert(searchPaths.begin(), "scenetest/LoadSceneEdtiorFileTest"); } #if CC_TARGET_PLATFORM == CC_PLATFORM_BLACKBERRY searchPaths.push_back("TestCppResources"); searchPaths.push_back("script"); #endif FileUtils::getInstance()->setSearchPaths(searchPaths); pEngine->executeScriptFile("luaScript/controller.lua"); return true; }
void flurrySessionDidCreateWithInfo(std::map<std::string, std::string>& info) { std::string jsonStr = map2JsonString(info); LuaStack* stack = LUAENGINE->getLuaStack(); stack->pushString(jsonStr.c_str()); stack->executeFunctionByHandler(mLuaHandler, 1); }
static int SendBinaryMessageToLua(int nHandler,const unsigned char* pTable,int nLength) { if (NULL == pTable || nHandler <= 0) { return 0; } if (NULL == ScriptEngineManager::getInstance()->getScriptEngine()) { return 0; } LuaStack *pStack = LuaEngine::getInstance()->getLuaStack(); if (NULL == pStack) { return 0; } lua_State *tolua_s = pStack->getLuaState(); if (NULL == tolua_s) { return 0; } int nRet = 0; LuaValueArray array; for (int i = 0 ; i < nLength; i++) { LuaValue value = LuaValue::intValue(pTable[i]); array.push_back(value); } pStack->pushLuaValueArray(array); nRet = pStack->executeFunctionByHandler(nHandler, 1); pStack->clean(); return nRet; }
int lua_ActionGroup_callFunc(lua_State* L) { return cclua::obj_call(L, [=](ActionGroup* g, cclua::Index refIdx) { LUA_FUNCTION handler = toluafix_ref_function(L, refIdx.val, 0); auto mgr = ScriptHandlerMgr::getInstance(); auto type = (ScriptHandlerMgr::HandlerType)( (int)ScriptHandlerMgr::HandlerType::CALLFUNC + g->numberOfCallFunc()); if (0 == mgr->getObjectHandler(g, type)) { mgr->addObjectHandler(g, handler, type); auto func = [=]() { LUA_FUNCTION handler = mgr->getObjectHandler(g, type); if (0 != handler) { LuaStack* stack = LuaEngine::getInstance()->getLuaStack(); stack->executeFunctionByHandler(handler, 0); } }; g->callFunc(func); } return lua_pushActionGroup(L, g); }); }
bool AppDelegate::applicationDidFinishLaunching() { // set default FPS Director::getInstance()->setAnimationInterval(1.0 / 60.0f); // register lua module auto engine = LuaEngine::getInstance(); ScriptEngineManager::getInstance()->setScriptEngine(engine); lua_State* L = engine->getLuaStack()->getLuaState(); lua_module_register(L); register_all_packages(); LuaStack* stack = engine->getLuaStack(); stack->setXXTEAKeyAndSign("2dxLua", strlen("2dxLua"), "XXTEA", strlen("XXTEA")); //register custom function //LuaStack* stack = engine->getLuaStack(); //register_custom_function(stack->getLuaState()); #if CC_64BITS FileUtils::getInstance()->addSearchPath("src/64bit"); #endif FileUtils::getInstance()->addSearchPath("src"); FileUtils::getInstance()->addSearchPath("res"); if (engine->executeScriptFile("main.lua")) { return false; } return true; }
void LuaWebSocket::onMessage(WebSocket* ws, const WebSocket::Data& data) { LuaWebSocket* luaWs = dynamic_cast<LuaWebSocket*>(ws); if (NULL != luaWs) { if (data.isBinary) { int handler = ScriptHandlerMgr::getInstance()->getObjectHandler((void*)this,ScriptHandlerMgr::HandlerType::WEBSOCKET_MESSAGE); if (0 != handler) { SendBinaryMessageToLua(handler, (const unsigned char*)data.bytes, (int)data.len); } } else{ int handler = ScriptHandlerMgr::getInstance()->getObjectHandler((void*)this,ScriptHandlerMgr::HandlerType::WEBSOCKET_MESSAGE); if (0 != handler) { LuaStack* stack = LuaEngine::getInstance()->getLuaStack(); if (nullptr != stack) { stack->pushString(data.bytes,(int)data.len); stack->executeFunctionByHandler(handler, 1); } } } } }
LuaStack *LuaStack::create(void) { LuaStack *stack = new (std::nothrow) LuaStack(); stack->init(); stack->autorelease(); return stack; }
LuaStack *LuaStack::create(void) { LuaStack *stack = new LuaStack(); stack->init(); stack->autorelease(); return stack; }
bool AppDelegate::applicationDidFinishLaunching() { // register lua engine LuaEngine* pEngine = LuaEngine::getInstance(); ScriptEngineManager::getInstance()->setScriptEngine(pEngine); LuaStack* stack = pEngine->getLuaStack(); stack->setXXTEAKeyAndSign("2dxLua", strlen("2dxLua"), "XXTEA", strlen("XXTEA")); lua_State* L = stack->getLuaState(); lua_module_register(L); lua_getglobal(L, "_G"); if (lua_istable(L,-1))//stack:...,_G, { #if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 || CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID ||CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_MAC) register_assetsmanager_test_sample(L); #endif register_test_binding(L); } lua_pop(L, 1); pEngine->executeScriptFile("src/controller.lua"); return true; }
bool AppDelegate::applicationDidFinishLaunching() { // set default FPS Director::getInstance()->setAnimationInterval(1.0 / 60.0f); // register lua module auto engine = LuaEngine::getInstance(); ScriptEngineManager::getInstance()->setScriptEngine(engine); lua_State* L = engine->getLuaStack()->getLuaState(); lua_module_register(L); register_all_packages(); LuaStack* stack = engine->getLuaStack(); stack->setXXTEAKeyAndSign("2dxLua", strlen("2dxLua"), "XXTEA", strlen("XXTEA")); #if (COCOS2D_DEBUG > 0) && (CC_CODE_IDE_DEBUG_SUPPORT > 0) // NOTE:Please don't remove this call if you want to debug with Cocos Code IDE auto runtimeEngine = RuntimeEngine::getInstance(); runtimeEngine->addRuntime(RuntimeLuaImpl::create(), kRuntimeEngineLua); runtimeEngine->start(); #else if (engine->executeScriptFile("src/main.lua")) { return false; } #endif return true; }
LUA_STRING Crypto::encodingBase64Lua(bool isDecoding, const char* input, int inputLength) { LuaStack* stack = LuaEngine::getInstance()->getLuaStack(); stack->clean(); int bufferSize = isDecoding ? Base64decode_len(input) : Base64encode_len(inputLength); char *buffer = bufferSize ? (char*)malloc(bufferSize) : NULL; int size = 0; if (buffer) { size = isDecoding ? Base64decode(buffer, input) : Base64encode(buffer, input, inputLength); } if (size) { stack->pushString(buffer, size); } else { stack->pushNil(); } if (buffer) { free(buffer); } return 1; }
bool AppDelegate::applicationDidFinishLaunching() { //#if (COCOS2D_DEBUG>0) // initRuntime(); //#endif if (!ConfigParser::getInstance()->isInit()) { ConfigParser::getInstance()->readConfig(); } // initialize director auto director = Director::getInstance(); auto glview = director->getOpenGLView(); if(!glview) { Size viewSize = ConfigParser::getInstance()->getInitViewSize(); string title = ConfigParser::getInstance()->getInitViewName(); #if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 || CC_TARGET_PLATFORM == CC_PLATFORM_MAC) extern void createSimulator(const char* viewName, float width, float height,bool isLandscape = true, float frameZoomFactor = 1.0f); bool isLanscape = ConfigParser::getInstance()->isLanscape(); createSimulator(title.c_str(),viewSize.width,viewSize.height,isLanscape); #else glview = GLView::createWithRect(title.c_str(), Rect(0,0,viewSize.width,viewSize.height)); director->setOpenGLView(glview); #endif } // turn on display FPS director->setDisplayStats(false); // set FPS. the default value is 1.0/60 if you don't call this director->setAnimationInterval(1.0 / 60); auto engine = LuaEngine::getInstance(); ScriptEngineManager::getInstance()->setScriptEngine(engine); //register custom function //LuaStack* stack = engine->getLuaStack(); //register_custom_function(stack->getLuaState()); LuaStack* stack = engine->getLuaStack(); register_all_custom_manual(stack->getLuaState()); auto backListener = EventListenerKeyboard::create(); backListener->onKeyReleased = [=](EventKeyboard::KeyCode code, Event* event) { if (code == EventKeyboard::KeyCode::KEY_BACKSPACE) { director->end(); } }; director->getEventDispatcher()->addEventListenerWithFixedPriority(backListener, -1000); //#if (COCOS2D_DEBUG>0) // if (startRuntime()) // return true; //#endif CCLOG("%s",ConfigParser::getInstance()->getEntryFile().c_str()); engine->executeScriptFile(ConfigParser::getInstance()->getEntryFile().c_str()); return true; }
int Font::height(LuaStack& stack) const { int width = INT_MAX; if (stack.size() == 2 && !stack.isNil(2)) { width = stack.as<int>(2); } return height(stack.as<QString>(1), width); }
void MovieView::executeCallBack(int nHandle) { LuaEngine* pEngine = LuaEngine::getInstance(); LuaStack* pStack = pEngine->getLuaStack(); int nRet = pStack->executeFunctionByHandler(nHandle, 0); pStack->clean(); }
void onChartboostReward(const std::string& name, int reward) { LuaStack* stack = LUAENGINE->getLuaStack(); LuaValueDict dict; dict.insert(std::make_pair("func", LuaValue::stringValue("onChartboostReward"))); dict.insert(std::make_pair("name", LuaValue::stringValue(name))); dict.insert(std::make_pair("reward", LuaValue::intValue(reward))); stack->pushLuaValueDict(dict); stack->executeFunctionByHandler(mLuaHandler, 1); }
void onRestored(const sdkbox::Product& p) { LuaStack* stack = LUAENGINE->getLuaStack(); LuaValueDict dict; dict.insert(std::make_pair("event", LuaValue::stringValue("onRestored"))); dict.insert(std::make_pair("product", prouct2LuaValue(p))); stack->pushLuaValueDict(dict); stack->executeFunctionByHandler(mLuaHandler, 1); }
void onProductRequestFailure(const std::string& msg) { LuaStack* stack = LUAENGINE->getLuaStack(); LuaValueDict dict; dict.insert(std::make_pair("event", LuaValue::stringValue("onProductRequestFailure"))); dict.insert(std::make_pair("msg", LuaValue::stringValue(msg))); stack->pushLuaValueDict(dict); stack->executeFunctionByHandler(mLuaHandler, 1); }
void onInitialized(bool ok) { LuaStack* stack = LUAENGINE->getLuaStack(); LuaValueDict dict; dict.insert(std::make_pair("event", LuaValue::stringValue("onInitialized"))); dict.insert(std::make_pair("ok", LuaValue::booleanValue(ok))); stack->pushLuaValueDict(dict); stack->executeFunctionByHandler(mLuaHandler, 1); }
virtual void onConnectionStatusChanged( int status ) { LuaStack* stack = LUAENGINE->getLuaStack(); LuaValueDict dict; dict.insert(std::make_pair("name", LuaValue::stringValue("onConnectionStatusChanged"))); dict.insert(std::make_pair("status", LuaValue::intValue((int)status))); stack->pushLuaValueDict(dict); stack->executeFunctionByHandler(mLuaHandler, 1); }
virtual void onReveal( const std::string& reveal_name) { LuaStack* stack = LUAENGINE->getLuaStack(); LuaValueDict dict; dict.insert(std::make_pair("name", LuaValue::stringValue("onReveal"))); dict.insert(std::make_pair("reveal_name", LuaValue::stringValue(reveal_name))); stack->pushLuaValueDict(dict); stack->executeFunctionByHandler(mLuaHandler, 1); }
void onChartboostFailToRecordClick(const std::string& name, sdkbox::CB_ClickError e) { LuaStack* stack = LUAENGINE->getLuaStack(); LuaValueDict dict; dict.insert(std::make_pair("func", LuaValue::stringValue("onChartboostFailToRecordClick"))); dict.insert(std::make_pair("name", LuaValue::stringValue(name))); dict.insert(std::make_pair("e", LuaValue::intValue(e))); stack->pushLuaValueDict(dict); stack->executeFunctionByHandler(mLuaHandler, 1); }
void onCloseInterstitial(const char *placement) { LuaStack* stack = LUAENGINE->getLuaStack(); LuaValueDict dict; dict.insert(std::make_pair("event", LuaValue::stringValue("onCloseInterstitial"))); dict.insert(std::make_pair("placement", LuaValue::stringValue(placement))); stack->pushLuaValueDict(dict); stack->executeFunctionByHandler(mLuaHandler, 1); }
void onPlayEnds(bool played_ok) { LuaStack* stack = LUAENGINE->getLuaStack(); LuaValueDict dict; dict.insert(std::make_pair("name", LuaValue::stringValue("onPlayEnds"))); dict.insert(std::make_pair("played_ok", LuaValue::booleanValue(played_ok))); stack->pushLuaValueDict(dict); stack->executeFunctionByHandler(mLuaHandler, 1); }
virtual void onSaveGameData(bool success, const std::string& error) { LuaStack* stack = LUAENGINE->getLuaStack(); LuaValueDict dict; dict.insert(std::make_pair("name", LuaValue::stringValue("onSaveGameData"))); dict.insert(std::make_pair("success", LuaValue::booleanValue(success))); dict.insert(std::make_pair("error", LuaValue::stringValue(error))); stack->pushLuaValueDict(dict); stack->executeFunctionByHandler(mLuaHandler, 1); }
virtual void onSetSteps( const std::string& step_name, double steps ) { LuaStack* stack = LUAENGINE->getLuaStack(); LuaValueDict dict; dict.insert(std::make_pair("name", LuaValue::stringValue("onSetSteps"))); dict.insert(std::make_pair("step_name", LuaValue::stringValue(step_name))); dict.insert(std::make_pair("steps", LuaValue::floatValue(steps))); stack->pushLuaValueDict(dict); stack->executeFunctionByHandler(mLuaHandler, 1); }
virtual void onAchievementsLoaded( bool reload_forced, const std::string& json_achievements_info ) { LuaStack* stack = LUAENGINE->getLuaStack(); LuaValueDict dict; dict.insert(std::make_pair("name", LuaValue::stringValue("onAchievementsLoaded"))); dict.insert(std::make_pair("reload_forced", LuaValue::booleanValue(reload_forced))); dict.insert(std::make_pair("json_achievements_info", LuaValue::stringValue(json_achievements_info))); stack->pushLuaValueDict(dict); stack->executeFunctionByHandler(mLuaHandler, 1); }
virtual void onIncrementalAchievementUnlocked( const std::string& achievement_name ) { LuaStack* stack = LUAENGINE->getLuaStack(); LuaValueDict dict; dict.insert(std::make_pair("name", LuaValue::stringValue("onIncrementalAchievementUnlocked"))); dict.insert(std::make_pair("achievement_name", LuaValue::stringValue(achievement_name))); stack->pushLuaValueDict(dict); stack->executeFunctionByHandler(mLuaHandler, 1); }
Ref* CustomGUIReader::createInstance() { Ref* result = nullptr; LuaStack* stack = LuaEngine::getInstance()->getLuaStack(); stack->executeFunction(_createFunc, 0, 1, [&result](lua_State* L,int numReturn){ result = static_cast<Ref*>(tolua_tousertype(L, -1, nullptr)); lua_pop(L, 1); }); return result; }