Cocos2d-x  v3.12
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Groups
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)
 ! More...
 
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 id corresponding to the pointer of Lua function. More...
 
void removeObjectHandler (void *object, ScriptHandlerMgr::HandlerType handlerType)
 By the handlerType and Ref object, find the correct reference id corresponding to the pointer of Lua function. More...
 
int getObjectHandler (void *object, ScriptHandlerMgr::HandlerType handlerType)
 By the handlerType and object, find the correct reference id corresponding to the pointer of Lua function. More...
 
void removeObjectAllHandlers (void *object)
 Remove the all relationship among the object, HandlerType and the reference id 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 reference id 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.
 

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 reference id 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.

Constructor & Destructor Documentation

ScriptHandlerMgr ( void  )

!

Default constructor.

Member Function Documentation

static ScriptHandlerMgr*
getInstance
( void  )
static

Get the instance of the ScriptHandlerMgr.

the instance of the ScriptHandlerMgr.

local getInstance (   )
static

Get the instance of the ScriptHandlerMgr.

the instance of the ScriptHandlerMgr.

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

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

a Ref object. a reference id corresponding to the pointer of Lua function. ScriptHandlerMgr::HandlerType.

local registerScriptHandler ( local  object,
local  handler,
local  handlerType 
)

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

a Ref object. a reference id corresponding to the pointer of Lua function. ScriptHandlerMgr::HandlerType.

void removeObjectHandler ( void *  object,
ScriptHandlerMgr::HandlerType  handlerType 
)

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

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

a Ref object. ScriptHandlerMgr::HandlerType.

local unregisterScriptHandler ( local  object,
local  handlerType 
)

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

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

a Ref object. ScriptHandlerMgr::HandlerType.

int getObjectHandler ( void *  object,
ScriptHandlerMgr::HandlerType  handlerType 
)

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

a Ref object. ScriptHandlerMgr::HandlerType. reference id corresponding to the pointer of Lua function,otherwise 0.

void removeObjectAllHandlers ( void *  object)

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

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

the Ref object.

local removeObjectAllHandlers ( local  object)

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

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

the Ref object.

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

Add customizable relationship among c++ Ref object, HandlerType and the reference id 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 EVENT_CUSTOM_ENDED(110000),it would trigger assert.

the Ref object. a reference index corresponding to the pointer of Lua function. ScriptHandlerMgr::HandlerType the ScriptHandlerMgr::HandlerType value after adding.


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