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

The Lua engine integrated into the cocos2d-x to process the interactive operation between lua and c++. More...

#include <CCLuaEngine.h>

Inheritance diagram for LuaEngine:

Public Member Functions

virtual ~LuaEngine (void)
 Destrutor of LuaEngine. More...
 
virtual ccScriptType getScriptType () override
 Get ccScriptType of LuaEngine used, it is always kScriptTypeLua. More...
 
LuaStackgetLuaStack (void)
 Get LuaStack of the LuaEngine. More...
 
virtual void addSearchPath (const char *path)
 Add a path to find lua files in. More...
 
local addSearchPath ( local path)
 Add a path to find lua files in. More...
 
virtual void addLuaLoader (lua_CFunction func)
 Add lua loader. More...
 
var addLuaLoader ( var func)
 Add lua loader. More...
 
local addLuaLoader ( local func)
 Add lua loader. More...
 
virtual int reload (const char *moduleFileName)
 Reload script code corresponding to moduleFileName. More...
 
local reload ( local moduleFileName)
 Reload script code corresponding to moduleFileName. More...
 
virtual void removeScriptObjectByObject (Ref *object) override
 Remove the related reference about the Ref object stored in the Lua table by set the value of corresponding key nil: The related Lua tables are toluafix_refid_ptr_mapping,toluafix_refid_type_mapping,tolua_value_root and object_Metatable["tolua_ubox"] or tolua_ubox. More...
 
virtual void removeScriptHandler (int nHandler) override
 Remove Lua function reference by nHandler by setting toluafix_refid_function_mapping[nHandle] nil. More...
 
local removeScriptHandler ( local nHandler)
 Remove Lua function reference by nHandler by setting toluafix_refid_function_mapping[nHandle] nil. More...
 
virtual int reallocateScriptHandler (int nHandler) override
 Reallocate Lua function reference index to the Lua function pointer to add refrence. More...
 
virtual int executeString (const char *codes) override
 Execute script code contained in the given string. More...
 
virtual int executeScriptFile (const char *filename) override
 Execute a script file. More...
 
virtual int executeGlobalFunction (const char *functionName) override
 Execute a scripted global function. More...
 
virtual int executeNodeEvent (Node *pNode, int nAction)
local executeNodeEvent ( local pNode, local nAction)
virtual int executeMenuItemEvent (MenuItem *pMenuItem)
virtual int executeNotificationEvent (__NotificationCenter *pNotificationCenter, const char *pszName)
local executeNotificationEvent ( local pNotificationCenter, local pszName)
virtual int executeCallFuncActionEvent (CallFunc *pAction, Ref *pTarget=NULL)
var executeCallFuncActionEvent ( var pAction, var NULL)
local executeCallFuncActionEvent ( local pAction, local NULL)
virtual int executeSchedule (int nHandler, float dt, Node *pNode=NULL)
virtual int executeLayerTouchesEvent (Layer *pLayer, int eventType, __Set *pTouches)
local executeLayerTouchesEvent ( local pLayer, local eventType, local pTouches)
virtual int executeLayerTouchEvent (Layer *pLayer, int eventType, Touch *pTouch)
local executeLayerTouchEvent ( local pLayer, local eventType, local pTouch)
virtual int executeLayerKeypadEvent (Layer *pLayer, int eventType)
local executeLayerKeypadEvent ( local pLayer, local eventType)
virtual int executeAccelerometerEvent (Layer *pLayer, Acceleration *pAccelerationValue)
virtual int executeEvent (int nHandler, const char *pEventName, Ref *pEventSource=NULL, const char *pEventSourceClassName=NULL)
local executeEvent ( local nHandler, local pEventName, local NULL, local NULL)
virtual bool handleAssert (const char *msg) override
 Handle the assert message. More...
 
virtual bool parseConfig (ConfigType type, const std::string &str) override
 Parse the config information data. More...
 
local parseConfig ( local type, local str)
 Parse the config information data. More...
 
virtual int sendEvent (ScriptEvent *message) override
 When some events triggered in the c++ also needs to pass on to lua to handle, we could call this function to send events. More...
 
var sendEvent ( var message)
 When some events triggered in the c++ also needs to pass on to lua to handle, we could call this function to send events. More...
 
local sendEvent ( local message)
 When some events triggered in the c++ also needs to pass on to lua to handle, we could call this function to send events. More...
 
virtual int handleEvent (ScriptHandlerMgr::HandlerType type, void *data)
 Pass on the events related with ScrollView,TableCell,AssertManager, Armature, Accelerometer, Keyboard, Touch, Touches ,Mouse and Custom event to lua to handle. More...
 
