cocos2d-x  3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ScriptHandlerMgr Class Reference

In order to reduce the coupling of lua script engine and native c++ engine. More...

#include <LuaScriptHandlerMgr.h>

Public Types

enum  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, WEBSOCKET_CLOSE, WEBSOCKET_ERROR,
  GL_NODE_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, EVENT_CUSTIOM, EVENT_KEYBOARD_PRESSED, EVENT_KEYBOARD_RELEASED,
  EVENT_TOUCH_BEGAN, EVENT_TOUCH_MOVED, EVENT_TOUCH_ENDED, EVENT_TOUCH_CANCELLED,
  EVENT_TOUCHES_BEGAN, EVENT_TOUCHES_MOVED, EVENT_TOUCHES_ENDED, EVENT_TOUCHES_CANCELLED,
  EVENT_MOUSE_DOWN, EVENT_MOUSE_UP, EVENT_MOUSE_MOVE, EVENT_MOUSE_SCROLL,
  EVENT_SPINE, EVENT_PHYSICS_CONTACT_BEGIN, EVENT_PHYSICS_CONTACT_PRESOLVE, EVENT_PHYSICS_CONTACT_POSTSOLVE,
  EVENT_PHYSICS_CONTACT_SEPERATE, EVENT_FOCUS, EVENT_CONTROLLER_CONNECTED, EVENT_CONTROLLER_DISCONNECTED,
  EVENT_CONTROLLER_KEYDOWN, EVENT_CONTROLLER_KEYUP, EVENT_CONTROLLER_KEYREPEAT, EVENT_CONTROLLER_AXIS,
  EVENT_SPINE_ANIMATION_START, EVENT_SPINE_ANIMATION_END, EVENT_SPINE_ANIMATION_COMPLETE, EVENT_SPINE_ANIMATION_EVENT,
  EVENT_CUSTOM_BEGAN = 10000, EVENT_CUSTOM_ENDED = 11000
}
 HandlerType enum. More...
 

Public Member Functions

 ScriptHandlerMgr (void)
 ! More...
 
virtual ~ScriptHandlerMgr (void)
 Destructor. More...
 
var ~ScriptHandlerMgr ()
 Destructor. More...
 
void addObjectHandler (void *object, int handler, ScriptHandlerMgr::HandlerType handlerType)
 Construct or update the mapping relationship among c++ Ref object ,HandlerType and the refrence index corresponding to the pointer of Lua function. More...
 
void removeObjectHandler (void *object, ScriptHandlerMgr::HandlerType handlerType)
 By the handlerType and object, find the correct refrence index corresponding to the pointer of Lua function. More...
 
int getObjectHandler (void *object, ScriptHandlerMgr::HandlerType handlerType)
 By the handlerType and object, find the correct refrence index corresponding to the pointer of Lua function. More...
 
void removeObjectAllHandlers (void *object)
 Remove the all relationship among the object, HandlerType and the refrence index corresponding to the pointer of Lua function. More...
 
ScriptHandlerMgr::HandlerType addCustomHandler (void *object, int handler)
 Add customizable relationship among c++ Ref object, HandlerType and the refrence index corresponding to the pointer of Lua function. More...
 
local addCustomHandler ( local object, local handler)
 Add customizable relationship among c++ Ref object, HandlerType and the refrence index corresponding to the pointer of Lua function. More...
 

Static Public Member Functions

static ScriptHandlerMgrgetInstance (void)
 Get the instance of the ScriptHandlerMgr. More...
 
local getInstance ()
 Get the instance of the ScriptHandlerMgr. More...
 
static void destroyInstance (void)
 Destroy the instance of the ScriptHandlerMgr. More...
 
var destroyInstance ()
 Destroy the instance of the ScriptHandlerMgr. More...
 
local destroyInstance ()
 Destroy the instance of the ScriptHandlerMgr. More...
 

Detailed Description

In order to reduce the coupling of lua script engine and native c++ engine.

In the current mechanism, for the class derived frome the Ref, we constuct a mapping relationship among c++ Ref object ,HandlerType and the refrence index corresponding to the pointer of Lua function.Then, using the ScriptHandlerMgr to manager uniformly. By this mechanism,when native c++ Ref object wants to call the Lua function, we didn't insert the processing code in the native c++ class.

Member Enumeration Documentation

