Cocos2d-x  4.0.0
Public Types | Public Member Functions | Static Public Member Functions | List of all members
ScriptHandlerMgr Class Reference

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

Public Types

enum  HandlerType : int
 HandlerType enum. More...
 

Public Member Functions

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

Static Public Member Functions

static ScriptHandlerMgrgetInstance (void)
 Get the instance of the ScriptHandlerMgr.
 
static void destroyInstance (void)
 Destroy the instance of the ScriptHandlerMgr.
 

Detailed Description

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

In the current mechanism, for the class derived from the Ref, we construct a mapping relationship among c++ Ref object, HandlerType and the reference 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

HandlerType enum.

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

NA

Constructor & Destructor Documentation

ScriptHandlerMgr ( void  )

!

Default constructor.

NA NA

virtual ~ScriptHandlerMgr ( void  )
virtual

Destructor.

NA NA

Member Function Documentation

static ScriptHandlerMgr* getInstance ( void  )
static

Get the instance of the ScriptHandlerMgr.

Returns
the instance of the ScriptHandlerMgr. NA
static void destroyInstance ( void  )
static

Destroy the instance of the ScriptHandlerMgr.

NA NA

void addObjectHandler ( void *  object,
int  handler,
ScriptHandlerMgr::HandlerType  handlerType 
)

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

Parameters
objecta Ref object.
handlera reference index corresponding to the pointer of Lua function.
handlerTypeScriptHandlerMgr::HandlerType. registerScriptHandler NA
void removeObjectHandler ( void *  object,
ScriptHandlerMgr::HandlerType  handlerType 
)

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

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

Parameters
objecta Ref object.
handlerTypeScriptHandlerMgr::HandlerType. unregisterScriptHandler NA
int getObjectHandler ( void *  object,
ScriptHandlerMgr::HandlerType  handlerType 
)

By the handlerType and object, find the correct reference 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. NA NA
void removeObjectAllHandlers ( void *  object)

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

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

Parameters
objectthe Ref object. NA
ScriptHandlerMgr::HandlerType addCustomHandler ( void *  object,
int  handler 
)

Add customizable relationship among c++ Ref object, HandlerType and the reference 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 reference index corresponding to the pointer of Lua function.
Returns
ScriptHandlerMgr::HandlerType the value of current ScriptHandlerMgr::HandlerType after adding. NA NA

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