local handleEvent ( local type, local data)
 Pass on the events related with ScrollView,TableCell,AssertManager, Armature, Accelerometer, Keyboard, Touch, Touches ,Mouse and Custom event to lua to handle. More...
 
virtual int handleEvent (ScriptHandlerMgr::HandlerType type, void *data, int numResults, const std::function< void(lua_State *, int)> &func)
 Pass on the events related with TableCell and TableView to lua to handle. More...
 

Static Public Member Functions

static LuaEnginegetInstance (void)
 Get instance of LuaEngine. More...
 
local getInstance ()
 Get instance of LuaEngine. More...
 
static LuaEnginedefaultEngine (void)
 Get defaultEngine of LuaEngine, it was deprecated. More...
 
local defaultEngine ()
 Get defaultEngine of LuaEngine, it was deprecated. More...
 

Detailed Description

The Lua engine integrated into the cocos2d-x to process the interactive operation between lua and c++.

Constructor & Destructor Documentation

virtual ~LuaEngine ( void  )
virtual

Destrutor of LuaEngine.

var ~LuaEngine (   )
virtual

Destrutor of LuaEngine.

local ~LuaEngine (   )
virtual

Destrutor of LuaEngine.

Member Function Documentation

virtual void addLuaLoader ( lua_CFunction  func)
virtual

Add lua loader.

Parameters
funca function pointer point to the loader function.
var addLuaLoader ( var  func)
virtual

Add lua loader.

Parameters
funca function pointer point to the loader function.
local addLuaLoader ( local  func)
virtual

Add lua loader.

Parameters
funca function pointer point to the loader function.
virtual void addSearchPath ( const char *  path)
virtual

Add a path to find lua files in.

Parameters
pathto be added to the Lua path
var addSearchPath ( var  path)
virtual

Add a path to find lua files in.

Parameters
pathto be added to the Lua path
local addSearchPath ( local  path)
virtual

Add a path to find lua files in.

Parameters
pathto be added to the Lua path
static LuaEngine* defaultEngine ( void  )
inlinestatic

Get defaultEngine of LuaEngine, it was deprecated.

Returns
the instance of LuaEngine.
var defaultEngine (   )
inlinestatic

Get defaultEngine of LuaEngine, it was deprecated.

Returns
the instance of LuaEngine.
local defaultEngine (   )
inlinestatic

Get defaultEngine of LuaEngine, it was deprecated.

Returns
the instance of LuaEngine.
virtual int
executeAccelerometerEvent
( Layer pLayer,
Acceleration pAccelerationValue 
)
virtual
var executeAccelerometerEvent ( var  pLayer,
var  pAccelerationValue 
)
virtual
local executeAccelerometerEvent ( local  pLayer,
local  pAccelerationValue 
)
virtual
virtual int
executeCallFuncActionEvent
( CallFunc pAction,
Ref pTarget = NULL 
)
virtual
var executeCallFuncActionEvent ( var  pAction,
var  pTarget = NULL 
)
virtual
local executeCallFuncActionEvent ( local  pAction,
local  pTarget = NULL 
)
virtual
virtual int executeEvent ( int  nHandler,
const char *  pEventName,
Ref pEventSource = NULL,
const char *  pEventSourceClassName = NULL 
)
virtual
var executeEvent ( var  nHandler,
var  pEventName,
var  pEventSource = NULL,
var  pEventSourceClassName = NULL 
)
virtual
local executeEvent ( local  nHandler,
local  pEventName,
local  pEventSource = NULL,
local  pEventSourceClassName = NULL 
)
virtual
virtual int executeGlobalFunction ( const char *  functionName)
overridevirtual

Execute a scripted global function.

The function should not take any parameters and should return an integer.

Parameters
functionNameString object holding the name of the function, in the global script environment, that is to be executed.
Returns
The integer value returned from the script function.
var executeGlobalFunction ( var  functionName)
overridevirtual

Execute a scripted global function.

The function should not take any parameters and should return an integer.

Parameters
functionNameString object holding the name of the function, in the global script environment, that is to be executed.
Returns
The integer value returned from the script function.
local executeGlobalFunction ( local  functionName)
overridevirtual

Execute a scripted global function.

The function should not take any parameters and should return an integer.

Parameters
functionNameString object holding the name of the function, in the global script environment, that is to be executed.
Returns
The integer value returned from the script function.
virtual int executeLayerKeypadEvent ( Layer pLayer,
int  eventType 
)
virtual
var executeLayerKeypadEvent ( var  pLayer,
var  eventType 
)
virtual
local executeLayerKeypadEvent ( local  pLayer,
local  eventType 
)
virtual
virtual int
executeLayerTouchesEvent
( Layer pLayer,
int  eventType,
__Set *  pTouches 
)
virtual
var executeLayerTouchesEvent ( var  pLayer,
var  eventType,
var  pTouches 
)
virtual
local executeLayerTouchesEvent ( local  pLayer,
local  eventType,
local  pTouches 
)
virtual
virtual int executeLayerTouchEvent ( Layer pLayer,
int  eventType,
Touch pTouch 
)
virtual
var executeLayerTouchEvent ( var  pLayer,
var  eventType,
var  pTouch 
)
virtual
local executeLayerTouchEvent ( local  pLayer,
local  eventType,
local  pTouch 
)
virtual
virtual int executeMenuItemEvent ( MenuItem pMenuItem)
virtual
var executeMenuItemEvent ( var  pMenuItem)
virtual
local executeMenuItemEvent ( local  pMenuItem)
virtual
virtual int executeNodeEvent ( Node pNode,
int  nAction 
)
virtual
var executeNodeEvent ( var  pNode,
var  nAction 
)
virtual
local executeNodeEvent ( local  pNode,
local  nAction 
)
virtual
virtual int
executeNotificationEvent
( __NotificationCenter *  pNotificationCenter,
const char *  pszName 
)
virtual
var executeNotificationEvent ( var  pNotificationCenter,
var  pszName 
)
virtual
local executeNotificationEvent ( local  pNotificationCenter,
local  pszName 
)
virtual
virtual int executeSchedule ( int  nHandler,
float  dt,
Node pNode = NULL 
)
virtual
var executeSchedule ( var  nHandler,
var  dt,
var  pNode = NULL 
)
virtual
local executeSchedule ( local  nHandler,
local  dt,
local  pNode = NULL 
)
virtual
virtual int executeScriptFile ( const char *  filename)
overridevirtual

Execute a script file.

Parameters
filenameString object holding the filename of the script file that is to be executed.
Returns
the return values by calling executeFunction.
var executeScriptFile ( var  filename)
overridevirtual

Execute a script file.

Parameters
filenameString object holding the filename of the script file that is to be executed.
Returns
the return values by calling executeFunction.
local executeScriptFile ( local  filename)
overridevirtual

Execute a script file.

Parameters
filenameString object holding the filename of the script file that is to be executed.
Returns
the return values by calling executeFunction.
virtual int executeString ( const char *  codes)
overridevirtual

Execute script code contained in the given string.

Parameters
codesholding the valid script code that should be executed.
Returns
0 if the string is excuted correctly,other if the string is excuted wrongly.
var executeString ( var  codes)
overridevirtual

Execute script code contained in the given string.

Parameters
codesholding the valid script code that should be executed.
Returns
0 if the string is excuted correctly,other if the string is excuted wrongly.
local executeString ( local  codes)
overridevirtual

Execute script code contained in the given string.

Parameters
codesholding the valid script code that should be executed.
Returns
0 if the string is excuted correctly,other if the string is excuted wrongly.
static LuaEngine* getInstance ( void  )
static

Get instance of LuaEngine.

Returns
the instance of LuaEngine.
var getInstance (   )
static

Get instance of LuaEngine.

Returns
the instance of LuaEngine.
local getInstance (   )
static

Get instance of LuaEngine.

Returns
the instance of LuaEngine.
LuaStack* getLuaStack ( void  )
inline

Get LuaStack of the LuaEngine.

All the interactive operation are all base on the LuaStack.

Returns
LuaStack object.
var getLuaStack (   )
inline

Get LuaStack of the LuaEngine.

All the interactive operation are all base on the LuaStack.

Returns
LuaStack object.
local getLuaStack (   )
inline

Get LuaStack of the LuaEngine.

All the interactive operation are all base on the LuaStack.

Returns
LuaStack object.
virtual ccScriptType getScriptType ( )
inlineoverridevirtual

Get ccScriptType of LuaEngine used, it is always kScriptTypeLua.

Returns
kScriptTypeLua.
var getScriptType ( )
inlineoverridevirtual

Get ccScriptType of LuaEngine used, it is always kScriptTypeLua.

Returns
kScriptTypeLua.
local getScriptType ( )
inlineoverridevirtual

Get ccScriptType of LuaEngine used, it is always kScriptTypeLua.

Returns
kScriptTypeLua.
virtual bool handleAssert ( const char *  msg)
overridevirtual

Handle the assert message.

Returns
return true if current _callFromLua of LuaStack is not equal to 0 otherwise return false.
var handleAssert ( var  msg)
overridevirtual

Handle the assert message.

