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 }
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 }
static int handleUIEvent(int handler, cocos2d::Ref* sender, int eventType) { LuaStack* stack = LuaEngine::getInstance()->getLuaStack(); stack->pushObject(sender, "cc.Ref"); stack->pushInt(eventType); stack->executeFunctionByHandler(handler, 2); stack->clean(); return 0; }
void CWidgetWindow::executeTouchCancelledAfterLongClickHandler(Ref* pSender, Touch *pTouch, float fDuration) { if( m_pTouchCancelledAfterLongClickListener && m_pTouchCancelledAfterLongClickHandler ) { (m_pTouchCancelledAfterLongClickListener->*m_pTouchCancelledAfterLongClickHandler)(pSender, pTouch, fDuration); } #if USING_LUA else if( m_pTouchCancelledAfterLongClickScriptHandler != 0 ) { LuaEngine* pEngine = LuaEngine::getInstance(); LuaStack* pStack = pEngine->getLuaStack(); pStack->pushObject(pSender, "Ref"); pStack->pushObject(pTouch, "Touch"); pStack->pushFloat(fDuration); int nRet = pStack->executeFunctionByHandler(m_pTouchCancelledAfterLongClickScriptHandler, 3); pStack->clean(); } #endif }
static int lua_cocos2dx_experimental_video_VideoPlayer_addEventListener(lua_State* L) { int argc = 0; cocos2d::experimental::ui::VideoPlayer* self = nullptr; #if COCOS2D_DEBUG >= 1 tolua_Error tolua_err; if (!tolua_isusertype(L,1,"ccexp.VideoPlayer",0,&tolua_err)) goto tolua_lerror; #endif self = static_cast<cocos2d::experimental::ui::VideoPlayer*>(tolua_tousertype(L,1,0)); #if COCOS2D_DEBUG >= 1 if (nullptr == self) { tolua_error(L,"invalid 'self' in function 'lua_cocos2dx_Widget_addTouchEventListener'\n", nullptr); return 0; } #endif argc = lua_gettop(L) - 1; if (argc == 1) { #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([=](cocos2d::Ref* ref, cocos2d::experimental::ui::VideoPlayer::EventType eventType) { LuaStack* stack = LuaEngine::getInstance()->getLuaStack(); stack->pushObject(ref, "cc.Ref"); stack->pushInt((int)eventType); stack->executeFunctionByHandler(handler, 2); }); return 0; } luaL_error(L, "%s has wrong number of arguments: %d, was expecting %d\n ", "ccexp.VideoPlayer:addEventListener",argc, 0); return 0; #if COCOS2D_DEBUG >= 1 tolua_lerror: tolua_error(L, "#ferror in function 'lua_cocos2dx_experimental_VideoPlayer_addEventListener'.", &tolua_err); #endif return 0; }
void CNetDelegate::executeOnMessageReceivedScriptHandler(CBuffer *oBuffer) { if (m_nMessageReceivedScriptHandler != 0) { LuaEngine* pEngine = LuaEngine::getInstance(); LuaStack* pStack = pEngine->getLuaStack(); pStack->pushObject(oBuffer, "CBuffer"); pStack->executeFunctionByHandler(m_nMessageReceivedScriptHandler, 1); pStack->clean(); } }
void CCMsgDelegate::executeOnMessageScriptHandler(unsigned int uMsg, Ref* pMsgObj) { if (m_nMessageScriptHandler != 0) { LuaEngine* pEngine = LuaEngine::getInstance(); LuaStack* pStack = pEngine->getLuaStack(); pStack->pushInt(uMsg); pStack->pushObject(pMsgObj, "Ref"); pStack->executeFunctionByHandler(m_nMessageScriptHandler, 2); pStack->clean(); } }
bool NBGCCBReader::onAssignCCBMemberVariable(Ref * pTarget, const char * pMemberVariableName, Node * node) { if (pTarget == this) { if (luaHandler_memberVarSetter > 0) { auto engine = LuaEngine::getInstance(); LuaStack* stack = engine->getLuaStack(); stack->pushString(pMemberVariableName); stack->pushObject(node, "cc.Node"); stack->executeFunctionByHandler(luaHandler_memberVarSetter, 2); stack->clean(); } if (assignMemVarCallback != nullptr) { return assignMemVarCallback(pTarget, pMemberVariableName, node); } } return false; }
static int tolua_cocos2dx_EventListenerPhysicsContact_registerScriptHandler(lua_State* tolua_S) { if (nullptr == tolua_S) return 0; int argc = 0; EventListenerPhysicsContact* self = nullptr; #if COCOS2D_DEBUG >= 1 tolua_Error tolua_err; if (!tolua_isusertype(tolua_S, 1, "cc.EventListenerPhysicsContact", 0, &tolua_err)) goto tolua_lerror; #endif self = static_cast<EventListenerPhysicsContact*>(tolua_tousertype(tolua_S,1,0)); #if COCOS2D_DEBUG >= 1 if (nullptr == self) { tolua_error(tolua_S,"invalid 'self' in function 'tolua_cocos2dx_EventListenerPhysicsContact_registerScriptHandler'\n", nullptr); return 0; } #endif argc = lua_gettop(tolua_S) - 1; if (argc == 2) { #if COCOS2D_DEBUG >= 1 if (!toluafix_isfunction(tolua_S,2,"LUA_FUNCTION",0,&tolua_err) || !tolua_isnumber(tolua_S, 3, 0, &tolua_err)) { goto tolua_lerror; } #endif LUA_FUNCTION handler = toluafix_ref_function(tolua_S,2,0); ScriptHandlerMgr::HandlerType type = static_cast<ScriptHandlerMgr::HandlerType>((int)tolua_tonumber(tolua_S, 3, 0)); switch (type) { case ScriptHandlerMgr::HandlerType::EVENT_PHYSICS_CONTACT_BEGIN: { ScriptHandlerMgr::getInstance()->addObjectHandler((void*)self, handler, type); self->onContactBegin = [handler](PhysicsContact& contact) -> bool{ LuaStack* stack = LuaEngine::getInstance()->getLuaStack(); stack->pushObject(&contact, "cc.PhysicsContact"); bool ret = stack->executeFunctionByHandler(handler, 1); stack->clean(); return ret; }; } break; case ScriptHandlerMgr::HandlerType::EVENT_PHYSICS_CONTACT_PRESOLVE: { ScriptHandlerMgr::getInstance()->addObjectHandler((void*)self, handler, type); self->onContactPreSolve = [handler](PhysicsContact& contact, PhysicsContactPreSolve& solve) -> bool{ LuaStack* stack = LuaEngine::getInstance()->getLuaStack(); stack->pushObject(&contact, "cc.PhysicsContact"); tolua_pushusertype(stack->getLuaState(), &solve, "cc.PhysicsContactPreSolve"); bool ret = stack->executeFunctionByHandler(handler, 2); stack->clean(); return ret; }; } break; case ScriptHandlerMgr::HandlerType::EVENT_PHYSICS_CONTACT_POSTSOLVE: { ScriptHandlerMgr::getInstance()->addObjectHandler((void*)self, handler, type); self->onContactPostSolve = [handler](PhysicsContact& contact, const PhysicsContactPostSolve& solve){ LuaStack* stack = LuaEngine::getInstance()->getLuaStack(); stack->pushObject(&contact, "cc.PhysicsContact"); tolua_pushusertype(stack->getLuaState(), const_cast<PhysicsContactPostSolve*>(&solve), "cc.PhysicsContactPostSolve"); stack->executeFunctionByHandler(handler, 2); stack->clean(); }; } break; case ScriptHandlerMgr::HandlerType::EVENT_PHYSICS_CONTACT_SEPERATE: { ScriptHandlerMgr::getInstance()->addObjectHandler((void*)self, handler, type); self->onContactSeperate = [handler](PhysicsContact& contact){ LuaStack* stack = LuaEngine::getInstance()->getLuaStack(); stack->pushObject(&contact, "cc.PhysicsContact"); stack->executeFunctionByHandler(handler, 1); stack->clean(); }; } break; default: break; } return 0; } CCLOG("'registerScriptHandler' has wrong number of arguments: %d, was expecting %d\n", argc, 2); return 0; #if COCOS2D_DEBUG >= 1 tolua_lerror: tolua_error(tolua_S,"#ferror in function 'registerScriptHandler'.",&tolua_err); return 0; #endif }