diff --git a/cocos/2d/CCComponent.cpp b/cocos/2d/CCComponent.cpp index 2fd2c7c..a89f982 100644 --- a/cocos/2d/CCComponent.cpp +++ b/cocos/2d/CCComponent.cpp @@ -46,77 +46,24 @@ bool Component::init() return true; } -#if CC_ENABLE_SCRIPT_BINDING - -static bool sendComponentEventToJS(Component* node, int action) -{ - auto scriptEngine = ScriptEngineManager::getInstance()->getScriptEngine(); - - if (scriptEngine->isCalledFromScript()) - { - scriptEngine->setCalledFromScript(false); - } - else - { - BasicScriptData data(node,(void*)&action); - ScriptEvent scriptEvent(kComponentEvent,(void*)&data); - if (scriptEngine->sendEvent(&scriptEvent)) - return true; - } - - return false; -} - -#endif - void Component::onEnter() { -#if CC_ENABLE_SCRIPT_BINDING - if (_scriptType == kScriptTypeJavascript) - { - sendComponentEventToJS(this, kComponentOnEnter); - } -#endif } void Component::onExit() { -#if CC_ENABLE_SCRIPT_BINDING - if (_scriptType == kScriptTypeJavascript) - { - sendComponentEventToJS(this, kComponentOnExit); - } -#endif } void Component::onAdd() { -#if CC_ENABLE_SCRIPT_BINDING - if (_scriptType == kScriptTypeJavascript) - { - sendComponentEventToJS(this, kComponentOnAdd); - } -#endif } void Component::onRemove() { -#if CC_ENABLE_SCRIPT_BINDING - if (_scriptType == kScriptTypeJavascript) - { - sendComponentEventToJS(this, kComponentOnRemove); - } -#endif } void Component::update(float /*delta*/) { -#if CC_ENABLE_SCRIPT_BINDING - if (_scriptType == kScriptTypeJavascript) - { - sendComponentEventToJS(this, kComponentOnUpdate); - } -#endif } bool Component::serialize(void* /*ar*/) diff --git a/cocos/base/CCDirector.cpp b/cocos/base/CCDirector.cpp index 5031377..abc50fa 100644 --- a/cocos/base/CCDirector.cpp +++ b/cocos/base/CCDirector.cpp @@ -1062,12 +1062,6 @@ void Director::restartDirector() // Restart animation startAnimation(); - - // Real restart in script level -#if CC_ENABLE_SCRIPT_BINDING - ScriptEvent scriptEvent(kRestartGame, nullptr); - ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&scriptEvent); -#endif } void Director::setNextScene() diff --git a/cocos/base/CCRef.cpp b/cocos/base/CCRef.cpp index 3425829..cc88af0 100644 --- a/cocos/base/CCRef.cpp +++ b/cocos/base/CCRef.cpp @@ -70,18 +70,8 @@ Ref::~Ref() // if the object is referenced by Lua engine, remove it pEngine->removeScriptObjectByObject(this); } -#if !CC_ENABLE_GC_FOR_NATIVE_OBJECTS - else - { - if (pEngine != nullptr && pEngine->getScriptType() == kScriptTypeJavascript) - { - pEngine->removeScriptObjectByObject(this); - } - } -#endif // !CC_ENABLE_GC_FOR_NATIVE_OBJECTS #endif // CC_ENABLE_SCRIPT_BINDING - #if CC_REF_LEAK_DETECTION if (_referenceCount != 0) untrackRef(this); @@ -136,14 +126,6 @@ void Ref::release() } #endif -#if CC_ENABLE_SCRIPT_BINDING - ScriptEngineProtocol* pEngine = ScriptEngineManager::getInstance()->getScriptEngine(); - if (pEngine != nullptr && pEngine->getScriptType() == kScriptTypeJavascript) - { - pEngine->removeObjectProxy(this); - } -#endif // CC_ENABLE_SCRIPT_BINDING - #if CC_REF_LEAK_DETECTION untrackRef(this); #endif diff --git a/cocos/base/CCScriptSupport.h b/cocos/base/CCScriptSupport.h index ba56dd6..7a9070a 100644 --- a/cocos/base/CCScriptSupport.h +++ b/cocos/base/CCScriptSupport.h @@ -56,8 +56,7 @@ class Action; enum ccScriptType { kScriptTypeNone = 0, - kScriptTypeLua, - kScriptTypeJavascript + kScriptTypeLua }; /** @@ -253,14 +252,7 @@ enum ScriptEventType kNodeEvent = 0, kCallFuncEvent, kScheduleEvent, - kTouchEvent, - kTouchesEvent, - kKeypadEvent, - kAccelerometerEvent, - kCommonEvent, - kComponentEvent, - kRestartGame, - kScriptActionEvent + kCommonEvent }; /** @@ -297,48 +289,6 @@ struct BasicScriptData } }; -/** - * For Lua, Wrapper the script data that should be used to find the handler corresponding to the Lua function by the nativeobject pointer and store the value pointer which would be converted concretely by the different events,then the converted data would be passed into the Lua stack. - * @js NA - */ -struct ActionObjectScriptData -{ - /** - * For Lua, nativeobject is used to get handler corresponding to the Lua function. - * - * @js NA - * @lua NA - */ - void* nativeObject; - - /** - * A pointer point to the value data which event action - * - * @js NA - * @lua NA - */ - int* eventType; - - /** - * A pointer point to the value data which would be converted by different events. - * - * @js NA - * @lua NA - */ - void* param; - - /** - * Constructor of BasicScriptData. - * - * @js NA - * @lua NA - */ - ActionObjectScriptData(void* inObject,int* inValue = nullptr, void* inParam = nullptr) - : nativeObject(inObject),eventType(inValue), param(inParam) - { - } -}; - /** * For Lua, the SchedulerScriptData is used to find the Lua function pointer by the handler, then call the Lua function by push the elapse into the Lua stack as a parameter when scheduler update event is triggered. * @js NA @@ -376,141 +326,6 @@ struct SchedulerScriptData } }; -/** - * For Lua, the TouchesScriptData is used to find the Lua function pointer by the nativeObject, then call the Lua function by push touches data and actionType into the Lua stack as the parameters when the touches event is triggered. - * @js NA - */ -struct TouchesScriptData -{ - /** - * The EventTouch::EventCode type. - * - * @lua NA - * @js NA - */ - EventTouch::EventCode actionType; - /** - * For Lua, it Used to find the Lua function pointer by the ScriptHandlerMgr. - * - * @lua NA - * @js NA - */ - void* nativeObject; - /** - * The vector of Touch.For Lua, it would be convert to the Lua table form to be pushed into the Lua stack. - * - * @lua NA - * @js NA - */ - const std::vector& touches; - /** - * event information, it is useless for Lua. - * - * @lua NA - * @js NA - */ - Event* event; - - /** - * Constructor of TouchesScriptData. - * - * @lua NA - * @js NA - */ - TouchesScriptData(EventTouch::EventCode inActionType, void* inNativeObject, const std::vector& inTouches, Event* evt) - : actionType(inActionType), - nativeObject(inNativeObject), - touches(inTouches), - event(evt) - { - } -}; - -/** - * For Lua, the TouchScriptData is used to find the Lua function pointer by the nativeObject, then call the Lua function by push touch data and actionType converted to string type into the Lua stack as the parameters when the touch event is triggered. - * @js NA - */ -struct TouchScriptData -{ - /** - * The EventTouch::EventCode type. - * - * @lua NA - * @js NA - */ - EventTouch::EventCode actionType; - /** - * For Lua, it Used to find the Lua function pointer by the ScriptHandlerMgr. - * - * @lua NA - * @js NA - */ - void* nativeObject; - /** - * touch information. it would be in x,y form to push into the Lua stack. - * - * @lua NA - * @js NA - */ - Touch* touch; - /** - * event information,it is useless for Lua. - * - * @lua NA - * @js NA - */ - Event* event; - - /** - * Constructor of TouchScriptData. - * - * @lua NA - * @js NA - */ - TouchScriptData(EventTouch::EventCode inActionType, void* inNativeObject, Touch* inTouch, Event* evt) - : actionType(inActionType), - nativeObject(inNativeObject), - touch(inTouch), - event(evt) - { - } -}; - - -/** - * For Lua, the KeypadScriptData is used to find the Lua function pointer by the nativeObject, then call the Lua function by push the actionType converted to string type into the Lua stack as the parameters when the Keypad event is triggered. - * @js NA - */ -struct KeypadScriptData -{ - /** - * The specific type of EventKeyboard::KeyCode - * - * @lua NA - * @js NA - */ - EventKeyboard::KeyCode actionType; - /** - * For Lua, it Used to find the Lua function pointer by the ScriptHandlerMgr. - * - * @lua NA - * @js NA - */ - void* nativeObject; - - /** - * Constructor of KeypadScriptData. - * - * @lua NA - * @js NA - */ - KeypadScriptData(EventKeyboard::KeyCode inActionType,void* inNativeObject) - : actionType(inActionType),nativeObject(inNativeObject) - { - } -}; - - /** * For Lua, the CommonScriptData is used to find the Lua function pointer by the handler, then call the Lua function by push the eventName, eventSource(if it not nullptr), eventSourceClassName(if it is nullptr or "", and the eventSource is not nullptr,would give the default string "cc.Ref") into the Lua stack as the parameter when the common event such as is triggered. * @js NA diff --git a/cocos/scripting/lua-bindings/manual/CCLuaEngine.cpp b/cocos/scripting/lua-bindings/manual/CCLuaEngine.cpp index 21134b9..f5b4536 100644 --- a/cocos/scripting/lua-bindings/manual/CCLuaEngine.cpp +++ b/cocos/scripting/lua-bindings/manual/CCLuaEngine.cpp @@ -105,21 +105,6 @@ int LuaEngine::executeGlobalFunction(const char* functionName) return ret; } -int LuaEngine::executeNodeEvent(Node* pNode, int nAction) -{ - return 0; -} - -int LuaEngine::executeMenuItemEvent(MenuItem* pMenuItem) -{ - return 0; -} - -int LuaEngine::executeCallFuncActionEvent(CallFunc* pAction, Ref* pTarget/* = NULL*/) -{ - return 0; -} - int LuaEngine::executeSchedule(int nHandler, float dt, Node* pNode/* = NULL*/) { if (!nHandler) return 0; @@ -129,21 +114,6 @@ int LuaEngine::executeSchedule(int nHandler, float dt, Node* pNode/* = NULL*/) return ret; } -int LuaEngine::executeLayerTouchEvent(Layer* pLayer, int eventType, Touch *pTouch) -{ - return 0; -} - -int LuaEngine::executeLayerKeypadEvent(Layer* pLayer, int eventType) -{ - return 0; -} - -int LuaEngine::executeAccelerometerEvent(Layer* pLayer, Acceleration* pAccelerationValue) -{ - return 0; -} - int LuaEngine::executeEvent(int nHandler, const char* pEventName, Ref* pEventSource /* = NULL*/, const char* pEventSourceClassName /* = NULL*/) { _stack->pushString(pEventName); @@ -208,26 +178,6 @@ int LuaEngine::sendEvent(ScriptEvent* evt) return handleScheduler(evt->data); } break; - case kTouchEvent: - { - return handleTouchEvent(evt->data); - } - break; - case kTouchesEvent: - { - return handleTouchesEvent(evt->data); - } - break; - case kKeypadEvent: - { - return handleKeypadEvent(evt->data); - } - break; - case kAccelerometerEvent: - { - return handleAccelerometerEvent(evt->data); - } - break; case kCommonEvent: { return handleCommonEvent(evt->data); @@ -323,62 +273,6 @@ int LuaEngine::handleScheduler(void* data) return ret; } -int LuaEngine::handleKeypadEvent(void* data) -{ - if (NULL == data) - return 0; - - KeypadScriptData* keypadScriptData = static_cast(data); - if (NULL == keypadScriptData->nativeObject) - return 0; - - int handler = ScriptHandlerMgr::getInstance()->getObjectHandler(keypadScriptData->nativeObject, ScriptHandlerMgr::HandlerType::KEYPAD); - - if (0 == handler) - return 0; - - EventKeyboard::KeyCode action = keypadScriptData->actionType; - - switch(action) - { - case EventKeyboard::KeyCode::KEY_ESCAPE: - _stack->pushString("backClicked"); - break; - case EventKeyboard::KeyCode::KEY_MENU: - _stack->pushString("menuClicked"); - break; - default: - break; - } - - int ret = _stack->executeFunctionByHandler(handler, 1); - _stack->clean(); - return ret; -} - -int LuaEngine::handleAccelerometerEvent(void* data) -{ - if (NULL == data) - return 0; - - BasicScriptData* basicScriptData = static_cast(data); - if (NULL == basicScriptData->nativeObject || NULL == basicScriptData->value) - return 0; - - int handler = ScriptHandlerMgr::getInstance()->getObjectHandler(basicScriptData->nativeObject, ScriptHandlerMgr::HandlerType::ACCELEROMETER); - if (0 == handler) - return 0; - - Acceleration* accelerationValue = static_cast(basicScriptData->value); - _stack->pushFloat(float(accelerationValue->x)); - _stack->pushFloat(float(accelerationValue->y)); - _stack->pushFloat(float(accelerationValue->z)); - _stack->pushFloat(float(accelerationValue->timestamp)); - int ret = _stack->executeFunctionByHandler(handler, 4); - _stack->clean(); - return ret; -} - int LuaEngine::handleCommonEvent(void* data) { if (NULL == data) @@ -405,113 +299,6 @@ int LuaEngine::handleCommonEvent(void* data) return ret; } -int LuaEngine::handleTouchEvent(void* data) -{ - if (NULL == data) - return 0; - - TouchScriptData* touchScriptData = static_cast(data); - if (NULL == touchScriptData->nativeObject || NULL == touchScriptData->touch) - return 0; - - int handler = ScriptHandlerMgr::getInstance()->getObjectHandler((void*)touchScriptData->nativeObject, ScriptHandlerMgr::HandlerType::TOUCHES); - - if (0 == handler) - return 0; - - switch (touchScriptData->actionType) - { - case EventTouch::EventCode::BEGAN: - _stack->pushString("began"); - break; - - case EventTouch::EventCode::MOVED: - _stack->pushString("moved"); - break; - - case EventTouch::EventCode::ENDED: - _stack->pushString("ended"); - break; - - case EventTouch::EventCode::CANCELLED: - _stack->pushString("cancelled"); - break; - - default: - return 0; - } - - int ret = 0; - - Touch* touch = touchScriptData->touch; - if (NULL != touch) { - const cocos2d::Vec2 pt = Director::getInstance()->convertToGL(touch->getLocationInView()); - _stack->pushFloat(pt.x); - _stack->pushFloat(pt.y); - ret = _stack->executeFunctionByHandler(handler, 3); - } - _stack->clean(); - return ret; -} - -int LuaEngine::handleTouchesEvent(void* data) -{ - if (NULL == data) - return 0; - - TouchesScriptData* touchesScriptData = static_cast(data); - if (NULL == touchesScriptData->nativeObject || touchesScriptData->touches.size() == 0) - return 0; - - int handler = ScriptHandlerMgr::getInstance()->getObjectHandler((void*)touchesScriptData->nativeObject, ScriptHandlerMgr::HandlerType::TOUCHES); - - if (0 == handler) - return 0; - - switch (touchesScriptData->actionType) - { - case EventTouch::EventCode::BEGAN: - _stack->pushString("began"); - break; - - case EventTouch::EventCode::MOVED: - _stack->pushString("moved"); - break; - - case EventTouch::EventCode::ENDED: - _stack->pushString("ended"); - break; - - case EventTouch::EventCode::CANCELLED: - _stack->pushString("cancelled"); - break; - - default: - return 0; - } - - Director* pDirector = Director::getInstance(); - lua_State *L = _stack->getLuaState(); - int ret = 0; - - lua_newtable(L); - int i = 1; - for (auto& touch : touchesScriptData->touches) - { - cocos2d::Vec2 pt = pDirector->convertToGL(touch->getLocationInView()); - lua_pushnumber(L, pt.x); - lua_rawseti(L, -2, i++); - lua_pushnumber(L, pt.y); - lua_rawseti(L, -2, i++); - lua_pushinteger(L, touch->getID()); - lua_rawseti(L, -2, i++); - } - ret = _stack->executeFunctionByHandler(handler, 2); - - _stack->clean(); - return ret; -} - int LuaEngine::handleEventAcc(void* data) { if (nullptr == data) @@ -681,23 +468,6 @@ int LuaEngine::handleEvent(ScriptHandlerMgr::HandlerType type,void* data) { switch (type) { - case ScriptHandlerMgr::HandlerType::SCROLLVIEW_SCROLL: - case ScriptHandlerMgr::HandlerType::SCROLLVIEW_ZOOM: - case ScriptHandlerMgr::HandlerType::TABLECELL_TOUCHED: - case ScriptHandlerMgr::HandlerType::TABLECELL_HIGHLIGHT: - case ScriptHandlerMgr::HandlerType::TABLECELL_UNHIGHLIGHT: - case ScriptHandlerMgr::HandlerType::TABLECELL_WILL_RECYCLE: - { - return handleTableViewEvent(type, data); - } - break; - case ScriptHandlerMgr::HandlerType::ASSETSMANAGER_PROGRESS: - case ScriptHandlerMgr::HandlerType::ASSETSMANAGER_ERROR: - case ScriptHandlerMgr::HandlerType::ASSETSMANAGER_SUCCESS: - { - return handleAssetsManagerEvent(type, data); - } - break; case ScriptHandlerMgr::HandlerType::ARMATURE_EVENT: { return handleArmatureWrapper(type, data); @@ -750,164 +520,6 @@ int LuaEngine::handleEvent(ScriptHandlerMgr::HandlerType type,void* data) return 0; } -int LuaEngine::handleEvent(ScriptHandlerMgr::HandlerType type, void* data, int numResults, const std::function& func) -{ - switch (type) - { - case ScriptHandlerMgr::HandlerType::TABLECELL_SIZE_FOR_INDEX: - case ScriptHandlerMgr::HandlerType::TABLECELL_AT_INDEX: - case ScriptHandlerMgr::HandlerType::TABLEVIEW_NUMS_OF_CELLS: - { - return handleTableViewEvent(type, data, numResults,func); - } - break; - default: - break; - } - - return 0; -} - -int LuaEngine::handleTableViewEvent(ScriptHandlerMgr::HandlerType type,void* data) -{ - if (nullptr == data) - return 0; - - BasicScriptData* eventData = static_cast(data); - if (nullptr == eventData->nativeObject || nullptr == eventData->value) - return 0; - - LuaTableViewEventData* tableViewData = static_cast(eventData->value); - int handler = ScriptHandlerMgr::getInstance()->getObjectHandler((void*)eventData->nativeObject, type); - - if (0 == handler) - return 0; - - Ref* obj = static_cast(eventData->nativeObject); - if (nullptr == obj) - return 0; - - int ret = 0; - switch (type) - { - case ScriptHandlerMgr::HandlerType::SCROLLVIEW_SCROLL: - case ScriptHandlerMgr::HandlerType::SCROLLVIEW_ZOOM: - { - toluafix_pushusertype_ccobject(_stack->getLuaState(), obj->_ID, &(obj->_luaID), (void*)(obj),"cc.TableView"); - ret = _stack->executeFunctionByHandler(handler, 1); - } - break; - case ScriptHandlerMgr::HandlerType::TABLECELL_TOUCHED: - case ScriptHandlerMgr::HandlerType::TABLECELL_HIGHLIGHT: - case ScriptHandlerMgr::HandlerType::TABLECELL_UNHIGHLIGHT: - case ScriptHandlerMgr::HandlerType::TABLECELL_WILL_RECYCLE: - { - Ref* cellObject = static_cast(tableViewData->value); - if (nullptr == cellObject) { - break; - } - toluafix_pushusertype_ccobject(_stack->getLuaState(), obj->_ID, &(obj->_luaID), (void*)(obj),"cc.TableView"); - toluafix_pushusertype_ccobject(_stack->getLuaState(), cellObject->_ID, &(cellObject->_luaID), (void*)(cellObject),"cc.TableViewCell"); - ret = _stack->executeFunctionByHandler(handler, 2); - } - break; - default: - break; - } - - return ret; - -} - -int LuaEngine::handleTableViewEvent(ScriptHandlerMgr::HandlerType handlerType,void* data, int numResults, const std::function& func) -{ - if (nullptr == data || numResults <= 0) - return 0; - - BasicScriptData* eventData = static_cast(data); - if (nullptr == eventData->nativeObject || nullptr == eventData->value) - return 0; - - LuaTableViewEventData* tableViewData = static_cast(eventData->value); - int handler = ScriptHandlerMgr::getInstance()->getObjectHandler((void*)eventData->nativeObject, handlerType); - - if (0 == handler) - return 0; - - Ref* obj = static_cast(eventData->nativeObject); - if (nullptr == obj) - return 0; - - int ret = 0; - switch (handlerType) - { - case ScriptHandlerMgr::HandlerType::TABLECELL_SIZE_FOR_INDEX: - { - toluafix_pushusertype_ccobject(_stack->getLuaState(), obj->_ID, &(obj->_luaID), (void*)(obj),"cc.TableView"); - _stack->pushLong(*((ssize_t*)tableViewData->value)); - ret = _stack->executeFunction(handler, 2, 2, func); - } - break; - case ScriptHandlerMgr::HandlerType::TABLECELL_AT_INDEX: - { - toluafix_pushusertype_ccobject(_stack->getLuaState(), obj->_ID, &(obj->_luaID), (void*)(obj),"cc.TableView"); - _stack->pushLong(*((ssize_t*)tableViewData->value)); - ret = _stack->executeFunction(handler, 2, 1, func); - } - break; - case ScriptHandlerMgr::HandlerType::TABLEVIEW_NUMS_OF_CELLS: - { - toluafix_pushusertype_ccobject(_stack->getLuaState(), obj->_ID, &(obj->_luaID), (void*)(obj),"cc.TableView"); - ret = _stack->executeFunction(handler, 1, 1, func); - } - break; - default: - break; - } - - return ret; -} - -int LuaEngine::handleAssetsManagerEvent(ScriptHandlerMgr::HandlerType type,void* data) -{ - if (nullptr == data) - return 0; - - BasicScriptData* eventData = static_cast(data); - if (nullptr == eventData->nativeObject || nullptr == eventData->value) - return 0; - - LuaAssetsManagerEventData* assetsManagerData = static_cast(eventData->value); - - int handler = ScriptHandlerMgr::getInstance()->getObjectHandler((void*)eventData->nativeObject, type); - - if (0 == handler) - return 0; - - int ret = 0; - switch (type) - { - case ScriptHandlerMgr::HandlerType::ASSETSMANAGER_PROGRESS: - case ScriptHandlerMgr::HandlerType::ASSETSMANAGER_ERROR: - { - _stack->pushInt(assetsManagerData->value); - ret = _stack->executeFunctionByHandler(handler, 1); - } - break; - - case ScriptHandlerMgr::HandlerType::ASSETSMANAGER_SUCCESS: - { - ret = _stack->executeFunctionByHandler(handler, 0); - } - break; - - default: - break; - } - - return ret; -} - int LuaEngine::handleArmatureWrapper(ScriptHandlerMgr::HandlerType type,void* data) { if (nullptr == data) diff --git a/cocos/scripting/lua-bindings/manual/CCLuaEngine.h b/cocos/scripting/lua-bindings/manual/CCLuaEngine.h index eab741a..6e0f9f9 100644 --- a/cocos/scripting/lua-bindings/manual/CCLuaEngine.h +++ b/cocos/scripting/lua-bindings/manual/CCLuaEngine.h @@ -157,13 +157,7 @@ public: * @return The integer value returned from the script function. */ virtual int executeGlobalFunction(const char* functionName) override; - virtual int executeNodeEvent(Node* pNode, int nAction); - virtual int executeMenuItemEvent(MenuItem* pMenuItem); - virtual int executeCallFuncActionEvent(CallFunc* pAction, Ref* pTarget = NULL); virtual int executeSchedule(int nHandler, float dt, Node* pNode = NULL); - virtual int executeLayerTouchEvent(Layer* pLayer, int eventType, Touch *pTouch); - virtual int executeLayerKeypadEvent(Layer* pLayer, int eventType); - virtual int executeAccelerometerEvent(Layer* pLayer, Acceleration* pAccelerationValue); virtual int executeEvent(int nHandler, const char* pEventName, Ref* pEventSource = NULL, const char* pEventSourceClassName = NULL); /** * Handle the assert message. @@ -197,16 +191,6 @@ public: * @return default return 0 otherwise return values according different ScriptHandlerMgr::HandlerType. */ virtual int handleEvent(ScriptHandlerMgr::HandlerType type,void* data); - /** - * Pass on the events related with TableCell and TableView to lua to handle. - * - * @param type Different ScriptHandlerMgr::HandlerType means different processing for the data. - * @param data The pointer point to the information which should be pass on to lua, it would be parsed in the function to convert to the specific data according to the ScriptHandlerMgr::HandlerType,then pass to lua as function parameters. - * @param numResults The number of the return values. - * @param func The callback would be called when numResults is > 0. - * @return default return 0 otherwise return values according different ScriptHandlerMgr::HandlerType. - */ - virtual int handleEvent(ScriptHandlerMgr::HandlerType type, void* data, int numResults, const std::function& func); private: LuaEngine(void) : _stack(nullptr) @@ -219,13 +203,8 @@ private: int handleKeypadEvent(void* data); int handleAccelerometerEvent(void* data); int handleCommonEvent(void* data); - int handleTouchEvent(void* data); - int handleTouchesEvent(void* data); int handlerControlEvent(void* data); int handleEvenCustom(void* data); - int handleAssetsManagerEvent(ScriptHandlerMgr::HandlerType type,void* data); - int handleTableViewEvent(ScriptHandlerMgr::HandlerType type,void* data); - int handleTableViewEvent(ScriptHandlerMgr::HandlerType type,void* data, int numResults, const std::function& func); int handleArmatureWrapper(ScriptHandlerMgr::HandlerType type,void* data); int handleEventAcc(void* data); int handleEventKeyboard(ScriptHandlerMgr::HandlerType type,void* data); diff --git a/cocos/scripting/lua-bindings/manual/CCLuaStack.cpp b/cocos/scripting/lua-bindings/manual/CCLuaStack.cpp index c368795..8d9f4b9 100644 --- a/cocos/scripting/lua-bindings/manual/CCLuaStack.cpp +++ b/cocos/scripting/lua-bindings/manual/CCLuaStack.cpp @@ -621,7 +621,8 @@ int LuaStack::luaLoadChunksFromZIP(lua_State *L) { if (lua_gettop(L) < 1) { CCLOG("luaLoadChunksFromZIP() - invalid arguments"); - return 0; + lua_pushboolean(L, 0); + return 1; } const char *zipFilename = lua_tostring(L, -1); diff --git a/cocos/scripting/lua-bindings/manual/cocos2d/LuaScriptHandlerMgr.h b/cocos/scripting/lua-bindings/manual/cocos2d/LuaScriptHandlerMgr.h index 6d3c339..b6e423d 100644 --- a/cocos/scripting/lua-bindings/manual/cocos2d/LuaScriptHandlerMgr.h +++ b/cocos/scripting/lua-bindings/manual/cocos2d/LuaScriptHandlerMgr.h @@ -130,22 +130,7 @@ public: enum class HandlerType: int { NODE = 0, - MENU_CLICKED, CALLFUNC, - SCHEDULE, - TOUCHES, - KEYPAD, - ACCELEROMETER, - - CONTROL_TOUCH_DOWN, - CONTROL_TOUCH_DRAG_INSIDE, - CONTROL_TOUCH_DRAG_OUTSIDE, - CONTROL_TOUCH_DRAG_ENTER, - CONTROL_TOUCH_DRAG_EXIT, - CONTROL_TOUCH_UP_INSIDE, - CONTROL_TOUCH_UP_OUTSIDE, - CONTROL_TOUCH_UP_CANCEL, - CONTROL_VALUE_CHANGED, WEBSOCKET_OPEN, WEBSOCKET_MESSAGE, @@ -154,24 +139,6 @@ public: LUANODE_DRAW, - SCROLLVIEW_SCROLL, - SCROLLVIEW_ZOOM, - - TABLECELL_TOUCHED, - TABLECELL_HIGHLIGHT, - TABLECELL_UNHIGHLIGHT, - TABLECELL_WILL_RECYCLE, - TABLECELL_SIZE_FOR_INDEX, - TABLECELL_AT_INDEX, - TABLEVIEW_NUMS_OF_CELLS, - - XMLHTTPREQUEST_READY_STATE_CHANGE, - - ASSETSMANAGER_PROGRESS, - ASSETSMANAGER_SUCCESS, - ASSETSMANAGER_ERROR, - - STUDIO_EVENT_LISTENER, ARMATURE_EVENT, EVENT_ACC, @@ -195,8 +162,6 @@ public: EVENT_MOUSE_MOVE, EVENT_MOUSE_SCROLL, - EVENT_SPINE, - EVENT_PHYSICS_CONTACT_BEGIN, EVENT_PHYSICS_CONTACT_PRESOLVE, EVENT_PHYSICS_CONTACT_POSTSOLVE, diff --git a/cocos/scripting/lua-bindings/manual/cocos2d/lua_cocos2dx_manual.cpp b/cocos/scripting/lua-bindings/manual/cocos2d/lua_cocos2dx_manual.cpp index d6d79c3..286913b 100644 --- a/cocos/scripting/lua-bindings/manual/cocos2d/lua_cocos2dx_manual.cpp +++ b/cocos/scripting/lua-bindings/manual/cocos2d/lua_cocos2dx_manual.cpp @@ -210,22 +210,6 @@ int register_luanode_manual(lua_State* tolua_S) return 1; } -static int executeScriptTouchHandler(Layer* layer, EventTouch::EventCode eventType, Touch* touch, Event* event) -{ - TouchScriptData data(eventType, layer, touch, event); - ScriptEvent scriptEvent(kTouchEvent, &data); - return ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&scriptEvent); -} - -static int executeScriptTouchesHandler(Layer* layer, EventTouch::EventCode eventType, const std::vector& touches, Event* event) -{ - TouchesScriptData data(eventType, layer, touches, event); - ScriptEvent scriptEvent(kTouchesEvent, &data); - return ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&scriptEvent); -} - - - static int tolua_cocos2d_Scheduler_scheduleScriptFunc(lua_State* tolua_S) { if (NULL == tolua_S) @@ -276,7 +260,6 @@ tolua_lerror: #endif } - static int tolua_cocos2d_Scheduler_unscheduleScriptEntry(lua_State* tolua_S) { if (NULL == tolua_S) diff --git a/cocos/scripting/lua-bindings/manual/extension/lua_cocos2dx_extension_manual.h b/cocos/scripting/lua-bindings/manual/extension/lua_cocos2dx_extension_manual.h index 8a909f2..8c5eeb1 100644 --- a/cocos/scripting/lua-bindings/manual/extension/lua_cocos2dx_extension_manual.h +++ b/cocos/scripting/lua-bindings/manual/extension/lua_cocos2dx_extension_manual.h @@ -54,25 +54,4 @@ TOLUA_API int register_extension_module(lua_State* tolua_S); TOLUA_API int register_all_cocos2dx_extension_manual(lua_State* tolua_S); /// @endcond -struct LuaAssetsManagerEventData -{ - int value; - - LuaAssetsManagerEventData(int _value = 0):value(_value) - { - } -}; - - -struct LuaTableViewEventData -{ - void* value; - - // Constructor - LuaTableViewEventData(void* _value = nullptr) - :value(_value) - { - } -}; - #endif // #ifndef COCOS2DX_SCRIPT_LUA_COCOS2DX_SUPPORT_LUA_COCOS2DX_EXTENSION_MANUAL_H diff --git a/cocos/scripting/lua-bindings/script/cocos2d/Cocos2dConstants.lua b/cocos/scripting/lua-bindings/script/cocos2d/Cocos2dConstants.lua index bfd2e42..37801ef 100644 --- a/cocos/scripting/lua-bindings/script/cocos2d/Cocos2dConstants.lua +++ b/cocos/scripting/lua-bindings/script/cocos2d/Cocos2dConstants.lua @@ -217,79 +217,49 @@ cc.NODE_ON_EXIT_TRANSITION_DID_START = 3 cc.NODE_ON_CLEAN_UP = 4 cc.Handler = cc.Handler or {} -cc.Handler.NODE = 0 -cc.Handler.MENU_CLICKED = 1 -cc.Handler.CALLFUNC = 2 -cc.Handler.SCHEDULE = 3 -cc.Handler.TOUCHES = 4 -cc.Handler.KEYPAD = 5 -cc.Handler.ACCELEROMETER = 6 -cc.Handler.CONTROL_TOUCH_DOWN = 7 -cc.Handler.CONTROL_TOUCH_DRAG_INSIDE = 8 -cc.Handler.CONTROL_TOUCH_DRAG_OUTSIDE = 9 -cc.Handler.CONTROL_TOUCH_DRAG_ENTER = 10 -cc.Handler.CONTROL_TOUCH_DRAG_EXIT = 11 -cc.Handler.CONTROL_TOUCH_UP_INSIDE = 12 -cc.Handler.CONTROL_TOUCH_UP_OUTSIDE = 13 -cc.Handler.CONTROL_TOUCH_UP_CANCEL = 14 -cc.Handler.CONTROL_VALUE_CHANGED = 15 -cc.Handler.WEBSOCKET_OPEN = 16 -cc.Handler.WEBSOCKET_MESSAGE = 17 -cc.Handler.WEBSOCKET_CLOSE = 18 -cc.Handler.WEBSOCKET_ERROR = 19 -cc.Handler.GL_NODE_DRAW = 20 -cc.Handler.SCROLLVIEW_SCROLL = 21 -cc.Handler.SCROLLVIEW_ZOOM = 22 -cc.Handler.TABLECELL_TOUCHED = 23 -cc.Handler.TABLECELL_HIGHLIGHT = 24 -cc.Handler.TABLECELL_UNHIGHLIGHT = 25 -cc.Handler.TABLECELL_WILL_RECYCLE = 26 -cc.Handler.TABLECELL_SIZE_FOR_INDEX = 27 -cc.Handler.TABLECELL_AT_INDEX = 28 -cc.Handler.TABLEVIEW_NUMS_OF_CELLS = 29 -cc.Handler.HTTPREQUEST_STATE_CHANGE = 30 -cc.Handler.ASSETSMANAGER_PROGRESS = 31 -cc.Handler.ASSETSMANAGER_SUCCESS = 32 -cc.Handler.ASSETSMANAGER_ERROR = 33 -cc.Handler.STUDIO_EVENT_LISTENER = 34 -cc.Handler.ARMATURE_EVENT = 35 -cc.Handler.EVENT_ACC = 36 -cc.Handler.EVENT_CUSTIOM = 37 -cc.Handler.EVENT_KEYBOARD_PRESSED = 38 -cc.Handler.EVENT_KEYBOARD_RELEASED = 39 -cc.Handler.EVENT_TOUCH_BEGAN = 40 -cc.Handler.EVENT_TOUCH_MOVED = 41 -cc.Handler.EVENT_TOUCH_ENDED = 42 -cc.Handler.EVENT_TOUCH_CANCELLED = 43 -cc.Handler.EVENT_TOUCHES_BEGAN = 44 -cc.Handler.EVENT_TOUCHES_MOVED = 45 -cc.Handler.EVENT_TOUCHES_ENDED = 46 -cc.Handler.EVENT_TOUCHES_CANCELLED = 47 -cc.Handler.EVENT_MOUSE_DOWN = 48 -cc.Handler.EVENT_MOUSE_UP = 49 -cc.Handler.EVENT_MOUSE_MOVE = 50 -cc.Handler.EVENT_MOUSE_SCROLL = 51 -cc.Handler.EVENT_SPINE = 52 -cc.Handler.EVENT_PHYSICS_CONTACT_BEGIN = 53 -cc.Handler.EVENT_PHYSICS_CONTACT_PRESOLVE = 54 -cc.Handler.EVENT_PHYSICS_CONTACT_POSTSOLVE = 55 -cc.Handler.EVENT_PHYSICS_CONTACT_SEPARATE = 56 -cc.Handler.EVENT_FOCUS = 57 -cc.Handler.EVENT_CONTROLLER_CONNECTED = 58 -cc.Handler.EVENT_CONTROLLER_DISCONNECTED = 59 -cc.Handler.EVENT_CONTROLLER_KEYDOWN = 60 -cc.Handler.EVENT_CONTROLLER_KEYUP = 61 -cc.Handler.EVENT_CONTROLLER_KEYREPEAT = 62 -cc.Handler.EVENT_CONTROLLER_AXIS = 63 -cc.Handler.EVENT_SPINE_ANIMATION_START = 64 -cc.Handler.EVENT_SPINE_ANIMATION_INTERRUPT = 65 -cc.Handler.EVENT_SPINE_ANIMATION_END = 66 -cc.Handler.EVENT_SPINE_ANIMATION_DISPOSE = 67 -cc.Handler.EVENT_SPINE_ANIMATION_COMPLETE = 68 -cc.Handler.EVENT_SPINE_ANIMATION_EVENT = 69 -cc.Handler.EVENT_SPINE_ANIMATION_PREUPDATE = 70 -cc.Handler.EVENT_SPINE_ANIMATION_POSTUPDATE = 71 - +cc.Handler.NODE = 0 +cc.Handler.CALLFUNC = 1 +cc.Handler.WEBSOCKET_OPEN = 2 +cc.Handler.WEBSOCKET_MESSAGE = 3 +cc.Handler.WEBSOCKET_CLOSE = 4 +cc.Handler.WEBSOCKET_ERROR = 5 +cc.Handler.LUANODE_DRAW = 6 +cc.Handler.ARMATURE_EVENT = 7 +cc.Handler.EVENT_ACC = 8 +cc.Handler.EVENT_CUSTIOM = 9 +cc.Handler.EVENT_KEYBOARD_PRESSED = 10 +cc.Handler.EVENT_KEYBOARD_RELEASED = 11 +cc.Handler.EVENT_TOUCH_BEGAN = 12 +cc.Handler.EVENT_TOUCH_MOVED = 13 +cc.Handler.EVENT_TOUCH_ENDED = 14 +cc.Handler.EVENT_TOUCH_CANCELLED = 15 +cc.Handler.EVENT_TOUCHES_BEGAN = 16 +cc.Handler.EVENT_TOUCHES_MOVED = 17 +cc.Handler.EVENT_TOUCHES_ENDED = 18 +cc.Handler.EVENT_TOUCHES_CANCELLED = 19 +cc.Handler.EVENT_MOUSE_DOWN = 20 +cc.Handler.EVENT_MOUSE_UP = 21 +cc.Handler.EVENT_MOUSE_MOVE = 22 +cc.Handler.EVENT_MOUSE_SCROLL = 23 +cc.Handler.EVENT_PHYSICS_CONTACT_BEGIN = 24 +cc.Handler.EVENT_PHYSICS_CONTACT_PRESOLVE = 25 +cc.Handler.EVENT_PHYSICS_CONTACT_POSTSOLVE = 26 +cc.Handler.EVENT_PHYSICS_CONTACT_SEPARATE = 27 +cc.Handler.EVENT_FOCUS = 28 +cc.Handler.EVENT_CONTROLLER_CONNECTED = 29 +cc.Handler.EVENT_CONTROLLER_DISCONNECTED = 30 +cc.Handler.EVENT_CONTROLLER_KEYDOWN = 31 +cc.Handler.EVENT_CONTROLLER_KEYUP = 32 +cc.Handler.EVENT_CONTROLLER_KEYREPEAT = 33 +cc.Handler.EVENT_CONTROLLER_AXIS = 34 +cc.Handler.EVENT_SPINE_ANIMATION_START = 35 +cc.Handler.EVENT_SPINE_ANIMATION_INTERRUPT = 36 +cc.Handler.EVENT_SPINE_ANIMATION_END = 37 +cc.Handler.EVENT_SPINE_ANIMATION_DISPOSE = 38 +cc.Handler.EVENT_SPINE_ANIMATION_COMPLETE = 39 +cc.Handler.EVENT_SPINE_ANIMATION_EVENT = 40 +cc.Handler.EVENT_SPINE_ANIMATION_PREUPDATE = 41 +cc.Handler.EVENT_SPINE_ANIMATION_POSTUPDATE = 42 cc.EVENT_UNKNOWN = 0 cc.EVENT_TOUCH_ONE_BY_ONE = 1