enum HandlerType : int
strong

HandlerType enum.

This enum class represent the processing type for c++ call the Lua function.

Enumerator
NODE 
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 
WEBSOCKET_CLOSE 
WEBSOCKET_ERROR 
GL_NODE_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 
EVENT_CUSTIOM 
EVENT_KEYBOARD_PRESSED 
EVENT_KEYBOARD_RELEASED 
EVENT_TOUCH_BEGAN 
EVENT_TOUCH_MOVED 
EVENT_TOUCH_ENDED 
EVENT_TOUCH_CANCELLED 
EVENT_TOUCHES_BEGAN 
EVENT_TOUCHES_MOVED 
EVENT_TOUCHES_ENDED 
EVENT_TOUCHES_CANCELLED 
EVENT_MOUSE_DOWN 
EVENT_MOUSE_UP 
EVENT_MOUSE_MOVE 
EVENT_MOUSE_SCROLL 
EVENT_SPINE 
EVENT_PHYSICS_CONTACT_BEGIN 
EVENT_PHYSICS_CONTACT_PRESOLVE 
EVENT_PHYSICS_CONTACT_POSTSOLVE 
EVENT_PHYSICS_CONTACT_SEPERATE 
EVENT_FOCUS 
EVENT_CONTROLLER_CONNECTED 
EVENT_CONTROLLER_DISCONNECTED 
EVENT_CONTROLLER_KEYDOWN 
EVENT_CONTROLLER_KEYUP 
EVENT_CONTROLLER_KEYREPEAT 
EVENT_CONTROLLER_AXIS 
EVENT_SPINE_ANIMATION_START 
EVENT_SPINE_ANIMATION_END 
EVENT_SPINE_ANIMATION_COMPLETE 
EVENT_SPINE_ANIMATION_EVENT 
EVENT_CUSTOM_BEGAN 
EVENT_CUSTOM_ENDED 
var int
strong

HandlerType enum.

This enum class represent the processing type for c++ call the Lua function.

Enumerator
NODE 
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 
WEBSOCKET_CLOSE 
WEBSOCKET_ERROR 
GL_NODE_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 
EVENT_CUSTIOM 
EVENT_KEYBOARD_PRESSED 
EVENT_KEYBOARD_RELEASED 
EVENT_TOUCH_BEGAN 
EVENT_TOUCH_MOVED 
EVENT_TOUCH_ENDED 
EVENT_TOUCH_CANCELLED 
EVENT_TOUCHES_BEGAN 
EVENT_TOUCHES_MOVED 
EVENT_TOUCHES_ENDED 
EVENT_TOUCHES_CANCELLED 
EVENT_MOUSE_DOWN 
EVENT_MOUSE_UP 
EVENT_MOUSE_MOVE 
EVENT_MOUSE_SCROLL 
EVENT_SPINE 
EVENT_PHYSICS_CONTACT_BEGIN 
EVENT_PHYSICS_CONTACT_PRESOLVE 
EVENT_PHYSICS_CONTACT_POSTSOLVE 
EVENT_PHYSICS_CONTACT_SEPERATE 
EVENT_FOCUS 
EVENT_CONTROLLER_CONNECTED 
EVENT_CONTROLLER_DISCONNECTED 
EVENT_CONTROLLER_KEYDOWN 
EVENT_CONTROLLER_KEYUP 
EVENT_CONTROLLER_KEYREPEAT 
EVENT_CONTROLLER_AXIS 
EVENT_SPINE_ANIMATION_START 
EVENT_SPINE_ANIMATION_END 
EVENT_SPINE_ANIMATION_COMPLETE 
EVENT_SPINE_ANIMATION_EVENT 
EVENT_CUSTOM_BEGAN 
EVENT_CUSTOM_ENDED 
local int
strong

HandlerType enum.

This enum class represent the processing type for c++ call the Lua function.

Enumerator
NODE 
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 
WEBSOCKET_CLOSE 
WEBSOCKET_ERROR 
GL_NODE_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 
EVENT_CUSTIOM 
EVENT_KEYBOARD_PRESSED 
EVENT_KEYBOARD_RELEASED 
EVENT_TOUCH_BEGAN 
EVENT_TOUCH_MOVED 
EVENT_TOUCH_ENDED 
EVENT_TOUCH_CANCELLED 
EVENT_TOUCHES_BEGAN 
EVENT_TOUCHES_MOVED 
EVENT_TOUCHES_ENDED 
EVENT_TOUCHES_CANCELLED 
EVENT_MOUSE_DOWN 
EVENT_MOUSE_UP 
EVENT_MOUSE_MOVE 
EVENT_MOUSE_SCROLL 
EVENT_SPINE 
EVENT_PHYSICS_CONTACT_BEGIN 
EVENT_PHYSICS_CONTACT_PRESOLVE 
EVENT_PHYSICS_CONTACT_POSTSOLVE 
EVENT_PHYSICS_CONTACT_SEPERATE 
EVENT_FOCUS 
EVENT_CONTROLLER_CONNECTED 
EVENT_CONTROLLER_DISCONNECTED 
EVENT_CONTROLLER_KEYDOWN 
EVENT_CONTROLLER_KEYUP 
EVENT_CONTROLLER_KEYREPEAT 
EVENT_CONTROLLER_AXIS 
EVENT_SPINE_ANIMATION_START 
EVENT_SPINE_ANIMATION_END 
EVENT_SPINE_ANIMATION_COMPLETE 
EVENT_SPINE_ANIMATION_EVENT 
EVENT_CUSTOM_BEGAN 
EVENT_CUSTOM_ENDED 

Constructor & Destructor Documentation

ScriptHandlerMgr ( void  )

!

Default constructor.

var ScriptHandlerMgr (   )

!

Default constructor.

virtual ~ScriptHandlerMgr ( void  )
virtual

Destructor.

var ~ScriptHandlerMgr (   )
virtual

Destructor.

Member Function Documentation

ScriptHandlerMgr::HandlerType
addCustomHandler
( void *  object,
int  handler 
)

Add customizable relationship among c++ Ref object, HandlerType and the refrence index corresponding to the pointer of Lua function.

In the customizable relationship, we don't pass the HandlerType, it will obtain the HandlerType by auto-increasing. The HandlerTypes used to customizable relationship are between EVENT_CUSTOM_BEGAN(10000) and EVENT_CUSTOM_ENDED(11000). If the HandlerType increased more than 12,it would trigger assert.

Parameters
objectthe Ref object.
handlera refrence index corresponding to the pointer of Lua function.
Returns
ScriptHandlerMgr::HandlerType the value of current ScriptHandlerMgr::HandlerType after adding.
var addCustomHandler ( var  object,
var  handler 
)

Add customizable relationship among c++ Ref object, HandlerType and the refrence index corresponding to the pointer of Lua function.

In the customizable relationship, we don't pass the HandlerType, it will obtain the HandlerType by auto-increasing. The HandlerTypes used to customizable relationship are between EVENT_CUSTOM_BEGAN(10000) and EVENT_CUSTOM_ENDED(11000). If the HandlerType increased more than 12,it would trigger assert.

Parameters
objectthe Ref object.
handlera refrence index corresponding to the pointer of Lua function.
Returns
ScriptHandlerMgr::HandlerType the value of current ScriptHandlerMgr::HandlerType after adding.
local addCustomHandler ( local  object,
local  handler 
)

Add customizable relationship among c++ Ref object, HandlerType and the refrence index corresponding to the pointer of Lua function.

In the customizable relationship, we don't pass the HandlerType, it will obtain the HandlerType by auto-increasing. The HandlerTypes used to customizable relationship are between EVENT_CUSTOM_BEGAN(10000) and EVENT_CUSTOM_ENDED(11000). If the HandlerType increased more than 12,it would trigger assert.

Parameters
objectthe Ref object.
handlera refrence index corresponding to the pointer of Lua function.
Returns
ScriptHandlerMgr::HandlerType the value of current ScriptHandlerMgr::HandlerType after adding.
void addObjectHandler ( void *  object,
int  handler,
ScriptHandlerMgr::HandlerType  handlerType 
)

Construct or update the mapping relationship among c++ Ref object ,HandlerType and the refrence index corresponding to the pointer of Lua function.

Parameters
objecta Ref object.
handlera refrence index corresponding to the pointer of Lua function.
handlerTypeScriptHandlerMgr::HandlerType.
var addObjectHandler ( var  object,
var  handler,
var  handlerType 
)

Construct or update the mapping relationship among c++ Ref object ,HandlerType and the refrence index corresponding to the pointer of Lua function.