Returns
return true if current _callFromLua of LuaStack is not equal to 0 otherwise return false.
local handleAssert ( local  msg)
overridevirtual

Handle the assert message.

Returns
return true if current _callFromLua of LuaStack is not equal to 0 otherwise return false.
virtual int handleEvent ( ScriptHandlerMgr::HandlerType  type,
void *  data 
)
virtual

Pass on the events related with ScrollView,TableCell,AssertManager, Armature, Accelerometer, Keyboard, Touch, Touches ,Mouse and Custom event to lua to handle.

Parameters
typeDifferent ScriptHandlerMgr::HandlerType means different processing for the data.
dataThe 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.
Returns
default return 0 otherwise return values according different ScriptHandlerMgr::HandlerType.
var handleEvent ( var  type,
var  data 
)
virtual

Pass on the events related with ScrollView,TableCell,AssertManager, Armature, Accelerometer, Keyboard, Touch, Touches ,Mouse and Custom event to lua to handle.

Parameters
typeDifferent ScriptHandlerMgr::HandlerType means different processing for the data.
dataThe 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.
Returns
default return 0 otherwise return values according different ScriptHandlerMgr::HandlerType.
local handleEvent ( local  type,
local  data 
)
virtual

Pass on the events related with ScrollView,TableCell,AssertManager, Armature, Accelerometer, Keyboard, Touch, Touches ,Mouse and Custom event to lua to handle.

Parameters
typeDifferent ScriptHandlerMgr::HandlerType means different processing for the data.
dataThe 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.
Returns
default return 0 otherwise return values according different ScriptHandlerMgr::HandlerType.
virtual int handleEvent ( ScriptHandlerMgr::HandlerType  type,
void *  data,
int  numResults,
const std::function< void(lua_State *, int)> &  func 
)
virtual

Pass on the events related with TableCell and TableView to lua to handle.

Parameters
typeDifferent ScriptHandlerMgr::HandlerType means different processing for the data.
dataThe 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.
numResultsThe number of the return values.
funcThe callback would be called when numResults is > 0.
Returns
default return 0 otherwise return values according different ScriptHandlerMgr::HandlerType.
var handleEvent ( var  type,
var  data,
var  numResults,
var  func 
)
virtual

Pass on the events related with TableCell and TableView to lua to handle.

Parameters
typeDifferent ScriptHandlerMgr::HandlerType means different processing for the data.
dataThe 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.
numResultsThe number of the return values.
funcThe callback would be called when numResults is > 0.
Returns
default return 0 otherwise return values according different ScriptHandlerMgr::HandlerType.
local handleEvent ( local  type,
local  data,
local  numResults,
local  func 
)
virtual

Pass on the events related with TableCell and TableView to lua to handle.

Parameters
typeDifferent ScriptHandlerMgr::HandlerType means different processing for the data.
dataThe 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.
numResultsThe number of the return values.
funcThe callback would be called when numResults is > 0.
Returns
default return 0 otherwise return values according different ScriptHandlerMgr::HandlerType.
virtual bool parseConfig ( ConfigType  type,
const std::string &  str 
)
overridevirtual

Parse the config information data.

Parameters
typein current mechanism,it always ConfigType::COCOSTUDIO.
strthe information data.
Returns
if __onParseConfig function exist in the Lua, it return the value that _stack->executeFunction returns otherwise return false.
var parseConfig ( var  type,
var  str 
)
overridevirtual

Parse the config information data.

Parameters
typein current mechanism,it always ConfigType::COCOSTUDIO.
strthe information data.
Returns
if __onParseConfig function exist in the Lua, it return the value that _stack->executeFunction returns otherwise return false.
local parseConfig ( local  type,
local  str 
)
overridevirtual

Parse the config information data.

Parameters
typein current mechanism,it always ConfigType::COCOSTUDIO.
strthe information data.
Returns
if __onParseConfig function exist in the Lua, it return the value that _stack->executeFunction returns otherwise return false.
virtual int reallocateScriptHandler ( int  nHandler)
overridevirtual

Reallocate Lua function reference index to the Lua function pointer to add refrence.

Parameters
nHandlerthe function refrence index to find the correspoinding Lua function pointer.
var reallocateScriptHandler ( var  nHandler)
overridevirtual

Reallocate Lua function reference index to the Lua function pointer to add refrence.

Parameters
nHandlerthe function refrence index to find the correspoinding Lua function pointer.
local reallocateScriptHandler ( local  nHandler)
overridevirtual

Reallocate Lua function reference index to the Lua function pointer to add refrence.

Parameters
nHandlerthe function refrence index to find the correspoinding Lua function pointer.
virtual int reload ( const char *  moduleFileName)
virtual

Reload script code corresponding to moduleFileName.

If value of package["loaded"][moduleFileName] is existed, it would set the vaule nil.Then,it calls executeString function.

Parameters
moduleFileNameString object holding the filename of the script file that is to be executed.
Returns
0 if the string is excuted correctly or other if the string is excuted wrongly.
var reload ( var  moduleFileName)
virtual

Reload script code corresponding to moduleFileName.

If value of package["loaded"][moduleFileName] is existed, it would set the vaule nil.Then,it calls executeString function.

Parameters
moduleFileNameString object holding the filename of the script file that is to be executed.
Returns
0 if the string is excuted correctly or other if the string is excuted wrongly.
local reload ( local  moduleFileName)
virtual

Reload script code corresponding to moduleFileName.

If value of package["loaded"][moduleFileName] is existed, it would set the vaule nil.Then,it calls executeString function.

Parameters
moduleFileNameString object holding the filename of the script file that is to be executed.
Returns
0 if the string is excuted correctly or other if the string is excuted wrongly.
virtual void removeScriptHandler ( int  nHandler)
overridevirtual

Remove Lua function reference by nHandler by setting toluafix_refid_function_mapping[nHandle] nil.

Parameters
nHandlerthe function refrence index to find the correspoinding Lua function pointer.
var removeScriptHandler ( var  nHandler)
overridevirtual

Remove Lua function reference by nHandler by setting toluafix_refid_function_mapping[nHandle] nil.

Parameters
nHandlerthe function refrence index to find the correspoinding Lua function pointer.
local removeScriptHandler ( local  nHandler)
overridevirtual

Remove Lua function reference by nHandler by setting toluafix_refid_function_mapping[nHandle] nil.

Parameters
nHandlerthe function refrence index to find the correspoinding Lua function pointer.
virtual void
removeScriptObjectByObject
( Ref object)
overridevirtual

Remove the related reference about the Ref object stored in the Lua table by set the value of corresponding key nil: The related Lua tables are toluafix_refid_ptr_mapping,toluafix_refid_type_mapping,tolua_value_root and object_Metatable["tolua_ubox"] or tolua_ubox.

Meanwhile set the corresponding userdata nullptr and remove the all the lua function refrence corresponding to this object.

In current mechanism, this function is called in the destructor of Ref object, developer don't call this functions.

Parameters
objectthe key object to remove script object.
var removeScriptObjectByObject ( var  object)
overridevirtual

Remove the related reference about the Ref object stored in the Lua table by set the value of corresponding key nil: The related Lua tables are toluafix_refid_ptr_mapping,toluafix_refid_type_mapping,tolua_value_root and object_Metatable["tolua_ubox"] or tolua_ubox.

Meanwhile set the corresponding userdata nullptr and remove the all the lua function refrence corresponding to this object.

In current mechanism, this function is called in the destructor of Ref object, developer don't call this functions.

Parameters
objectthe key object to remove script object.
local removeScriptObjectByObject ( local  object)
overridevirtual

Remove the related reference about the Ref object stored in the Lua table by set the value of corresponding key nil: The related Lua tables are toluafix_refid_ptr_mapping,toluafix_refid_type_mapping,tolua_value_root and object_Metatable["tolua_ubox"] or tolua_ubox.

Meanwhile set the corresponding userdata nullptr and remove the all the lua function refrence corresponding to this object.

In current mechanism, this function is called in the destructor of Ref object, developer don't call this functions.

Parameters
objectthe key object to remove script object.
virtual int sendEvent ( ScriptEvent *  message)
overridevirtual

When some events triggered in the c++ also needs to pass on to lua to handle, we could call this function to send events.

Parameters
messagethe ScriptEvent object that has ScriptEventType and the pointer to information data.
Returns
default return 0 otherwise return values the same as handleNodeEvent, handleMenuClickedEvent or handleCallFuncActionEvent,etc.
var sendEvent ( var  message)
overridevirtual

When some events triggered in the c++ also needs to pass on to lua to handle, we could call this function to send events.

Parameters
messagethe ScriptEvent object that has ScriptEventType and the pointer to information data.
Returns
default return 0 otherwise return values the same as handleNodeEvent, handleMenuClickedEvent or handleCallFuncActionEvent,etc.
local sendEvent ( local  message)
overridevirtual

When some events triggered in the c++ also needs to pass on to lua to handle, we could call this function to send events.

Parameters
messagethe ScriptEvent object that has ScriptEventType and the pointer to information data.
Returns
default return 0 otherwise return values the same as handleNodeEvent, handleMenuClickedEvent or handleCallFuncActionEvent,etc.

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