cocos2d-x  v3.6
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Groups Pages
ScriptEngineProtocol Class Referenceabstract

Don't make ScriptEngineProtocol inherits from Object since setScriptEngine is invoked only once in AppDelegate.cpp, It will affect the lifecycle of ScriptEngine instance, the autorelease pool will be destroyed before destructing ScriptEngine. More...

Inherited by LuaEngine.

Public Types

enum  ConfigType
 ConfigType enum. More...
 

Public Member Functions

 ScriptEngineProtocol ()
 Constructor of ScriptEngineProtocol.
 
virtual ~ScriptEngineProtocol ()
 Destructor of ScriptEngineProtocol.
 
virtual ccScriptType getScriptType ()
 Get the specific script type. More...
 
virtual void removeScriptObjectByObject (Ref *obj)=0
 Remove script object,The specific meaning should refer to the ScriptType. More...
 
virtual void removeScriptHandler (int handler)
 Remove script function handler, only LuaEngine class need to implement this function. More...
 
virtual int reallocateScriptHandler (int handler)
 Reallocate script function handler, only LuaEngine class need to implement this function. More...
 
virtual int executeString (const char *codes)=0
 Execute script code contained in the given string. More...
 
virtual int executeScriptFile (const char *filename)=0
 Execute a script file. More...
 
virtual int executeGlobalFunction (const char *functionName)=0
 Execute a scripted global function. More...
 
virtual int sendEvent (ScriptEvent *evt)=0
 When trigger a script event ,call this func,add params needed into ScriptEvent object.nativeObject is object triggering the event, can be nullptr in Lua.
 
virtual bool handleAssert (const char *msg)=0
 Handle the assert message. More...
 
virtual void setCalledFromScript (bool callFromScript)
 Useless for Lua.
 
virtual bool isCalledFromScript ()
 Useless for Lua.
 
virtual bool parseConfig (ConfigType type, const std::string &str)=0
 Parse configuration file. More...
 

Detailed Description

Don't make ScriptEngineProtocol inherits from Object since setScriptEngine is invoked only once in AppDelegate.cpp, It will affect the lifecycle of ScriptEngine instance, the autorelease pool will be destroyed before destructing ScriptEngine.

So a crash will appear on Win32 if you click the close button.

Member Function Documentation

virtual ccScriptType getScriptType ( )
inlinevirtual

Get the specific script type.

Returns
the specific script type.

Reimplemented in LuaEngine.

virtual void
removeScriptObjectByObject
( Ref obj)
pure virtual

Remove script object,The specific meaning should refer to the ScriptType.

For Lua,

See also
removeScriptObjectByObject of LuaEngine.

Implemented in LuaEngine.

virtual void removeScriptHandler ( int  handler)
inlinevirtual

Remove script function handler, only LuaEngine class need to implement this function.

See also
removeScriptHandler of LuaEngine.

Reimplemented in LuaEngine.

virtual int reallocateScriptHandler ( int  handler)
inlinevirtual

Reallocate script function handler, only LuaEngine class need to implement this function.

See also
reallocateScriptHandler of LuaEngine.

Reimplemented in LuaEngine.

virtual int executeString ( const char *  codes)
pure virtual

Execute script code contained in the given string.

Parameters
codesholding the valid script code that should be executed.
Returns
0 if the string is executed correctly.
other if the string is executed wrongly.

Implemented in LuaEngine.

virtual int executeScriptFile ( const char *  filename)
pure virtual

Execute a script file.

Parameters
filenameString object holding the filename of the script file that is to be executed.
Returns
0 if it happen the error or it hasn't return value, otherwise it return the value by calling the lua function.

Implemented in LuaEngine.

virtual int executeGlobalFunction ( const char *  functionName)
pure virtual

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.

Implemented in LuaEngine.

virtual bool handleAssert ( const char *  msg)
pure virtual

Handle the assert message.

Returns
true if the assert was handled by the script engine, false otherwise.

Implemented in LuaEngine.

virtual bool parseConfig ( ConfigType  type,
const std::string &  str 
)
pure virtual

Parse configuration file.

Parameters
typethe specific type value.
strthe information data.

Implemented in LuaEngine.


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