Parameters
objecta Ref object.
handlera refrence index corresponding to the pointer of Lua function.
handlerTypeScriptHandlerMgr::HandlerType.
local addObjectHandler ( local  object,
local  handler,
local  handlerType 
)

Construct or update the mapping relationship among c++ Ref object ,HandlerType and the refrence index corresponding to the pointer of Lua function.

Parameters
objecta Ref object.
handlera refrence index corresponding to the pointer of Lua function.
handlerTypeScriptHandlerMgr::HandlerType.
static void destroyInstance ( void  )
static

Destroy the instance of the ScriptHandlerMgr.

var destroyInstance (   )
static

Destroy the instance of the ScriptHandlerMgr.

local destroyInstance (   )
static

Destroy the instance of the ScriptHandlerMgr.

static ScriptHandlerMgr*
getInstance
( void  )
static

Get the instance of the ScriptHandlerMgr.

Returns
the instance of the ScriptHandlerMgr.
var getInstance (   )
static

Get the instance of the ScriptHandlerMgr.

Returns
the instance of the ScriptHandlerMgr.
local getInstance (   )
static

Get the instance of the ScriptHandlerMgr.

Returns
the instance of the ScriptHandlerMgr.
int getObjectHandler ( void *  object,
ScriptHandlerMgr::HandlerType  handlerType 
)

By the handlerType and object, find the correct refrence index corresponding to the pointer of Lua function.

Parameters
objecta Ref object.
handlerTypeScriptHandlerMgr::HandlerType.
Returns
index corresponding to the pointer of Lua function,otherwise 0.
var getObjectHandler ( var  object,
var  handlerType 
)

By the handlerType and object, find the correct refrence index corresponding to the pointer of Lua function.

Parameters
objecta Ref object.
handlerTypeScriptHandlerMgr::HandlerType.
Returns
index corresponding to the pointer of Lua function,otherwise 0.
local getObjectHandler ( local  object,
local  handlerType 
)

By the handlerType and object, find the correct refrence index corresponding to the pointer of Lua function.

Parameters
objecta Ref object.
handlerTypeScriptHandlerMgr::HandlerType.
Returns
index corresponding to the pointer of Lua function,otherwise 0.
void removeObjectAllHandlers ( void *  object)

Remove the all relationship among the object, HandlerType and the refrence index corresponding to the pointer of Lua function.

Meanwhile, remove the refrence of Lua function corresponding to the indexs the object has in the 'toluafix_refid_function_mapping' table.

Parameters
objectthe Ref object.
var removeObjectAllHandlers ( var  object)

Remove the all relationship among the object, HandlerType and the refrence index corresponding to the pointer of Lua function.

Meanwhile, remove the refrence of Lua function corresponding to the indexs the object has in the 'toluafix_refid_function_mapping' table.

Parameters
objectthe Ref object.
local removeObjectAllHandlers ( local  object)

Remove the all relationship among the object, HandlerType and the refrence index corresponding to the pointer of Lua function.

Meanwhile, remove the refrence of Lua function corresponding to the indexs the object has in the 'toluafix_refid_function_mapping' table.

Parameters
objectthe Ref object.
void removeObjectHandler ( void *  object,
ScriptHandlerMgr::HandlerType  handlerType 
)

By the handlerType and object, find the correct refrence index corresponding to the pointer of Lua function.

If found, remove the refrence of Lua function corresponding to this index in the 'toluafix_refid_function_mapping' table.

Parameters
objecta Ref object.
handlerTypeScriptHandlerMgr::HandlerType.
var removeObjectHandler ( var  object,
var  handlerType 
)

By the handlerType and object, find the correct refrence index corresponding to the pointer of Lua function.

If found, remove the refrence of Lua function corresponding to this index in the 'toluafix_refid_function_mapping' table.

Parameters
objecta Ref object.
handlerTypeScriptHandlerMgr::HandlerType.
local removeObjectHandler ( local  object,
local  handlerType 
)

By the handlerType and object, find the correct refrence index corresponding to the pointer of Lua function.

If found, remove the refrence of Lua function corresponding to this index in the 'toluafix_refid_function_mapping' table.

Parameters
objecta Ref object.
handlerTypeScriptHandlerMgr::HandlerType.

The documentation for this class was generated from the following file: