mirror of https://github.com/axmolengine/axmol.git
Merge pull request #11150 from samuele3hu/v3_5_test
[ci skip]Update comments of some header files
This commit is contained in:
commit
fae951d928
|
@ -53,20 +53,48 @@ enum ccScriptType {
|
|||
kScriptTypeJavascript
|
||||
};
|
||||
|
||||
/**
|
||||
* @addtogroup script_support
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* This classes is wrapped to store the handler corresponding to the Lua function pointer and assign the handler a unique id
|
||||
*
|
||||
* @lua NA
|
||||
* @js NA
|
||||
*/
|
||||
class ScriptHandlerEntry : public Ref
|
||||
{
|
||||
public:
|
||||
static ScriptHandlerEntry* create(int handler);
|
||||
|
||||
/**
|
||||
* @js NA
|
||||
* @lua NA
|
||||
* create a ScriptHandlerEntry instance by the handler.
|
||||
*
|
||||
* @param handler corresponding to the Lua function pointer.
|
||||
* @return ScriptHandlerEntry instance.
|
||||
*/
|
||||
static ScriptHandlerEntry* create(int handler);
|
||||
|
||||
/**
|
||||
* Destructor of ScriptHandlerEntry.
|
||||
*/
|
||||
virtual ~ScriptHandlerEntry();
|
||||
|
||||
/**
|
||||
* Get the handler corresponding to the Lua function pointer.
|
||||
*
|
||||
* @return the handler corresponding to the Lua function pointer.
|
||||
*/
|
||||
int getHandler(void) {
|
||||
return _handler;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the unique id corresponding to the handler.
|
||||
*
|
||||
* @return the unique id corresponding to the handler.
|
||||
*/
|
||||
int getEntryId(void) {
|
||||
return _entryId;
|
||||
}
|
||||
|
@ -85,48 +113,57 @@ protected:
|
|||
};
|
||||
|
||||
/**
|
||||
* @addtogroup script_support
|
||||
* @{
|
||||
* The SchedulerScriptHandlerEntry is used to store the handler corresponding to the Lua function pointer and assign the handler a unique id like ScriptHandlerEntry.
|
||||
* Meanwhile,create a timer that named TimerScriptHandler to execute the Lua function corresponding to the handler in the interval time if the SchedulerScriptHandlerEntry object isn't paused.
|
||||
*
|
||||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
|
||||
class SchedulerScriptHandlerEntry : public ScriptHandlerEntry
|
||||
{
|
||||
public:
|
||||
// nHandler return by tolua_ref_function(), called from LuaCocos2d.cpp
|
||||
/**
|
||||
* @js NA
|
||||
* @lua NA
|
||||
* create a SchedulerScriptHandlerEntry object.
|
||||
*
|
||||
* @param handler the index corresponding to the Lua function pointer.
|
||||
* @param interval the interval to execute the Lua function. If the value is 0, then the lua function will be scheduled every frame.
|
||||
* @param paused if paused is true, then the timer won't be started until it is resumed.
|
||||
* @return a SchedulerScriptHandlerEntry object.
|
||||
*/
|
||||
static SchedulerScriptHandlerEntry* create(int handler, float interval, bool paused);
|
||||
|
||||
/**
|
||||
* @js NA
|
||||
* @lua NA
|
||||
* Destructor of SchedulerScriptHandlerEntry
|
||||
*/
|
||||
virtual ~SchedulerScriptHandlerEntry();
|
||||
|
||||
/**
|
||||
* @js NA
|
||||
* @lua NA
|
||||
* Get the pointer of TimerScriptHandler object.
|
||||
*
|
||||
* @return the pointer of TimerScriptHandler object
|
||||
*/
|
||||
TimerScriptHandler* getTimer(void) {
|
||||
return _timer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @js NA
|
||||
* @lua NA
|
||||
* Get the flag whether paused or not.
|
||||
*
|
||||
* @return the flag whether paused or not.
|
||||
*/
|
||||
bool isPaused(void) {
|
||||
return _paused;
|
||||
}
|
||||
/**
|
||||
* @js NA
|
||||
* @lua NA
|
||||
* Set the markedForDeletion flag true.
|
||||
*/
|
||||
void markedForDeletion(void) {
|
||||
_markedForDeletion = true;
|
||||
}
|
||||
/**
|
||||
* @js NA
|
||||
* @lua NA
|
||||
* Get the flag whether markedForDeletion or not.
|
||||
*
|
||||
* @return the flag whether markedForDeletion or not.
|
||||
*/
|
||||
bool isMarkedForDeletion(void) {
|
||||
return _markedForDeletion;
|
||||
|
@ -148,38 +185,25 @@ private:
|
|||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @cond
|
||||
*/
|
||||
class TouchScriptHandlerEntry : public ScriptHandlerEntry
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
|
||||
static TouchScriptHandlerEntry* create(int handler, bool isMultiTouches, int priority, bool swallowsTouches);
|
||||
/**
|
||||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
|
||||
virtual ~TouchScriptHandlerEntry();
|
||||
/**
|
||||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
|
||||
bool isMultiTouches(void) {
|
||||
return _isMultiTouches;
|
||||
}
|
||||
/**
|
||||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
|
||||
int getPriority(void) {
|
||||
return _priority;
|
||||
}
|
||||
/**
|
||||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
|
||||
bool getSwallowsTouches(void) {
|
||||
return _swallowsTouches;
|
||||
}
|
||||
|
@ -199,6 +223,11 @@ private:
|
|||
bool _swallowsTouches;
|
||||
};
|
||||
|
||||
/**
|
||||
* @endcond
|
||||
*/
|
||||
|
||||
/** ScriptEventType enum*/
|
||||
enum ScriptEventType
|
||||
{
|
||||
kNodeEvent = 0,
|
||||
|
@ -215,17 +244,26 @@ enum ScriptEventType
|
|||
kRestartGame
|
||||
};
|
||||
|
||||
/**
|
||||
* For Lua, Wrapper the script data that should be used to find the handler corresponding to the Lua function by the nativeobject pointer and store the value pointer which would be converted concretely by the different events,then the converted data would be passed into the Lua stack.
|
||||
*
|
||||
* @lua NA.
|
||||
* @js NA.
|
||||
*/
|
||||
struct BasicScriptData
|
||||
{
|
||||
// nativeobject:to get handler for lua or to get jsobject for js
|
||||
/**
|
||||
* For Lua, nativeobject is used to get handler corresponding to the Lua function.
|
||||
*/
|
||||
void* nativeObject;
|
||||
// value: a pointer to a object that already defined
|
||||
|
||||
/**
|
||||
* A pointer point to the value data which would be converted by different events.
|
||||
*/
|
||||
void* value;
|
||||
|
||||
// Constructor
|
||||
/**
|
||||
* @js NA
|
||||
* @lua NA
|
||||
* Constructor of BasicScriptData.
|
||||
*/
|
||||
BasicScriptData(void* inObject,void* inValue = nullptr)
|
||||
: nativeObject(inObject),value(inValue)
|
||||
|
@ -233,18 +271,23 @@ struct BasicScriptData
|
|||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* For Lua, the SchedulerScriptData is used to find the Lua function pointer by the handler, then call the Lua function by push the elapse into the Lua stack as a parameter when scheduler update event is triggered.
|
||||
*
|
||||
* @lua NA.
|
||||
* @js NA.
|
||||
*/
|
||||
struct SchedulerScriptData
|
||||
{
|
||||
// lua use
|
||||
/** the handler corresponding to the Lua function pointer, only use in the Lua.*/
|
||||
int handler;
|
||||
/** the parameter would be passed in to the Lua function, only use in the Lua.*/
|
||||
float elapse;
|
||||
// js use
|
||||
void* node;
|
||||
|
||||
// Constructor
|
||||
/**
|
||||
* @js NA
|
||||
* @lua NA
|
||||
* Construtor of SchedulerScriptData.
|
||||
*/
|
||||
SchedulerScriptData(int inHandler,float inElapse,void* inNode = nullptr)
|
||||
: handler(inHandler),
|
||||
|
@ -254,17 +297,25 @@ struct SchedulerScriptData
|
|||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* For Lua, the TouchesScriptData is used to find the Lua function pointer by the nativeObject, then call the Lua function by push touches data and actionType into the Lua stack as the parameters when the touches event is triggered.
|
||||
*
|
||||
* @lua NA
|
||||
* @js NA
|
||||
*/
|
||||
struct TouchesScriptData
|
||||
{
|
||||
/** The EventTouch::EventCode type. */
|
||||
EventTouch::EventCode actionType;
|
||||
/** For Lua, it Used to find the Lua function pointer by the ScriptHandlerMgr. */
|
||||
void* nativeObject;
|
||||
/** The vector of Touch.For Lua, it would be convert to the Lua table form to be pushed into the Lua stack. */
|
||||
const std::vector<Touch*>& touches;
|
||||
/** event information, it is useless for Lua. */
|
||||
Event* event;
|
||||
|
||||
// Constructor
|
||||
/**
|
||||
* @js NA
|
||||
* @lua NA
|
||||
* Constructor of TouchesScriptData.
|
||||
*/
|
||||
TouchesScriptData(EventTouch::EventCode inActionType, void* inNativeObject, const std::vector<Touch*>& inTouches, Event* evt)
|
||||
: actionType(inActionType),
|
||||
|
@ -275,17 +326,25 @@ struct TouchesScriptData
|
|||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* For Lua, the TouchScriptData is used to find the Lua function pointer by the nativeObject, then call the Lua function by push touch data and actionType convered to string type into the Lua stack as the parameters when the touch event is triggered.
|
||||
*
|
||||
* @lua NA.
|
||||
* @js NA.
|
||||
*/
|
||||
struct TouchScriptData
|
||||
{
|
||||
/** The EventTouch::EventCode type. */
|
||||
EventTouch::EventCode actionType;
|
||||
/** For Lua, it Used to find the Lua function pointer by the ScriptHandlerMgr. */
|
||||
void* nativeObject;
|
||||
/** touch information. it would be in x,y form to push into the Lua stack. */
|
||||
Touch* touch;
|
||||
/** event information,it is useless for Lua. */
|
||||
Event* event;
|
||||
|
||||
// Constructor
|
||||
/**
|
||||
* @js NA
|
||||
* @lua NA
|
||||
/**
|
||||
* Constructor of TouchScriptData.
|
||||
*/
|
||||
TouchScriptData(EventTouch::EventCode inActionType, void* inNativeObject, Touch* inTouch, Event* evt)
|
||||
: actionType(inActionType),
|
||||
|
@ -296,15 +355,22 @@ struct TouchScriptData
|
|||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* For Lua, the KeypadScriptData is used to find the Lua function pointer by the nativeObject, then call the Lua function by push the actionType convered to string type into the Lua stack as the parameters when the Keypad event is triggered.
|
||||
*
|
||||
* @lua NA
|
||||
* @js NA
|
||||
*/
|
||||
struct KeypadScriptData
|
||||
{
|
||||
/** The specific type of EventKeyboard::KeyCode*/
|
||||
EventKeyboard::KeyCode actionType;
|
||||
/** For Lua, it Used to find the Lua function pointer by the ScriptHandlerMgr. */
|
||||
void* nativeObject;
|
||||
|
||||
// Constructor
|
||||
/**
|
||||
* @js NA
|
||||
* @lua NA
|
||||
* Constructor of KeypadScriptData.
|
||||
*/
|
||||
KeypadScriptData(EventKeyboard::KeyCode inActionType,void* inNativeObject)
|
||||
: actionType(inActionType),nativeObject(inNativeObject)
|
||||
|
@ -312,19 +378,25 @@ struct KeypadScriptData
|
|||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* For Lua, the CommonScriptData is used to find the Lua function pointer by the handler, then call the Lua function by push the eventName, eventSource(if it not nullptr), eventSourceClassName(if it is nullptr or "", and the eventSource is not nullptr,would give the default string "cc.Ref") into the Lua stack as the parameter when the common event such as is triggered.
|
||||
*
|
||||
* @lua NA
|
||||
* @js NA
|
||||
*/
|
||||
struct CommonScriptData
|
||||
{
|
||||
// Now this struct is only used in LuaBinding.
|
||||
/** The index to find the corresponding to the Lua function pointer. */
|
||||
int handler;
|
||||
/** The string value to be pushed into the Lua stack. */
|
||||
char eventName[64];
|
||||
/** The source object trigger the event,could be nullptr. */
|
||||
Ref* eventSource;
|
||||
/** The class name of source object trigger the event, could be nullptr. */
|
||||
char eventSourceClassName[64];
|
||||
|
||||
// Constructor
|
||||
/**
|
||||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
/** Constructor of CommonScriptData*/
|
||||
CommonScriptData(int inHandler,const char* inName, Ref* inSource = nullptr,const char* inClassName = nullptr)
|
||||
: handler(inHandler),
|
||||
eventSource(inSource)
|
||||
|
@ -342,16 +414,21 @@ struct CommonScriptData
|
|||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* The ScriptEvent wrapper the different script data corresponding to the ScriptEventType in to the unified struct.
|
||||
* when the corresponding event is triggered, we could call the `sendEvent` of ScriptEngineProtocol to handle the event.
|
||||
*
|
||||
* @lua NA.
|
||||
* @js NA.
|
||||
*/
|
||||
struct ScriptEvent
|
||||
{
|
||||
/** The specific type of ScriptEventType. */
|
||||
ScriptEventType type;
|
||||
/** Pointer point to the different data. */
|
||||
void* data;
|
||||
|
||||
// Constructor
|
||||
/**
|
||||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
/** Constructor of ScriptEvent .*/
|
||||
ScriptEvent(ScriptEventType inType,void* inData)
|
||||
: type(inType),
|
||||
data(inData)
|
||||
|
@ -359,162 +436,172 @@ struct ScriptEvent
|
|||
}
|
||||
};
|
||||
|
||||
// Don't make ScriptEngineProtocol inherits from Object since setScriptEngine is invoked only once in AppDelegate.cpp,
|
||||
// It will affect the lifecycle of ScriptCore instance, the autorelease pool will be destroyed before destructing ScriptCore.
|
||||
// So a crash will appear on Win32 if you click the close button.
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @lua NA.
|
||||
* @js NA.
|
||||
*/
|
||||
class CC_DLL ScriptEngineProtocol
|
||||
{
|
||||
public:
|
||||
|
||||
/** Constructor of ScriptEngineProtocol. */
|
||||
ScriptEngineProtocol()
|
||||
{};
|
||||
|
||||
/**
|
||||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
/** Destructor of ScriptEngineProtocol. */
|
||||
virtual ~ScriptEngineProtocol() {};
|
||||
|
||||
/** Get script type
|
||||
* @js NA
|
||||
* @lua NA
|
||||
/**
|
||||
* Get the specific script type.
|
||||
*
|
||||
* @return the specific script type.
|
||||
*/
|
||||
virtual ccScriptType getScriptType() { return kScriptTypeNone; };
|
||||
|
||||
/** Remove script object.
|
||||
* @js NA
|
||||
* @lua NA
|
||||
/**
|
||||
* Remove script object,The specific meaning should refer to the ScriptType.
|
||||
* For Lua, @see removeScriptObjectByObject of LuaEngine.
|
||||
*/
|
||||
virtual void removeScriptObjectByObject(Ref* obj) = 0;
|
||||
|
||||
/** Remove script function handler, only LuaEngine class need to implement this function.
|
||||
* @js NA
|
||||
* @lua NA
|
||||
/**
|
||||
* Remove script function handler, only LuaEngine class need to implement this function.
|
||||
* @see removeScriptHandler of LuaEngine.
|
||||
*/
|
||||
virtual void removeScriptHandler(int handler) {};
|
||||
|
||||
/** Reallocate script function handler, only LuaEngine class need to implement this function.
|
||||
* @js NA
|
||||
* @lua NA
|
||||
/**
|
||||
* Reallocate script function handler, only LuaEngine class need to implement this function.
|
||||
* @see reallocateScriptHandler of LuaEngine.
|
||||
*/
|
||||
virtual int reallocateScriptHandler(int handler) { return 0;}
|
||||
|
||||
/**
|
||||
@brief Execute script code contained in the given string.
|
||||
@param codes holding the valid script code that should be executed.
|
||||
@return 0 if the string is executed correctly.
|
||||
@return other if the string is executed wrongly.
|
||||
* @js NA
|
||||
* @lua NA
|
||||
* Execute script code contained in the given string.
|
||||
*
|
||||
* @param codes holding the valid script code that should be executed.
|
||||
* @return 0 if the string is executed correctly.
|
||||
* @return other if the string is executed wrongly.
|
||||
*/
|
||||
virtual int executeString(const char* codes) = 0;
|
||||
|
||||
/**
|
||||
@brief Execute a script file.
|
||||
@param filename String object holding the filename of the script file that is to be executed
|
||||
* @js NA
|
||||
* @lua NA
|
||||
* Execute a script file.
|
||||
*
|
||||
* @param filename String object holding the filename of the script file that is to be executed.
|
||||
* @return 0 if it happen the error or it hasn't return value, otherwise it return the value by calling the lua function.
|
||||
*/
|
||||
virtual int executeScriptFile(const char* filename) = 0;
|
||||
|
||||
/**
|
||||
@brief Execute a scripted global function.
|
||||
@brief The function should not take any parameters and should return an integer.
|
||||
@param functionName String object holding the name of the function, in the global script environment, that is to be executed.
|
||||
@return The integer value returned from the script function.
|
||||
* @js NA
|
||||
* @lua NA
|
||||
* Execute a scripted global function.
|
||||
* The function should not take any parameters and should return an integer.
|
||||
*
|
||||
* @param functionName String object holding the name of the function, in the global script environment, that is to be executed.
|
||||
* @return The integer value returned from the script function.
|
||||
*/
|
||||
virtual int executeGlobalFunction(const char* functionName) = 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
|
||||
* @js NA
|
||||
* @lua NA
|
||||
/**
|
||||
* 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 int sendEvent(ScriptEvent* evt) = 0;
|
||||
|
||||
/** called by CCAssert to allow scripting engine to handle failed assertions
|
||||
/**
|
||||
* Handle the assert message.
|
||||
*
|
||||
* @return true if the assert was handled by the script engine, false otherwise.
|
||||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
virtual bool handleAssert(const char *msg) = 0;
|
||||
|
||||
/** Useless for Lua.*/
|
||||
virtual void setCalledFromScript(bool callFromScript) { CC_UNUSED_PARAM(callFromScript); };
|
||||
|
||||
/** Useless for Lua.*/
|
||||
virtual bool isCalledFromScript() { return false; };
|
||||
|
||||
/** ConfigType enum. */
|
||||
enum class ConfigType
|
||||
{
|
||||
NONE,
|
||||
COCOSTUDIO
|
||||
};
|
||||
/** Parse configuration file */
|
||||
/**
|
||||
* Parse configuration file.
|
||||
*
|
||||
* @param type the specific type value.
|
||||
* @param str the information data.
|
||||
*/
|
||||
virtual bool parseConfig(ConfigType type, const std::string& str) = 0;
|
||||
};
|
||||
|
||||
class Node;
|
||||
/**
|
||||
ScriptEngineManager is a singleton which holds an object instance of ScriptEngineProtocl
|
||||
It helps cocos2d-x and the user code to find back LuaEngine object
|
||||
@since v0.99.5-x-0.8.5
|
||||
* ScriptEngineManager is a singleton which manager an object instance of ScriptEngineProtocl, such as LuaEngine.
|
||||
*
|
||||
* @since v0.99.5-x-0.8.5
|
||||
* @lua NA.
|
||||
* @js NA.
|
||||
*/
|
||||
class CC_DLL ScriptEngineManager
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
/** Constructor of ScriptEngineManager */
|
||||
~ScriptEngineManager(void);
|
||||
/**
|
||||
* @js NA
|
||||
* @lua NA
|
||||
/**
|
||||
* Get the ScriptEngineProtocol object.
|
||||
*
|
||||
* @return the ScriptEngineProtocol object.
|
||||
*/
|
||||
ScriptEngineProtocol* getScriptEngine(void) {
|
||||
return _scriptEngine;
|
||||
}
|
||||
/**
|
||||
* @js NA
|
||||
* @lua NA
|
||||
* Set the ScriptEngineProtocol object should be managered.
|
||||
*
|
||||
* @param scriptEngine should be managered.
|
||||
*/
|
||||
void setScriptEngine(ScriptEngineProtocol *scriptEngine);
|
||||
|
||||
/**
|
||||
* @js NA
|
||||
* @lua NA
|
||||
* Remove the ScriptEngineProtocol object managered.
|
||||
*/
|
||||
void removeScriptEngine(void);
|
||||
/**
|
||||
* @js NA
|
||||
* @lua NA
|
||||
* Get the instance of ScriptEngineManager object.
|
||||
*
|
||||
* @return the instance of ScriptEngineManager object.
|
||||
*/
|
||||
static ScriptEngineManager* getInstance();
|
||||
/**
|
||||
* @js NA
|
||||
* @lua NA
|
||||
* Destroy the singleton about ScriptEngineManager.
|
||||
*/
|
||||
static void destroyInstance();
|
||||
/**
|
||||
* @js NA
|
||||
* @lua NA
|
||||
*
|
||||
*/
|
||||
static bool sendNodeEventToJS(Node* node, int action);
|
||||
/**
|
||||
* @js NA
|
||||
* @lua NA
|
||||
*
|
||||
*/
|
||||
static bool sendNodeEventToJSExtended(Node* node, int action);
|
||||
/**
|
||||
* @js NA
|
||||
* @lua NA
|
||||
* Call the Lua function when the event of node is triggered.
|
||||
*
|
||||
* @param node the nativeobject triggers the event
|
||||
* @param action the specific type
|
||||
*/
|
||||
static void sendNodeEventToLua(Node* node, int action);
|
||||
/**
|
||||
* @js NA
|
||||
* @lua NA
|
||||
* @deprecated Use getInstance() instead.
|
||||
*/
|
||||
CC_DEPRECATED_ATTRIBUTE static ScriptEngineManager* sharedManager() { return ScriptEngineManager::getInstance(); };
|
||||
/**
|
||||
* @js NA
|
||||
* @lua NA
|
||||
* @deprecated Use destroyInstance() instead.
|
||||
*/
|
||||
CC_DEPRECATED_ATTRIBUTE static void purgeSharedManager() { ScriptEngineManager::destroyInstance(); };
|
||||
|
||||
|
|
|
@ -25,16 +25,61 @@ using namespace cocos2d;
|
|||
#define LUAJ_REGISTRY_FUNCTION "luaj_function_id" // table[function] = id
|
||||
#define LUAJ_REGISTRY_RETAIN "luaj_function_id_retain" // table[id] = retain count
|
||||
|
||||
|
||||
/**
|
||||
* Build a bridge between Java and Lua script.
|
||||
* This mechanism make Lua and Java call each other easily.
|
||||
* @js NA
|
||||
*/
|
||||
class LuaJavaBridge
|
||||
{
|
||||
public:
|
||||
///@cond
|
||||
/**
|
||||
* Bind callStaticMethod of LuaJavaBridge to Lua.
|
||||
* In current mechanism,we could call LuaJavaBridge.callStaticMethod(className, methodName, args) in Lua directly.
|
||||
* Meanwhile the callStaticMethod of LuaObjcBridge binding function is wrapped in the luaj.lua
|
||||
* @lua NA
|
||||
*/
|
||||
static void luaopen_luaj(lua_State *L);
|
||||
///@endcond
|
||||
|
||||
/**
|
||||
* Add a reference count for the Lua functionId,and save this reference in the Lua table named luaj_function_id_retain.
|
||||
*
|
||||
* @param functionId the id of Lua function.
|
||||
* @return the reference count of the functionId if luaj_function_id_retain table exists and the corresponding value for functionId exists, otherwise return 0.
|
||||
* @lua NA
|
||||
*/
|
||||
static int retainLuaFunctionById(int functionId);
|
||||
|
||||
/**
|
||||
* Release a reference count for the Lua functionId, If the reference count is still greater than 0,save this reference in the Lua table named luaj_function_id_retain.
|
||||
* Otherwise, remove the refrence about this functionId in the luaj_function_id table and the luaj_function_id_retain table by set the corresponding value nil.
|
||||
*
|
||||
* @param functionId the id of Lua function.
|
||||
* @return the reference count of the functionId if the luaj_function_id table, the luaj_function_id_retain table and the corresponding value for functionId exists a reference count for the Lua functionId is still greater than 0,and otherwise return 0.
|
||||
* @lua NA
|
||||
*/
|
||||
static int releaseLuaFunctionById(int functionId);
|
||||
|
||||
/**
|
||||
* Call the Lua function corresponding to the functionId with the string pointer arg.
|
||||
*
|
||||
* @param functionId the values corresponding to the Lua function.
|
||||
* @param arg the string pointer point to the argument.
|
||||
* @return a number value returned frome the Lua function when call sucessfully, otherwise return -1 or the opposite number for one of the three numbers LUA_ERRRUN,LUA_ERRMEM and LUA_ERRERR.
|
||||
* @lua NA
|
||||
*/
|
||||
static int callLuaFunctionById(int functionId, const char *arg);
|
||||
|
||||
/**
|
||||
* Call a global Lua function named functionName with the string pointer arg.
|
||||
*
|
||||
* @param functionName the name of global function.
|
||||
* @param arg the string pointer point to the argument.
|
||||
* @return a number value returned frome the Lua function when call sucessfully, otherwise return -1 or the opposite number for one of the three numbers LUA_ERRRUN,LUA_ERRMEM and LUA_ERRERR.
|
||||
* @lua NA
|
||||
*/
|
||||
static int callLuaGlobalFunction(const char *functionName, const char *arg);
|
||||
|
||||
private:
|
||||
|
|
|
@ -6,9 +6,23 @@
|
|||
|
||||
NS_CC_BEGIN
|
||||
|
||||
/**
|
||||
* Build a bridge between ObjectC and Lua script.
|
||||
* This mechanism make Lua and ObjectC call each other easily.
|
||||
*
|
||||
* @js NA
|
||||
*/
|
||||
class LuaObjcBridge : public LuaBridge
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Bind callObjcStaticMethod of LuaObjcBridge to Lua.
|
||||
* In current mechanism,we could call LuaObjcBridge.callStaticMethod(className, methodName, args) in Lua directly.
|
||||
* Meanwhile the callObjcStaticMethod of LuaObjcBridge binding function is wrapped in the luaoc.lua
|
||||
*
|
||||
* @param L the current lua_State
|
||||
* @lua NA
|
||||
*/
|
||||
static void luaopen_luaoc(lua_State *L);
|
||||
|
||||
protected:
|
||||
|
@ -16,7 +30,6 @@ protected:
|
|||
|
||||
static void pushValue(lua_State *L, void *val);
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
||||
#endif // __LUA_OBJC_BRIDGE_H_
|
||||
|
|
|
@ -7,20 +7,121 @@
|
|||
#define TOLUA_REFID_PTR_MAPPING "toluafix_refid_ptr_mapping"
|
||||
#define TOLUA_REFID_TYPE_MAPPING "toluafix_refid_type_mapping"
|
||||
#define TOLUA_REFID_FUNCTION_MAPPING "toluafix_refid_function_mapping"
|
||||
|
||||
/// @cond
|
||||
TOLUA_API void toluafix_open(lua_State* L);
|
||||
/// @endcond
|
||||
|
||||
/**
|
||||
* Push the userdata correspondings to the ptr on the top index of the Lua stack.
|
||||
* If the userdata correspondings to the ptr don't exist, it would call lua_newuserdata to new a userdata.
|
||||
* If the userdata correspondings to the ptr exist,it would update the metatable information of the super.
|
||||
* In addition, this function would update some table in the Lua registry,such as toluafix_refid_ptr_mapping, toluafix_refid_type_mapping,tolua_value_root,and so on.
|
||||
* Meanwhile, Add a refrence about the userdata corresponding to the ptr in the tolua_ubox table.
|
||||
* The ptr should be point to a Ref object.
|
||||
*
|
||||
* @param L the current lua_State.
|
||||
* @param uid the object id of the ptr.
|
||||
* @param p_refid the pointer points to the Lua reference id of the ptr.
|
||||
* @param ptr the pointer points to the Ref object.
|
||||
* @param type the type name of the ptr.
|
||||
* @return -1 if the p_refid equal to nullptr or ptr equal to nullptr, otherwise return 0.
|
||||
* @lua NA.
|
||||
* @js NA.
|
||||
*/
|
||||
TOLUA_API int toluafix_pushusertype_ccobject(lua_State* L,
|
||||
int uid,
|
||||
int* p_refid,
|
||||
void* ptr,
|
||||
const char* type);
|
||||
|
||||
/**
|
||||
* Find the value of Ref object pointer in the Lua registry by the refid.
|
||||
* Then, remove the corresponding refrence in some table in the Lua registry by refid, such as toluafix_refid_type_mapping, toluafix_refid_ptr_mapping,tolua_value_root,and so on.
|
||||
* Set the value of userdata nullptr and remove the refrence of userdata in the tolua_ubox table.
|
||||
* This function is called in the destructor of the Ref automatically.
|
||||
*
|
||||
* @param L the current lua_State.
|
||||
* @param refid the value of the _luaID of a Ref object.
|
||||
* @return -1,if refid equals to 0 , type name found by refid equals to nil or corresponding userdata pointer equal to nullptr; return -2, if the Ref object pointer found by refid is nullptr; return 3, if the value corresponding to the Ref object pointer in the tolua_ubox is nil; otherwise return 0.
|
||||
* @lua NA.
|
||||
* @js NA.
|
||||
*/
|
||||
TOLUA_API int toluafix_remove_ccobject_by_refid(lua_State* L, int refid);
|
||||
|
||||
/**
|
||||
* Get the refrence id of the Lua function at the given accepteable index lo of stack.
|
||||
* Meanwhile add refrence about the Lua function through the toluafix_refid_function_mapping table in the Lua registry.
|
||||
*
|
||||
* @param L the current lua_State.
|
||||
* @param lo the given accepteable index lo of stack.
|
||||
* @param def useless.
|
||||
* @return 0 if the type of value at the given accepteable index lo of stack is not LUA_TFUNCTION; otherwise return the refrence id.
|
||||
* @lua NA.
|
||||
* @js NA.
|
||||
*/
|
||||
TOLUA_API int toluafix_ref_function(lua_State* L, int lo, int def);
|
||||
|
||||
/**
|
||||
* Push the Lua function found by the refid in the toluafix_refid_function_mapping table in the Lua registry on the top index of the current stack.
|
||||
*
|
||||
* @param L the current lua_State.
|
||||
* @param refid referenc id corresponding to the Lua function.
|
||||
* @lua NA.
|
||||
* @js NA.
|
||||
*/
|
||||
TOLUA_API void toluafix_get_function_by_refid(lua_State* L, int refid);
|
||||
|
||||
/**
|
||||
* Remove the reference of the Lua function corresponding to the refid in the toluafix_refid_function_mapping table in the Lua registry.
|
||||
*
|
||||
* @param L the current lua_State.
|
||||
* @param refid referenc id corresponding to the Lua function.
|
||||
* @lua NA.
|
||||
* @js NA.
|
||||
*/
|
||||
TOLUA_API void toluafix_remove_function_by_refid(lua_State* L, int refid);
|
||||
|
||||
/**
|
||||
* Verify the value at the given acceptable index is a function or not.
|
||||
*
|
||||
* @param L the current lua_State.
|
||||
* @param lo the given accepteable index lo of stack.
|
||||
* @param type useless.
|
||||
* @param def useless.
|
||||
* @param err if triggger the error, record the error message to err.
|
||||
* @return 1 if the value at the given acceptable index is a function, otherwise return 0.
|
||||
* @lua NA.
|
||||
* @js NA.
|
||||
*/
|
||||
TOLUA_API int toluafix_isfunction(lua_State* L, int lo, const char* type, int def, tolua_Error* err);
|
||||
|
||||
/// @cond
|
||||
TOLUA_API int toluafix_totable(lua_State* L, int lo, int def);
|
||||
/// @endcond
|
||||
|
||||
/**
|
||||
* Verify the value at the given acceptable index is a table or not.
|
||||
*
|
||||
* @param L the current lua_State.
|
||||
* @param lo the given accepteable index lo of stack.
|
||||
* @param type useless.
|
||||
* @param def whether has the default value.
|
||||
* @param err if triggger the error, record the error message to err.
|
||||
* @return 1 if the value at the given acceptable index is a table or have def value is not 0, otherwise return 0.
|
||||
* @lua NA.
|
||||
* @js NA.
|
||||
*/
|
||||
TOLUA_API int toluafix_istable(lua_State* L, int lo, const char* type, int def, tolua_Error* err);
|
||||
|
||||
/**
|
||||
* Print all information of the stack from the top index.
|
||||
* If the type corresponding to the index of the stack is LUA_TSTRING, LUA_TBOOLEAN or LUA_TNUMBER, it would output the value of the index,otherwise output the type name of the index.
|
||||
*
|
||||
* @param L the current lua_State.
|
||||
* @param label the string pointer to define the label of the dump information.
|
||||
* @lua NA.
|
||||
* @js NA.
|
||||
*/
|
||||
TOLUA_API void toluafix_stack_dump(lua_State* L, const char* label);
|
||||
|
||||
#endif // __TOLUA_FIX_H_
|
||||
|
|
Loading…
Reference in New Issue