mirror of https://github.com/axmolengine/axmol.git
remove CC_LUA_ENGINE_ENABLED macro
This commit is contained in:
parent
cc69e39c8a
commit
57bccc7e4a
|
@ -35,11 +35,11 @@ THE SOFTWARE.
|
|||
#include "CCStdC.h"
|
||||
|
||||
#ifndef CCAssert
|
||||
#if CC_LUA_ENGINE_ENABLED > 0
|
||||
extern void cc_lua_assert(bool cond, const char *msg);
|
||||
#define CCAssert(cond, msg) cc_lua_assert(cond, msg)
|
||||
#if COCOS2D_DEBUG > 0
|
||||
extern void cc_assert_script_compatible(bool cond, const char *msg);
|
||||
#define CCAssert(cond, msg) cc_assert_script_compatible(cond, msg)
|
||||
#else
|
||||
#define CCAssert(cond, msg) CC_ASSERT(cond)
|
||||
#define CCAssert(cond, msg)
|
||||
#endif
|
||||
#endif // CCAssert
|
||||
|
||||
|
|
|
@ -25,6 +25,17 @@
|
|||
#include "CCScriptSupport.h"
|
||||
#include "CCScheduler.h"
|
||||
|
||||
void cc_assert_script_compatible(bool cond, const char *msg)
|
||||
{
|
||||
cocos2d::CCScriptEngineProtocol* pEngine = cocos2d::CCScriptEngineManager::sharedManager()->getScriptEngine();
|
||||
if (!cond && pEngine && pEngine->executeAssert(cond, msg))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
CC_ASSERT(cond);
|
||||
}
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
// #pragma mark -
|
||||
|
|
|
@ -222,6 +222,8 @@ public:
|
|||
|
||||
/** execute a accelerometer event */
|
||||
virtual int executeAccelerometerEvent(CCLayer* pLayer, CCAcceleration* pAccelerationValue) = 0;
|
||||
/** function for assert test */
|
||||
virtual bool executeAssert(bool cond, const char *msg = NULL) = 0;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -85,6 +85,7 @@ public:
|
|||
virtual int executeLayerTouchEvent(CCLayer* pLayer, int eventType, CCTouch *pTouch);
|
||||
virtual int executeAccelerometerEvent(CCLayer* pLayer, CCAcceleration* pAccelerationValue);
|
||||
virtual int executeLayerKeypadEvent(CCLayer* pLayer, int eventType);
|
||||
virtual bool executeAssert(bool cond, const char *msg = NULL) {return false;}
|
||||
|
||||
bool executeFunctionWithObjectData(CCNode *self, const char *name, JSObject *obj);
|
||||
int executeFunctionWithOwner(jsval owner, const char *name, jsval data);
|
||||
|
|
|
@ -40,20 +40,6 @@ extern "C" {
|
|||
#include "Cocos2dxLuaLoader.h"
|
||||
#endif
|
||||
|
||||
static bool in_lua_execute = false;
|
||||
static lua_State *in_lua_state = NULL;
|
||||
|
||||
void cc_lua_assert(bool cond, const char *msg)
|
||||
{
|
||||
if (!cond && in_lua_execute && in_lua_state)
|
||||
{
|
||||
lua_pushfstring(in_lua_state, "ASSERT FAILED ON LUA EXECUTE: %s", msg ? msg : "unknown");
|
||||
lua_error(in_lua_state);
|
||||
return;
|
||||
}
|
||||
CC_ASSERT(cond);
|
||||
}
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
// #pragma mark -
|
||||
|
@ -252,11 +238,9 @@ void CCLuaEngine::addSearchPath(const char* path)
|
|||
|
||||
int CCLuaEngine::executeString(const char *codes)
|
||||
{
|
||||
in_lua_execute = true;
|
||||
in_lua_state = m_state;
|
||||
m_callFromLua = true;
|
||||
int nRet = luaL_dostring(m_state, codes);
|
||||
in_lua_execute = false;
|
||||
in_lua_state = NULL;
|
||||
m_callFromLua = false;
|
||||
lua_gc(m_state, LUA_GCCOLLECT, 0);
|
||||
|
||||
if (nRet != 0)
|
||||
|
@ -270,11 +254,9 @@ int CCLuaEngine::executeString(const char *codes)
|
|||
|
||||
int CCLuaEngine::executeScriptFile(const char* filename)
|
||||
{
|
||||
in_lua_execute = true;
|
||||
in_lua_state = m_state;
|
||||
m_callFromLua = true;
|
||||
int nRet = luaL_dofile(m_state, filename);
|
||||
in_lua_execute = false;
|
||||
in_lua_state = NULL;
|
||||
m_callFromLua = false;
|
||||
// lua_gc(m_state, LUA_GCCOLLECT, 0);
|
||||
|
||||
if (nRet != 0)
|
||||
|
@ -296,11 +278,9 @@ int CCLuaEngine::executeGlobalFunction(const char* functionName)
|
|||
return 0;
|
||||
}
|
||||
|
||||
in_lua_execute = true;
|
||||
in_lua_state = m_state;
|
||||
m_callFromLua = true;
|
||||
int error = lua_pcall(m_state, 0, 1, 0); /* call function, stack: ret */
|
||||
in_lua_execute = false;
|
||||
in_lua_state = NULL;
|
||||
m_callFromLua = false;
|
||||
// lua_gc(m_state, LUA_GCCOLLECT, 0);
|
||||
|
||||
if (error)
|
||||
|
@ -502,6 +482,15 @@ int CCLuaEngine::executeAccelerometerEvent(CCLayer* pLayer, CCAcceleration* pAcc
|
|||
return ret;
|
||||
}
|
||||
|
||||
bool CCLuaEngine::executeAssert(bool cond, const char *msg/* = NULL */)
|
||||
{
|
||||
if (!m_callFromLua) return false;
|
||||
|
||||
lua_pushfstring(m_state, "ASSERT FAILED ON LUA EXECUTE: %s", msg ? msg : "unknown");
|
||||
lua_error(m_state);
|
||||
return true;
|
||||
}
|
||||
|
||||
int CCLuaEngine::executeFunctionByHandler(int nHandler, int numArgs)
|
||||
{
|
||||
if (pushFunction(nHandler)) /* stack: ... arg1 arg2 ... func */
|
||||
|
@ -524,11 +513,9 @@ int CCLuaEngine::executeFunctionByHandler(int nHandler, int numArgs)
|
|||
}
|
||||
|
||||
int error = 0;
|
||||
in_lua_execute = true;
|
||||
in_lua_state = m_state;
|
||||
m_callFromLua = true;
|
||||
error = lua_pcall(m_state, numArgs, 1, traceback); /* stack: ... ret */
|
||||
in_lua_execute = false;
|
||||
in_lua_state = NULL;
|
||||
m_callFromLua = false;
|
||||
if (error)
|
||||
{
|
||||
if (traceback == 0)
|
||||
|
|
|
@ -200,6 +200,7 @@ public:
|
|||
virtual int executeLayerKeypadEvent(CCLayer* pLayer, int eventType);
|
||||
/** execute a accelerometer event */
|
||||
virtual int executeAccelerometerEvent(CCLayer* pLayer, CCAcceleration* pAccelerationValue);
|
||||
virtual bool executeAssert(bool cond, const char *msg = NULL);
|
||||
/**
|
||||
@brief Method used to get a pointer to the lua_State that the script module is attached to.
|
||||
@return A pointer to the lua_State that the script module is attached to.
|
||||
|
@ -227,6 +228,7 @@ public:
|
|||
private:
|
||||
CCLuaEngine(void)
|
||||
: m_state(NULL)
|
||||
, m_callFromLua(false)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -234,6 +236,8 @@ private:
|
|||
bool pushFunction(int nHandler);
|
||||
|
||||
lua_State* m_state;
|
||||
bool m_callFromLua;
|
||||
|
||||
static CCLuaEngine* m_defaultEngine;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue