mirror of https://github.com/axmolengine/axmol.git
Reconstruct the operation of handling lua script event
This commit is contained in:
parent
9679b0c8a7
commit
756a72cbca
|
@ -210,8 +210,6 @@ enum ScriptEventType
|
||||||
kAccelerometerEvent,
|
kAccelerometerEvent,
|
||||||
kControlEvent,
|
kControlEvent,
|
||||||
kCommonEvent,
|
kCommonEvent,
|
||||||
kTableViewEvent,//Now it's only used in LuaBinding
|
|
||||||
kAssetsManagerEvent,//Now it's only used in Lua Binding
|
|
||||||
kCocoStudioEventListener,//Now it's only used in Lua Binding
|
kCocoStudioEventListener,//Now it's only used in Lua Binding
|
||||||
kArmatureWrapper,//Now it's only used in Lua Binding
|
kArmatureWrapper,//Now it's only used in Lua Binding
|
||||||
kEventListenerAcc,//Now it's only used in Lua Binding
|
kEventListenerAcc,//Now it's only used in Lua Binding
|
||||||
|
|
|
@ -27,7 +27,6 @@
|
||||||
#include "cocos2d.h"
|
#include "cocos2d.h"
|
||||||
#include "CCArray.h"
|
#include "CCArray.h"
|
||||||
#include "CCScheduler.h"
|
#include "CCScheduler.h"
|
||||||
#include "LuaScriptHandlerMgr.h"
|
|
||||||
#include "extensions/GUI/CCControlExtension/CCControl.h"
|
#include "extensions/GUI/CCControlExtension/CCControl.h"
|
||||||
#include "LuaOpengl.h"
|
#include "LuaOpengl.h"
|
||||||
#include "lua_cocos2dx_manual.hpp"
|
#include "lua_cocos2dx_manual.hpp"
|
||||||
|
@ -249,16 +248,6 @@ int LuaEngine::sendEvent(ScriptEvent* evt)
|
||||||
return handlerControlEvent(evt->data);
|
return handlerControlEvent(evt->data);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case kTableViewEvent:
|
|
||||||
{
|
|
||||||
return handleTableViewEvent(evt->data);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case kAssetsManagerEvent:
|
|
||||||
{
|
|
||||||
return handleAssetsManagerEvent(evt->data);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case kCocoStudioEventListener:
|
case kCocoStudioEventListener:
|
||||||
{
|
{
|
||||||
return handleCocoStudioEventListener(evt->data);
|
return handleCocoStudioEventListener(evt->data);
|
||||||
|
@ -622,51 +611,6 @@ int LuaEngine::handleTouchesEvent(void* data)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int LuaEngine::handleTableViewEvent(void* data)
|
|
||||||
{
|
|
||||||
if (nullptr == data)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
BasicScriptData* eventData = static_cast<BasicScriptData*>(data);
|
|
||||||
if (nullptr == eventData->nativeObject || nullptr == eventData->value)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
LuaTableViewEventData* tableViewEventData = static_cast<LuaTableViewEventData*>(eventData->value);
|
|
||||||
if (tableViewEventData->handlerType < ScriptHandlerMgr::HandlerType::SCROLLVIEW_SCROLL || tableViewEventData->handlerType > ScriptHandlerMgr::HandlerType::TABLEVIEW_NUMS_OF_CELLS )
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
int handler = ScriptHandlerMgr::getInstance()->getObjectHandler((void*)eventData->nativeObject, tableViewEventData->handlerType);
|
|
||||||
|
|
||||||
if (0 == handler)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
int ret = 0;
|
|
||||||
switch (tableViewEventData->handlerType)
|
|
||||||
{
|
|
||||||
case ScriptHandlerMgr::HandlerType::SCROLLVIEW_SCROLL:
|
|
||||||
case ScriptHandlerMgr::HandlerType::SCROLLVIEW_ZOOM:
|
|
||||||
{
|
|
||||||
_stack->pushObject(static_cast<Object*>(eventData->nativeObject), "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:
|
|
||||||
{
|
|
||||||
_stack->pushObject(static_cast<Object*>(eventData->nativeObject), "TableView");
|
|
||||||
_stack->pushObject(static_cast<Object*>(tableViewEventData->value), "TableViewCell");
|
|
||||||
ret = _stack->executeFunctionByHandler(handler, 2);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
int LuaEngine::handlerControlEvent(void* data)
|
int LuaEngine::handlerControlEvent(void* data)
|
||||||
{
|
{
|
||||||
if ( NULL == data )
|
if ( NULL == data )
|
||||||
|
@ -706,110 +650,9 @@ int LuaEngine::sendEventReturnArray(ScriptEvent* message,int numResults,Array& r
|
||||||
if (nullptr == message || numResults <= 0)
|
if (nullptr == message || numResults <= 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
switch (message->type)
|
|
||||||
{
|
|
||||||
case kTableViewEvent:
|
|
||||||
return handleTableViewEventReturnArray(message->data,numResults,resultArray);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int LuaEngine::handleTableViewEventReturnArray(void* data,int numResults,Array& resultArray)
|
|
||||||
{
|
|
||||||
if (nullptr == data || numResults <= 0)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
if (nullptr == data)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
BasicScriptData* eventData = static_cast<BasicScriptData*>(data);
|
|
||||||
if (nullptr == eventData->nativeObject || nullptr == eventData->value)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
LuaTableViewEventData* tableViewEventData = static_cast<LuaTableViewEventData*>(eventData->value);
|
|
||||||
if (tableViewEventData->handlerType < ScriptHandlerMgr::HandlerType::SCROLLVIEW_SCROLL || tableViewEventData->handlerType > ScriptHandlerMgr::HandlerType::TABLEVIEW_NUMS_OF_CELLS )
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
int handler = ScriptHandlerMgr::getInstance()->getObjectHandler((void*)eventData->nativeObject, tableViewEventData->handlerType);
|
|
||||||
|
|
||||||
if (0 == handler)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
int ret = 0;
|
|
||||||
switch (tableViewEventData->handlerType)
|
|
||||||
{
|
|
||||||
case ScriptHandlerMgr::HandlerType::TABLECELL_SIZE_FOR_INDEX:
|
|
||||||
{
|
|
||||||
_stack->pushObject(static_cast<Object*>(eventData->nativeObject), "TableView");
|
|
||||||
_stack->pushLong(*((long*)tableViewEventData->value));
|
|
||||||
ret = _stack->executeFunctionReturnArray(handler, 2, 2, resultArray);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case ScriptHandlerMgr::HandlerType::TABLECELL_AT_INDEX:
|
|
||||||
{
|
|
||||||
_stack->pushObject(static_cast<Object*>(eventData->nativeObject), "TableView");
|
|
||||||
_stack->pushLong(*((long*)tableViewEventData->value));
|
|
||||||
ret = _stack->executeFunctionReturnArray(handler, 2, 1, resultArray);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case ScriptHandlerMgr::HandlerType::TABLEVIEW_NUMS_OF_CELLS:
|
|
||||||
{
|
|
||||||
_stack->pushObject(static_cast<Object*>(eventData->nativeObject), "TableView");
|
|
||||||
ret = _stack->executeFunctionReturnArray(handler, 1, 1, resultArray);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
int LuaEngine::handleAssetsManagerEvent(void* data)
|
|
||||||
{
|
|
||||||
if (nullptr == data)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
BasicScriptData* eventData = static_cast<BasicScriptData*>(data);
|
|
||||||
if (nullptr == eventData->nativeObject || nullptr == eventData->value)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
LuaAssetsManagerEventData* assetsManagerEventData = static_cast<LuaAssetsManagerEventData*>(eventData->value);
|
|
||||||
if (assetsManagerEventData->handlerType < ScriptHandlerMgr::HandlerType::ASSETSMANAGER_PROGRESS || assetsManagerEventData->handlerType > ScriptHandlerMgr::HandlerType::ASSETSMANAGER_ERROR )
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
int handler = ScriptHandlerMgr::getInstance()->getObjectHandler((void*)eventData->nativeObject, assetsManagerEventData->handlerType);
|
|
||||||
|
|
||||||
if (0 == handler)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
int ret = 0;
|
|
||||||
switch (assetsManagerEventData->handlerType)
|
|
||||||
{
|
|
||||||
case ScriptHandlerMgr::HandlerType::ASSETSMANAGER_PROGRESS:
|
|
||||||
case ScriptHandlerMgr::HandlerType::ASSETSMANAGER_ERROR:
|
|
||||||
{
|
|
||||||
_stack->pushInt(assetsManagerEventData->value);
|
|
||||||
ret = _stack->executeFunctionByHandler(handler, 1);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case ScriptHandlerMgr::HandlerType::ASSETSMANAGER_SUCCESS:
|
|
||||||
{
|
|
||||||
ret = _stack->executeFunctionByHandler(handler, 0);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
int LuaEngine::handleCocoStudioEventListener(void* data)
|
int LuaEngine::handleCocoStudioEventListener(void* data)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -1046,4 +889,190 @@ int LuaEngine::handleEventListenerCustom(void* data)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int LuaEngine::handleEvent(ScriptHandlerMgr::HandlerType type, void* data, int numResults, const std::function<void(lua_State*,int)>& func)
|
||||||
|
{
|
||||||
|
switch (type)
|
||||||
|
{
|
||||||
|
case ScriptHandlerMgr::HandlerType::TABLECELL_SIZE_FOR_INDEX:
|
||||||
|
case ScriptHandlerMgr::HandlerType::TABLECELL_AT_INDEX:
|
||||||
|
case ScriptHandlerMgr::HandlerType::TABLEVIEW_NUMS_OF_CELLS:
|
||||||
|
{
|
||||||
|
return handlerTableViewEvent(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<BasicScriptData*>(data);
|
||||||
|
if (nullptr == eventData->nativeObject || nullptr == eventData->value)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
LuaTableViewEventData* tableViewData = static_cast<LuaTableViewEventData*>(eventData->value);
|
||||||
|
int handler = ScriptHandlerMgr::getInstance()->getObjectHandler((void*)eventData->nativeObject, type);
|
||||||
|
|
||||||
|
if (0 == handler)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
Object* obj = static_cast<Object*>(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),"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:
|
||||||
|
{
|
||||||
|
Object* cellObject = static_cast<Object*>(tableViewData->value);
|
||||||
|
if (nullptr == cellObject) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
toluafix_pushusertype_ccobject(_stack->getLuaState(), obj->_ID, &(obj->_luaID), (void*)(obj),"TableView");
|
||||||
|
toluafix_pushusertype_ccobject(_stack->getLuaState(), cellObject->_ID, &(cellObject->_luaID), (void*)(cellObject),"TableViewCell");
|
||||||
|
ret = _stack->executeFunctionByHandler(handler, 2);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int LuaEngine::handlerTableViewEvent(ScriptHandlerMgr::HandlerType handlerType,void* data, int numResults, const std::function<void(lua_State*,int)> func)
|
||||||
|
{
|
||||||
|
if (nullptr == data || numResults <= 0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
BasicScriptData* eventData = static_cast<BasicScriptData*>(data);
|
||||||
|
if (nullptr == eventData->nativeObject || nullptr == eventData->value)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
LuaTableViewEventData* tableViewData = static_cast<LuaTableViewEventData*>(eventData->value);
|
||||||
|
int handler = ScriptHandlerMgr::getInstance()->getObjectHandler((void*)eventData->nativeObject, handlerType);
|
||||||
|
|
||||||
|
if (0 == handler)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
Object* obj = static_cast<Object*>(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),"TableView");
|
||||||
|
_stack->pushLong(*((long*)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),"TableView");
|
||||||
|
_stack->pushLong(*((long*)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),"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<BasicScriptData*>(data);
|
||||||
|
if (nullptr == eventData->nativeObject || nullptr == eventData->value)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
LuaAssetsManagerEventData* assetsManagerData = static_cast<LuaAssetsManagerEventData*>(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;
|
||||||
|
}
|
||||||
|
|
||||||
NS_CC_END
|
NS_CC_END
|
||||||
|
|
|
@ -33,6 +33,7 @@ extern "C" {
|
||||||
#include "CCScriptSupport.h"
|
#include "CCScriptSupport.h"
|
||||||
#include "CCLuaStack.h"
|
#include "CCLuaStack.h"
|
||||||
#include "CCLuaValue.h"
|
#include "CCLuaValue.h"
|
||||||
|
#include "LuaScriptHandlerMgr.h"
|
||||||
|
|
||||||
NS_CC_BEGIN
|
NS_CC_BEGIN
|
||||||
|
|
||||||
|
@ -117,6 +118,8 @@ public:
|
||||||
|
|
||||||
virtual int sendEvent(ScriptEvent* message);
|
virtual int sendEvent(ScriptEvent* message);
|
||||||
virtual int sendEventReturnArray(ScriptEvent* message,int numResults,Array& resultArray);
|
virtual int sendEventReturnArray(ScriptEvent* message,int numResults,Array& resultArray);
|
||||||
|
virtual int handleEvent(ScriptHandlerMgr::HandlerType type,void* data);
|
||||||
|
virtual int handleEvent(ScriptHandlerMgr::HandlerType type, void* data, int numResults, const std::function<void(lua_State*,int)>& func);
|
||||||
private:
|
private:
|
||||||
LuaEngine(void)
|
LuaEngine(void)
|
||||||
: _stack(NULL)
|
: _stack(NULL)
|
||||||
|
@ -134,9 +137,6 @@ private:
|
||||||
int handleTouchEvent(void* data);
|
int handleTouchEvent(void* data);
|
||||||
int handleTouchesEvent(void* data);
|
int handleTouchesEvent(void* data);
|
||||||
int handlerControlEvent(void* data);
|
int handlerControlEvent(void* data);
|
||||||
int handleTableViewEvent(void* data);
|
|
||||||
int handleTableViewEventReturnArray(void* data,int numResults,Array& resultArray);
|
|
||||||
int handleAssetsManagerEvent(void* data);
|
|
||||||
int handleCocoStudioEventListener(void* data);
|
int handleCocoStudioEventListener(void* data);
|
||||||
int handleArmatureWrapper(void* data);
|
int handleArmatureWrapper(void* data);
|
||||||
int handleEventListenerAcc(void* data);
|
int handleEventListenerAcc(void* data);
|
||||||
|
@ -145,6 +145,10 @@ private:
|
||||||
int handleEventListenerTouches(void* data);
|
int handleEventListenerTouches(void* data);
|
||||||
int handleEventListenerMouse(void* data);
|
int handleEventListenerMouse(void* data);
|
||||||
int handleEventListenerCustom(void* data);
|
int handleEventListenerCustom(void* data);
|
||||||
|
|
||||||
|
int handleAssetsManagerEvent(ScriptHandlerMgr::HandlerType type,void* data);
|
||||||
|
int handleTableViewEvent(ScriptHandlerMgr::HandlerType type,void* data);
|
||||||
|
int handlerTableViewEvent(ScriptHandlerMgr::HandlerType type,void* data, int numResults, const std::function<void(lua_State*,int)> func);
|
||||||
private:
|
private:
|
||||||
static LuaEngine* _defaultEngine;
|
static LuaEngine* _defaultEngine;
|
||||||
LuaStack *_stack;
|
LuaStack *_stack;
|
||||||
|
|
|
@ -577,4 +577,73 @@ int LuaStack::executeFunctionReturnArray(int handler,int numArgs,int numResults,
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int LuaStack::executeFunction(int handler, int numArgs, int numResults, const std::function<void(lua_State*,int)>& func)
|
||||||
|
{
|
||||||
|
if (pushFunctionByHandler(handler)) /* L: ... arg1 arg2 ... func */
|
||||||
|
{
|
||||||
|
if (numArgs > 0)
|
||||||
|
{
|
||||||
|
lua_insert(_state, -(numArgs + 1)); /* L: ... func arg1 arg2 ... */
|
||||||
|
}
|
||||||
|
|
||||||
|
int functionIndex = -(numArgs + 1);
|
||||||
|
|
||||||
|
if (!lua_isfunction(_state, functionIndex))
|
||||||
|
{
|
||||||
|
CCLOG("value at stack [%d] is not function", functionIndex);
|
||||||
|
lua_pop(_state, numArgs + 1); // remove function and arguments
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int traceCallback = 0;
|
||||||
|
lua_getglobal(_state, "__G__TRACKBACK__"); /* L: ... func arg1 arg2 ... G */
|
||||||
|
if (!lua_isfunction(_state, -1))
|
||||||
|
{
|
||||||
|
lua_pop(_state, 1); /* L: ... func arg1 arg2 ... */
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
lua_insert(_state, functionIndex - 1); /* L: ... G func arg1 arg2 ... */
|
||||||
|
traceCallback = functionIndex - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int error = 0;
|
||||||
|
++_callFromLua;
|
||||||
|
error = lua_pcall(_state, numArgs, numResults, traceCallback); /* L: ... [G] ret1 ret2 ... retResults*/
|
||||||
|
--_callFromLua;
|
||||||
|
|
||||||
|
if (error)
|
||||||
|
{
|
||||||
|
if (traceCallback == 0)
|
||||||
|
{
|
||||||
|
CCLOG("[LUA ERROR] %s", lua_tostring(_state, - 1)); /* L: ... error */
|
||||||
|
lua_pop(_state, 1); // remove error message from stack
|
||||||
|
}
|
||||||
|
else /* L: ... G error */
|
||||||
|
{
|
||||||
|
lua_pop(_state, 2); // remove __G__TRACKBACK__ and error message from stack
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// get return value,don't pass LUA_MULTRET to numResults,
|
||||||
|
if (numResults <= 0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if (nullptr == func)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
func(_state,numResults);
|
||||||
|
|
||||||
|
if (traceCallback)
|
||||||
|
{
|
||||||
|
lua_pop(_state, 1); // remove __G__TRACKBACK__ from stack /* L: ... */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
lua_settop(_state, 0);
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
NS_CC_END
|
NS_CC_END
|
||||||
|
|
|
@ -116,6 +116,7 @@ public:
|
||||||
|
|
||||||
virtual int executeFunctionByHandler(int nHandler, int numArgs);
|
virtual int executeFunctionByHandler(int nHandler, int numArgs);
|
||||||
virtual int executeFunctionReturnArray(int handler,int numArgs,int numResults,Array& resultArray);
|
virtual int executeFunctionReturnArray(int handler,int numArgs,int numResults,Array& resultArray);
|
||||||
|
virtual int executeFunction(int handler, int numArgs, int numResults, const std::function<void(lua_State*,int)>& func);
|
||||||
|
|
||||||
virtual bool handleAssert(const char *msg);
|
virtual bool handleAssert(const char *msg);
|
||||||
|
|
||||||
|
|
|
@ -877,10 +877,9 @@ public:
|
||||||
int handler = ScriptHandlerMgr::getInstance()->getObjectHandler((void*)view, ScriptHandlerMgr::HandlerType::SCROLLVIEW_SCROLL);
|
int handler = ScriptHandlerMgr::getInstance()->getObjectHandler((void*)view, ScriptHandlerMgr::HandlerType::SCROLLVIEW_SCROLL);
|
||||||
if (0 != handler)
|
if (0 != handler)
|
||||||
{
|
{
|
||||||
LuaTableViewEventData eventData(ScriptHandlerMgr::HandlerType::SCROLLVIEW_SCROLL);
|
LuaTableViewEventData eventData;
|
||||||
BasicScriptData data(view,&eventData);
|
BasicScriptData data(view,&eventData);
|
||||||
ScriptEvent event(kTableViewEvent,(void*)&data);
|
LuaEngine::getInstance()->handleEvent(ScriptHandlerMgr::HandlerType::SCROLLVIEW_SCROLL, (void*)&data);
|
||||||
LuaEngine::getInstance()->sendEvent(&event);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -892,10 +891,9 @@ public:
|
||||||
int handler = ScriptHandlerMgr::getInstance()->getObjectHandler((void*)view, ScriptHandlerMgr::HandlerType::SCROLLVIEW_ZOOM);
|
int handler = ScriptHandlerMgr::getInstance()->getObjectHandler((void*)view, ScriptHandlerMgr::HandlerType::SCROLLVIEW_ZOOM);
|
||||||
if (0 != handler)
|
if (0 != handler)
|
||||||
{
|
{
|
||||||
LuaTableViewEventData eventData(ScriptHandlerMgr::HandlerType::SCROLLVIEW_ZOOM);
|
LuaTableViewEventData eventData;
|
||||||
BasicScriptData data(view,&eventData);
|
BasicScriptData data(view,&eventData);
|
||||||
ScriptEvent event(kTableViewEvent,(void*)&data);
|
LuaEngine::getInstance()->handleEvent(ScriptHandlerMgr::HandlerType::SCROLLVIEW_ZOOM, (void*)&data);
|
||||||
LuaEngine::getInstance()->sendEvent(&event);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -907,10 +905,9 @@ public:
|
||||||
int handler = ScriptHandlerMgr::getInstance()->getObjectHandler((void*)table, ScriptHandlerMgr::HandlerType::TABLECELL_TOUCHED);
|
int handler = ScriptHandlerMgr::getInstance()->getObjectHandler((void*)table, ScriptHandlerMgr::HandlerType::TABLECELL_TOUCHED);
|
||||||
if (0 != handler)
|
if (0 != handler)
|
||||||
{
|
{
|
||||||
LuaTableViewEventData eventData(ScriptHandlerMgr::HandlerType::TABLECELL_TOUCHED,cell);
|
LuaTableViewEventData eventData(cell);
|
||||||
BasicScriptData data(table,&eventData);
|
BasicScriptData data(table,&eventData);
|
||||||
ScriptEvent event(kTableViewEvent,(void*)&data);
|
LuaEngine::getInstance()->handleEvent(ScriptHandlerMgr::HandlerType::TABLECELL_TOUCHED,(void*)&data);
|
||||||
LuaEngine::getInstance()->sendEvent(&event);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -922,10 +919,9 @@ public:
|
||||||
int handler = ScriptHandlerMgr::getInstance()->getObjectHandler((void*)table, ScriptHandlerMgr::HandlerType::TABLECELL_HIGHLIGHT);
|
int handler = ScriptHandlerMgr::getInstance()->getObjectHandler((void*)table, ScriptHandlerMgr::HandlerType::TABLECELL_HIGHLIGHT);
|
||||||
if (0 != handler)
|
if (0 != handler)
|
||||||
{
|
{
|
||||||
LuaTableViewEventData eventData(ScriptHandlerMgr::HandlerType::TABLECELL_HIGHLIGHT,cell);
|
LuaTableViewEventData eventData(cell);
|
||||||
BasicScriptData data(table,&eventData);
|
BasicScriptData data(table,&eventData);
|
||||||
ScriptEvent event(kTableViewEvent,(void*)&data);
|
LuaEngine::getInstance()->handleEvent(ScriptHandlerMgr::HandlerType::TABLECELL_HIGHLIGHT,(void*)&data);
|
||||||
LuaEngine::getInstance()->sendEvent(&event);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -937,10 +933,9 @@ public:
|
||||||
int handler = ScriptHandlerMgr::getInstance()->getObjectHandler((void*)table, ScriptHandlerMgr::HandlerType::TABLECELL_UNHIGHLIGHT);
|
int handler = ScriptHandlerMgr::getInstance()->getObjectHandler((void*)table, ScriptHandlerMgr::HandlerType::TABLECELL_UNHIGHLIGHT);
|
||||||
if (0 != handler)
|
if (0 != handler)
|
||||||
{
|
{
|
||||||
LuaTableViewEventData eventData(ScriptHandlerMgr::HandlerType::TABLECELL_UNHIGHLIGHT,cell);
|
LuaTableViewEventData eventData(cell);
|
||||||
BasicScriptData data(table,&eventData);
|
BasicScriptData data(table,&eventData);
|
||||||
ScriptEvent event(kTableViewEvent,(void*)&data);
|
LuaEngine::getInstance()->handleEvent(ScriptHandlerMgr::HandlerType::TABLECELL_UNHIGHLIGHT,(void*)&data);
|
||||||
LuaEngine::getInstance()->sendEvent(&event);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -952,10 +947,9 @@ public:
|
||||||
int handler = ScriptHandlerMgr::getInstance()->getObjectHandler((void*)table, ScriptHandlerMgr::HandlerType::TABLECELL_WILL_RECYCLE);
|
int handler = ScriptHandlerMgr::getInstance()->getObjectHandler((void*)table, ScriptHandlerMgr::HandlerType::TABLECELL_WILL_RECYCLE);
|
||||||
if (0 != handler)
|
if (0 != handler)
|
||||||
{
|
{
|
||||||
LuaTableViewEventData eventData(ScriptHandlerMgr::HandlerType::TABLECELL_WILL_RECYCLE,cell);
|
LuaTableViewEventData eventData(cell);
|
||||||
BasicScriptData data(table,&eventData);
|
BasicScriptData data(table,&eventData);
|
||||||
ScriptEvent event(kTableViewEvent,(void*)&data);
|
LuaEngine::getInstance()->handleEvent(ScriptHandlerMgr::HandlerType::TABLECELL_WILL_RECYCLE,(void*)&data);
|
||||||
LuaEngine::getInstance()->sendEvent(&event);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1033,19 +1027,20 @@ public:
|
||||||
int handler = ScriptHandlerMgr::getInstance()->getObjectHandler((void*)table, ScriptHandlerMgr::HandlerType::TABLECELL_SIZE_FOR_INDEX);
|
int handler = ScriptHandlerMgr::getInstance()->getObjectHandler((void*)table, ScriptHandlerMgr::HandlerType::TABLECELL_SIZE_FOR_INDEX);
|
||||||
if (0 != handler)
|
if (0 != handler)
|
||||||
{
|
{
|
||||||
Array resultArray;
|
LuaTableViewEventData eventData(&idx);
|
||||||
resultArray.initWithCapacity(1);
|
|
||||||
LuaTableViewEventData eventData(ScriptHandlerMgr::HandlerType::TABLECELL_SIZE_FOR_INDEX,&idx);
|
|
||||||
BasicScriptData data(table,&eventData);
|
BasicScriptData data(table,&eventData);
|
||||||
ScriptEvent event(kTableViewEvent,(void*)&data);
|
float width = 0.0;
|
||||||
LuaEngine::getInstance()->sendEventReturnArray(&event, 2, resultArray);
|
float height = 0.0;
|
||||||
CCASSERT(resultArray.count() == 2, "tableCellSizeForIndex Array count error");
|
LuaEngine::getInstance()->handleEvent(ScriptHandlerMgr::HandlerType::TABLECELL_SIZE_FOR_INDEX, (void*)&data,2,[&](lua_State* L,int numReturn){
|
||||||
Double* width = dynamic_cast<Double*>(resultArray.getObjectAtIndex(0));
|
CCASSERT(numReturn == 2, "tableCellSizeForIndex return count error");
|
||||||
Double* height = dynamic_cast<Double*>(resultArray.getObjectAtIndex(1));
|
ValueVector vec;
|
||||||
if (nullptr != width && nullptr != height)
|
width = (float)tolua_tonumber(L, -1, 0);
|
||||||
{
|
lua_pop(L, 1);
|
||||||
return Size((float)width->getValue(), (float)height->getValue());
|
height = (float)tolua_tonumber(L, -1, 0);
|
||||||
}
|
lua_pop(L, 1);
|
||||||
|
});
|
||||||
|
|
||||||
|
return Size(width, height);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1059,17 +1054,14 @@ public:
|
||||||
int handler = ScriptHandlerMgr::getInstance()->getObjectHandler((void*)table, ScriptHandlerMgr::HandlerType::TABLECELL_AT_INDEX);
|
int handler = ScriptHandlerMgr::getInstance()->getObjectHandler((void*)table, ScriptHandlerMgr::HandlerType::TABLECELL_AT_INDEX);
|
||||||
if (0 != handler)
|
if (0 != handler)
|
||||||
{
|
{
|
||||||
Array resultArray;
|
LuaTableViewEventData eventData(&idx);
|
||||||
resultArray.initWithCapacity(1);
|
|
||||||
LuaTableViewEventData eventData(ScriptHandlerMgr::HandlerType::TABLECELL_AT_INDEX,&idx);
|
|
||||||
BasicScriptData data(table,&eventData);
|
BasicScriptData data(table,&eventData);
|
||||||
ScriptEvent event(kTableViewEvent,(void*)&data);
|
|
||||||
LuaEngine::getInstance()->sendEventReturnArray(&event, 1, resultArray);
|
|
||||||
TableViewCell* viewCell = nullptr;
|
TableViewCell* viewCell = nullptr;
|
||||||
if (resultArray.count() > 0)
|
LuaEngine::getInstance()->handleEvent(ScriptHandlerMgr::HandlerType::TABLECELL_AT_INDEX, (void*)&data, 1, [&](lua_State* L, int numReturn){
|
||||||
{
|
CCASSERT(numReturn == 1, "tableCellAtIndex return count error");
|
||||||
viewCell = dynamic_cast<TableViewCell*>(resultArray.getObjectAtIndex(0));
|
viewCell = static_cast<TableViewCell*>(tolua_tousertype(L, -1, nullptr));
|
||||||
}
|
lua_pop(L, 1);
|
||||||
|
});
|
||||||
|
|
||||||
return viewCell;
|
return viewCell;
|
||||||
}
|
}
|
||||||
|
@ -1085,17 +1077,15 @@ public:
|
||||||
int handler = ScriptHandlerMgr::getInstance()->getObjectHandler((void*)table, ScriptHandlerMgr::HandlerType::TABLEVIEW_NUMS_OF_CELLS);
|
int handler = ScriptHandlerMgr::getInstance()->getObjectHandler((void*)table, ScriptHandlerMgr::HandlerType::TABLEVIEW_NUMS_OF_CELLS);
|
||||||
if (0 != handler)
|
if (0 != handler)
|
||||||
{
|
{
|
||||||
Array resultArray;
|
LuaTableViewEventData eventData;
|
||||||
resultArray.initWithCapacity(1);
|
|
||||||
LuaTableViewEventData eventData(ScriptHandlerMgr::HandlerType::TABLEVIEW_NUMS_OF_CELLS);
|
|
||||||
BasicScriptData data(table,&eventData);
|
BasicScriptData data(table,&eventData);
|
||||||
ScriptEvent event(kTableViewEvent,(void*)&data);
|
long counts = 0;
|
||||||
LuaEngine::getInstance()->sendEventReturnArray(&event, 1, resultArray);
|
LuaEngine::getInstance()->handleEvent(ScriptHandlerMgr::HandlerType::TABLEVIEW_NUMS_OF_CELLS, (void*)&data,1, [&](lua_State* L, int numReturn){
|
||||||
Double* numbers = dynamic_cast<Double*>(resultArray.getObjectAtIndex(0));
|
CCASSERT(numReturn == 1, "numberOfCellsInTableView return count error");
|
||||||
if (NULL != numbers)
|
counts = (long)tolua_tonumber(L, -1, 0);
|
||||||
{
|
lua_pop(L, 1);
|
||||||
return (long)numbers->getValue();
|
});
|
||||||
}
|
return counts;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -1444,10 +1434,9 @@ public:
|
||||||
int handler = ScriptHandlerMgr::getInstance()->getObjectHandler((void*)this, ScriptHandlerMgr::HandlerType::ASSETSMANAGER_PROGRESS);
|
int handler = ScriptHandlerMgr::getInstance()->getObjectHandler((void*)this, ScriptHandlerMgr::HandlerType::ASSETSMANAGER_PROGRESS);
|
||||||
if (0 != handler)
|
if (0 != handler)
|
||||||
{
|
{
|
||||||
LuaAssetsManagerEventData eventData(ScriptHandlerMgr::HandlerType::ASSETSMANAGER_PROGRESS,percent);
|
LuaAssetsManagerEventData eventData(percent);
|
||||||
BasicScriptData data((void*)this,&eventData);
|
BasicScriptData data((void*)this,&eventData);
|
||||||
ScriptEvent event(kAssetsManagerEvent,(void*)&data);
|
LuaEngine::getInstance()->handleEvent(ScriptHandlerMgr::HandlerType::ASSETSMANAGER_PROGRESS, (void*)&data);
|
||||||
LuaEngine::getInstance()->sendEvent(&event);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1456,10 +1445,9 @@ public:
|
||||||
int handler = ScriptHandlerMgr::getInstance()->getObjectHandler((void*)this, ScriptHandlerMgr::HandlerType::ASSETSMANAGER_SUCCESS);
|
int handler = ScriptHandlerMgr::getInstance()->getObjectHandler((void*)this, ScriptHandlerMgr::HandlerType::ASSETSMANAGER_SUCCESS);
|
||||||
if (0 != handler)
|
if (0 != handler)
|
||||||
{
|
{
|
||||||
LuaAssetsManagerEventData eventData(ScriptHandlerMgr::HandlerType::ASSETSMANAGER_SUCCESS);
|
LuaAssetsManagerEventData eventData;
|
||||||
BasicScriptData data((void*)this,&eventData);
|
BasicScriptData data((void*)this,&eventData);
|
||||||
ScriptEvent event(kAssetsManagerEvent,(void*)&data);
|
LuaEngine::getInstance()->handleEvent(ScriptHandlerMgr::HandlerType::ASSETSMANAGER_SUCCESS, (void*)&data);
|
||||||
LuaEngine::getInstance()->sendEvent(&event);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1468,10 +1456,9 @@ public:
|
||||||
int handler = ScriptHandlerMgr::getInstance()->getObjectHandler((void*)this, ScriptHandlerMgr::HandlerType::ASSETSMANAGER_ERROR);
|
int handler = ScriptHandlerMgr::getInstance()->getObjectHandler((void*)this, ScriptHandlerMgr::HandlerType::ASSETSMANAGER_ERROR);
|
||||||
if (0 != handler)
|
if (0 != handler)
|
||||||
{
|
{
|
||||||
LuaAssetsManagerEventData eventData(ScriptHandlerMgr::HandlerType::ASSETSMANAGER_ERROR, (int)errorCode);
|
LuaAssetsManagerEventData eventData((int)errorCode);
|
||||||
BasicScriptData data((void*)this,&eventData);
|
BasicScriptData data((void*)this,&eventData);
|
||||||
ScriptEvent event(kAssetsManagerEvent,(void*)&data);
|
LuaEngine::getInstance()->handleEvent(ScriptHandlerMgr::HandlerType::ASSETSMANAGER_ERROR, (void*)&data);
|
||||||
LuaEngine::getInstance()->sendEvent(&event);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -16,22 +16,20 @@ TOLUA_API int register_cocos2dx_extension_CCBProxy(lua_State* tolua_S);
|
||||||
|
|
||||||
struct LuaTableViewEventData
|
struct LuaTableViewEventData
|
||||||
{
|
{
|
||||||
cocos2d::ScriptHandlerMgr::HandlerType handlerType;
|
|
||||||
void* value;
|
void* value;
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
LuaTableViewEventData(cocos2d::ScriptHandlerMgr::HandlerType _handleType,void* _value = nullptr)
|
LuaTableViewEventData(void* _value = nullptr)
|
||||||
: handlerType(_handleType),value(_value)
|
:value(_value)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct LuaAssetsManagerEventData
|
struct LuaAssetsManagerEventData
|
||||||
{
|
{
|
||||||
cocos2d::ScriptHandlerMgr::HandlerType handlerType;
|
|
||||||
int value;
|
int value;
|
||||||
|
|
||||||
LuaAssetsManagerEventData(cocos2d::ScriptHandlerMgr::HandlerType _handleType, int _value = 0):handlerType(_handleType),value(_value)
|
LuaAssetsManagerEventData(int _value = 0):value(_value)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue