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); }); }
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; }
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); } } } } }
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); }
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 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); }
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); }
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); }
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); }
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); }
static int lua_cocos2dx_RadioButtonGroup_addEventListener(lua_State* L) { if (nullptr == L) return 0; int argc = 0; RadioButtonGroup* self = nullptr; #if COCOS2D_DEBUG >= 1 tolua_Error tolua_err; if (!tolua_isusertype(L,1,"ccui.RadioButtonGroup",0,&tolua_err)) goto tolua_lerror; #endif self = static_cast<RadioButtonGroup*>(tolua_tousertype(L,1,0)); #if COCOS2D_DEBUG >= 1 if (nullptr == self) { tolua_error(L,"invalid 'self' in function 'lua_cocos2dx_RadioButtonGroup_addEventListener'\n", NULL); return 0; } #endif argc = lua_gettop(L) - 1; if (1 == argc) { #if COCOS2D_DEBUG >= 1 if (!toluafix_isfunction(L,2,"LUA_FUNCTION",0,&tolua_err)) { goto tolua_lerror; } #endif LUA_FUNCTION handler = ( toluafix_ref_function(L,2,0)); self->addEventListener([=](RadioButton* radioButton,int index,RadioButtonGroup::EventType eventType){ LuaStack* stack = LuaEngine::getInstance()->getLuaStack(); stack->pushObject(radioButton, "ccui.RadioButton"); stack->pushInt(index); stack->pushInt((int)eventType); stack->executeFunctionByHandler(handler, 3); stack->clean(); }); ScriptHandlerMgr::getInstance()->addCustomHandler((void*)self, handler); return 0; } luaL_error(L, "'addEventListener' function of RadioButtonGroup has wrong number of arguments: %d, was expecting %d\n", argc, 1); return 0; #if COCOS2D_DEBUG >= 1 tolua_lerror: tolua_error(L,"#ferror in function 'addEventListener'.",&tolua_err); return 0; #endif }
void onGetUserInfo( const sdkbox::FBGraphUser& user ) { LuaStack* stack = LUAENGINE->getLuaStack(); LuaValueDict dict; dict.insert(std::make_pair("name", LuaValue::stringValue("onGetUserInfo"))); dict.insert(std::make_pair("data", FBGraphUserToLua(user))); 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); }
void onProductRequestSuccess(const std::vector<sdkbox::Product>& products) { LuaStack* stack = LUAENGINE->getLuaStack(); LuaValueDict dict; dict.insert(std::make_pair("event", LuaValue::stringValue("onProductRequestSuccess"))); dict.insert(std::make_pair("products", proucts2LuaValue(products))); stack->pushLuaValueDict(dict); stack->executeFunctionByHandler(mLuaHandler, 1); }
void onSharedCancel() { LuaStack* stack = LUAENGINE->getLuaStack(); LuaValueDict dict; dict.insert(std::make_pair("name", LuaValue::stringValue("onSharedCancel"))); dict.insert(std::make_pair("data", LuaValue::stringValue("{}"))); 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); }
void invokeLuaHandler(const char* func, const char* name) { LuaStack* stack = LUAENGINE->getLuaStack(); LuaValueDict dict; dict.insert(std::make_pair("func", LuaValue::stringValue(func))); if (nullptr != name) { dict.insert(std::make_pair("name", LuaValue::stringValue(name))); } 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); }
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 onSharedFailed(const std::string& message) { LuaStack* stack = LUAENGINE->getLuaStack(); LuaValueDict dict; dict.insert(std::make_pair("name", LuaValue::stringValue("onSharedFailed"))); dict.insert(std::make_pair("data", LuaValue::stringValue(message))); stack->pushLuaValueDict(dict); stack->executeFunctionByHandler(mLuaHandler, 1); }
static int lua_cocos2dx_Widget_addClickEventListener(lua_State* L) { if (nullptr == L) return 0; int argc = 0; Widget* self = nullptr; #if COCOS2D_DEBUG >= 1 tolua_Error tolua_err; if (!tolua_isusertype(L,1,"ccui.Widget",0,&tolua_err)) goto tolua_lerror; #endif self = static_cast<Widget*>(tolua_tousertype(L,1,0)); #if COCOS2D_DEBUG >= 1 if (nullptr == self) { tolua_error(L,"invalid 'self' in function 'lua_cocos2dx_Widget_addClickEventListener'\n", NULL); return 0; } #endif argc = lua_gettop(L) - 1; if (1 == argc) { #if COCOS2D_DEBUG >= 1 if (!toluafix_isfunction(L,2,"LUA_FUNCTION",0,&tolua_err)) { goto tolua_lerror; } #endif LUA_FUNCTION handler = ( toluafix_ref_function(L,2,0)); self->addClickEventListener([=](cocos2d::Ref* sender){ LuaStack* stack = LuaEngine::getInstance()->getLuaStack(); stack->pushObject(sender, "cc.Ref"); stack->executeFunctionByHandler(handler, 1); stack->clean(); }); ScriptHandlerMgr::getInstance()->addCustomHandler((void*)self, handler); return 0; } luaL_error(L, "'addClickEventListener' function of Widget has wrong number of arguments: %d, was expecting %d\n", argc, 1); return 0; #if COCOS2D_DEBUG >= 1 tolua_lerror: tolua_error(L,"#ferror in function 'addClickEventListener'.",&tolua_err); return 0; #endif }
virtual void onAchievementUnlockError( const std::string& achievement_name, int error_code, const std::string& error_description ) { LuaStack* stack = LUAENGINE->getLuaStack(); LuaValueDict dict; dict.insert(std::make_pair("name", LuaValue::stringValue(__FUNCTION__))); dict.insert(std::make_pair("achievement_name", LuaValue::stringValue(achievement_name))); dict.insert(std::make_pair("error_code", LuaValue::intValue(error_code))); dict.insert(std::make_pair("error_description", LuaValue::stringValue(error_description))); stack->pushLuaValueDict(dict); stack->executeFunctionByHandler(mLuaHandler, 1); }
void onRequestOpenURL(const char *placement, const char *URL) { LuaStack* stack = LUAENGINE->getLuaStack(); LuaValueDict dict; dict.insert(std::make_pair("event", LuaValue::stringValue("onRequestOpenURL"))); dict.insert(std::make_pair("placement", LuaValue::stringValue(placement))); dict.insert(std::make_pair("URL", LuaValue::stringValue(URL))); stack->pushLuaValueDict(dict); stack->executeFunctionByHandler(mLuaHandler, 1); }
int lua_game_manager_Http_get(lua_State* tolua_S) { int argc = 0; bool ok = true; #if COCOS2D_DEBUG >= 1 tolua_Error tolua_err; #endif game::manager::Http* cobj = (game::manager::Http*)tolua_tousertype(tolua_S,1,0); #if COCOS2D_DEBUG >= 1 //if (!tolua_isusertable(tolua_S,1,"game.manager.Http",0,&tolua_err)) goto tolua_lerror; #endif argc = lua_gettop(tolua_S) - 1; if (argc >= 1) { if(!ok) { tolua_error(tolua_S,"invalid arguments in function 'lua_game_manager_Http_get'", nullptr); return 0; } std::string url,postData; ok &= luaval_to_std_string(tolua_S, 2,&url, "game.manager.Http"); if(argc >= 2) { ok &= luaval_to_std_string(tolua_S, 3,&postData, "game.manager.Http"); } RequestCompleteCallBack completeCallback = nullptr; if (argc >= 3) { LUA_FUNCTION handler = ( toluafix_ref_function(tolua_S,4,0)); completeCallback = [=](const char* szBuffer){ LuaStack* stack = LuaEngine::getInstance()->getLuaStack(); stack->pushString(szBuffer); stack->executeFunctionByHandler(handler, 1); stack->clean(); }; } cobj->get(url,postData,completeCallback); return 1; } luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d\n ", "cc.Node:create",argc, 0); return 0; #if COCOS2D_DEBUG >= 1 tolua_lerror: tolua_error(tolua_S,"#ferror in function 'lua_game_manager_Http_get'.",&tolua_err); #endif return 0; }
virtual void onAdAction( const std::string& ad_unit_id, const std::string& zone_place_location, sdkbox::AdActionType action_type) { LuaStack* stack = LUAENGINE->getLuaStack(); LuaValueDict dict; dict.insert(std::make_pair("name", LuaValue::stringValue("onAdAction"))); dict.insert(std::make_pair("ad_unit_id", LuaValue::stringValue(ad_unit_id))); dict.insert(std::make_pair("ad_name", LuaValue::stringValue(zone_place_location))); dict.insert(std::make_pair("ad_action_type", LuaValue::intValue((int)action_type))); stack->pushLuaValueDict(dict); stack->executeFunctionByHandler(mLuaHandler, 1); }
virtual void onRevealError( const std::string& reveal_name, int error_code, const std::string& error_description ) { LuaStack* stack = LUAENGINE->getLuaStack(); LuaValueDict dict; dict.insert(std::make_pair("name", LuaValue::stringValue("onRevealError"))); dict.insert(std::make_pair("reveal_name", LuaValue::stringValue(reveal_name))); dict.insert(std::make_pair("error_code", LuaValue::intValue(error_code))); dict.insert(std::make_pair("error_description", LuaValue::stringValue(error_description))); stack->pushLuaValueDict(dict); stack->executeFunctionByHandler(mLuaHandler, 1); }