mirror of https://github.com/axmolengine/axmol.git
Merge pull request #1303 from dualface/gles20
fixed #1477: Updated CCLuaEngine for new script binding protocol.
This commit is contained in:
commit
fe5c2f438d
|
@ -48,10 +48,6 @@ enum ccScriptType {
|
||||||
kScriptTypeJavascript
|
kScriptTypeJavascript
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef int LUA_FUNCTION;
|
|
||||||
typedef int LUA_TABLE;
|
|
||||||
typedef int LUA_STRING;
|
|
||||||
|
|
||||||
// #pragma mark -
|
// #pragma mark -
|
||||||
// #pragma mark CCScriptHandlerEntry
|
// #pragma mark CCScriptHandlerEntry
|
||||||
|
|
||||||
|
|
|
@ -43,128 +43,128 @@ extern "C" {
|
||||||
NS_CC_BEGIN
|
NS_CC_BEGIN
|
||||||
|
|
||||||
// #pragma mark -
|
// #pragma mark -
|
||||||
// #pragma mark CCScriptValue
|
// #pragma mark CCLuaValue
|
||||||
|
|
||||||
const CCScriptValue CCScriptValue::intValue(const int intValue)
|
const CCLuaValue CCLuaValue::intValue(const int intValue)
|
||||||
{
|
{
|
||||||
CCScriptValue value;
|
CCLuaValue value;
|
||||||
value.m_type = CCScriptValueTypeInt;
|
value.m_type = CCLuaValueTypeInt;
|
||||||
value.m_field.intValue = intValue;
|
value.m_field.intValue = intValue;
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
const CCScriptValue CCScriptValue::floatValue(const float floatValue)
|
const CCLuaValue CCLuaValue::floatValue(const float floatValue)
|
||||||
{
|
{
|
||||||
CCScriptValue value;
|
CCLuaValue value;
|
||||||
value.m_type = CCScriptValueTypeFloat;
|
value.m_type = CCLuaValueTypeFloat;
|
||||||
value.m_field.floatValue = floatValue;
|
value.m_field.floatValue = floatValue;
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
const CCScriptValue CCScriptValue::booleanValue(const bool booleanValue)
|
const CCLuaValue CCLuaValue::booleanValue(const bool booleanValue)
|
||||||
{
|
{
|
||||||
CCScriptValue value;
|
CCLuaValue value;
|
||||||
value.m_type = CCScriptValueTypeBoolean;
|
value.m_type = CCLuaValueTypeBoolean;
|
||||||
value.m_field.booleanValue = booleanValue;
|
value.m_field.booleanValue = booleanValue;
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
const CCScriptValue CCScriptValue::stringValue(const char* stringValue)
|
const CCLuaValue CCLuaValue::stringValue(const char* stringValue)
|
||||||
{
|
{
|
||||||
CCScriptValue value;
|
CCLuaValue value;
|
||||||
value.m_type = CCScriptValueTypeString;
|
value.m_type = CCLuaValueTypeString;
|
||||||
value.m_field.stringValue = new std::string(stringValue);
|
value.m_field.stringValue = new std::string(stringValue);
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
const CCScriptValue CCScriptValue::stringValue(const std::string& stringValue)
|
const CCLuaValue CCLuaValue::stringValue(const std::string& stringValue)
|
||||||
{
|
{
|
||||||
CCScriptValue value;
|
CCLuaValue value;
|
||||||
value.m_type = CCScriptValueTypeString;
|
value.m_type = CCLuaValueTypeString;
|
||||||
value.m_field.stringValue = new std::string(stringValue);
|
value.m_field.stringValue = new std::string(stringValue);
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
const CCScriptValue CCScriptValue::dictValue(const CCScriptValueDict& dictValue)
|
const CCLuaValue CCLuaValue::dictValue(const CCLuaValueDict& dictValue)
|
||||||
{
|
{
|
||||||
CCScriptValue value;
|
CCLuaValue value;
|
||||||
value.m_type = CCScriptValueTypeDict;
|
value.m_type = CCLuaValueTypeDict;
|
||||||
value.m_field.dictValue = new CCScriptValueDict(dictValue);
|
value.m_field.dictValue = new CCLuaValueDict(dictValue);
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
const CCScriptValue CCScriptValue::arrayValue(const CCScriptValueArray& arrayValue)
|
const CCLuaValue CCLuaValue::arrayValue(const CCLuaValueArray& arrayValue)
|
||||||
{
|
{
|
||||||
CCScriptValue value;
|
CCLuaValue value;
|
||||||
value.m_type = CCScriptValueTypeArray;
|
value.m_type = CCLuaValueTypeArray;
|
||||||
value.m_field.arrayValue = new CCScriptValueArray(arrayValue);
|
value.m_field.arrayValue = new CCLuaValueArray(arrayValue);
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
const CCScriptValue CCScriptValue::ccobjectValue(CCObject* ccobjectValue, const char* objectTypename)
|
const CCLuaValue CCLuaValue::ccobjectValue(CCObject* ccobjectValue, const char* objectTypename)
|
||||||
{
|
{
|
||||||
CCScriptValue value;
|
CCLuaValue value;
|
||||||
value.m_type = CCScriptValueTypeCCObject;
|
value.m_type = CCLuaValueTypeCCObject;
|
||||||
value.m_field.ccobjectValue = ccobjectValue;
|
value.m_field.ccobjectValue = ccobjectValue;
|
||||||
ccobjectValue->retain();
|
ccobjectValue->retain();
|
||||||
value.m_ccobjectType = new std::string(objectTypename);
|
value.m_ccobjectType = new std::string(objectTypename);
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
const CCScriptValue CCScriptValue::ccobjectValue(CCObject* ccobjectValue, const std::string& objectTypename)
|
const CCLuaValue CCLuaValue::ccobjectValue(CCObject* ccobjectValue, const std::string& objectTypename)
|
||||||
{
|
{
|
||||||
return CCScriptValue::ccobjectValue(ccobjectValue, objectTypename.c_str());
|
return CCLuaValue::ccobjectValue(ccobjectValue, objectTypename.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
CCScriptValue::CCScriptValue(const CCScriptValue& rhs)
|
CCLuaValue::CCLuaValue(const CCLuaValue& rhs)
|
||||||
{
|
{
|
||||||
copy(rhs);
|
copy(rhs);
|
||||||
}
|
}
|
||||||
|
|
||||||
CCScriptValue& CCScriptValue::operator=(const CCScriptValue& rhs)
|
CCLuaValue& CCLuaValue::operator=(const CCLuaValue& rhs)
|
||||||
{
|
{
|
||||||
if (this != &rhs) copy(rhs);
|
if (this != &rhs) copy(rhs);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
CCScriptValue::~CCScriptValue(void)
|
CCLuaValue::~CCLuaValue(void)
|
||||||
{
|
{
|
||||||
if (m_type == CCScriptValueTypeString)
|
if (m_type == CCLuaValueTypeString)
|
||||||
{
|
{
|
||||||
delete m_field.stringValue;
|
delete m_field.stringValue;
|
||||||
}
|
}
|
||||||
else if (m_type == CCScriptValueTypeDict)
|
else if (m_type == CCLuaValueTypeDict)
|
||||||
{
|
{
|
||||||
delete m_field.dictValue;
|
delete m_field.dictValue;
|
||||||
}
|
}
|
||||||
else if (m_type == CCScriptValueTypeArray)
|
else if (m_type == CCLuaValueTypeArray)
|
||||||
{
|
{
|
||||||
delete m_field.arrayValue;
|
delete m_field.arrayValue;
|
||||||
}
|
}
|
||||||
else if (m_type == CCScriptValueTypeCCObject)
|
else if (m_type == CCLuaValueTypeCCObject)
|
||||||
{
|
{
|
||||||
m_field.ccobjectValue->release();
|
m_field.ccobjectValue->release();
|
||||||
delete m_ccobjectType;
|
delete m_ccobjectType;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCScriptValue::copy(const CCScriptValue& rhs)
|
void CCLuaValue::copy(const CCLuaValue& rhs)
|
||||||
{
|
{
|
||||||
memcpy(&m_field, &rhs.m_field, sizeof(m_field));
|
memcpy(&m_field, &rhs.m_field, sizeof(m_field));
|
||||||
m_type = rhs.m_type;
|
m_type = rhs.m_type;
|
||||||
if (m_type == CCScriptValueTypeString)
|
if (m_type == CCLuaValueTypeString)
|
||||||
{
|
{
|
||||||
m_field.stringValue = new std::string(*rhs.m_field.stringValue);
|
m_field.stringValue = new std::string(*rhs.m_field.stringValue);
|
||||||
}
|
}
|
||||||
else if (m_type == CCScriptValueTypeDict)
|
else if (m_type == CCLuaValueTypeDict)
|
||||||
{
|
{
|
||||||
m_field.dictValue = new CCScriptValueDict(*rhs.m_field.dictValue);
|
m_field.dictValue = new CCLuaValueDict(*rhs.m_field.dictValue);
|
||||||
}
|
}
|
||||||
else if (m_type == CCScriptValueTypeArray)
|
else if (m_type == CCLuaValueTypeArray)
|
||||||
{
|
{
|
||||||
m_field.arrayValue = new CCScriptValueArray(*rhs.m_field.arrayValue);
|
m_field.arrayValue = new CCLuaValueArray(*rhs.m_field.arrayValue);
|
||||||
}
|
}
|
||||||
else if (m_type == CCScriptValueTypeCCObject)
|
else if (m_type == CCLuaValueTypeCCObject)
|
||||||
{
|
{
|
||||||
m_field.ccobjectValue = rhs.m_field.ccobjectValue;
|
m_field.ccobjectValue = rhs.m_field.ccobjectValue;
|
||||||
m_field.ccobjectValue->retain();
|
m_field.ccobjectValue->retain();
|
||||||
|
@ -172,6 +172,21 @@ void CCScriptValue::copy(const CCScriptValue& rhs)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#pragma mark -
|
||||||
|
#pragma mark CCLuaEngine
|
||||||
|
|
||||||
|
CCLuaEngine* CCLuaEngine::m_defaultEngine = NULL;
|
||||||
|
|
||||||
|
CCLuaEngine* CCLuaEngine::defaultEngine(void)
|
||||||
|
{
|
||||||
|
if (!m_defaultEngine)
|
||||||
|
{
|
||||||
|
m_defaultEngine = CCLuaEngine::create();
|
||||||
|
}
|
||||||
|
return m_defaultEngine;
|
||||||
|
}
|
||||||
|
|
||||||
CCLuaEngine* CCLuaEngine::create(void)
|
CCLuaEngine* CCLuaEngine::create(void)
|
||||||
{
|
{
|
||||||
CCLuaEngine* pEngine = new CCLuaEngine();
|
CCLuaEngine* pEngine = new CCLuaEngine();
|
||||||
|
@ -182,6 +197,10 @@ CCLuaEngine* CCLuaEngine::create(void)
|
||||||
CCLuaEngine::~CCLuaEngine(void)
|
CCLuaEngine::~CCLuaEngine(void)
|
||||||
{
|
{
|
||||||
lua_close(m_state);
|
lua_close(m_state);
|
||||||
|
if (this == m_defaultEngine)
|
||||||
|
{
|
||||||
|
m_defaultEngine = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CCLuaEngine::init(void)
|
bool CCLuaEngine::init(void)
|
||||||
|
@ -284,17 +303,17 @@ int CCLuaEngine::executeNodeEvent(CCNode* pNode, int nAction)
|
||||||
{
|
{
|
||||||
int nScriptHandler = pNode->getScriptHandler();
|
int nScriptHandler = pNode->getScriptHandler();
|
||||||
CC_BREAK_IF(0 == nScriptHandler);
|
CC_BREAK_IF(0 == nScriptHandler);
|
||||||
CCScriptValueDict dict;
|
CCLuaValueDict dict;
|
||||||
if (nAction == kCCNodeOnEnter)
|
if (nAction == kCCNodeOnEnter)
|
||||||
{
|
{
|
||||||
dict["name"] = CCScriptValue::stringValue("enter");
|
dict["name"] = CCLuaValue::stringValue("enter");
|
||||||
this->pushCCScriptValueDict(dict);
|
this->pushCCLuaValueDict(dict);
|
||||||
ret = this->executeFunctionByHandler(nScriptHandler, 1);
|
ret = this->executeFunctionByHandler(nScriptHandler, 1);
|
||||||
}
|
}
|
||||||
else if (nAction == kCCNodeOnExit)
|
else if (nAction == kCCNodeOnExit)
|
||||||
{
|
{
|
||||||
dict["name"] = CCScriptValue::stringValue("exit");
|
dict["name"] = CCLuaValue::stringValue("exit");
|
||||||
this->pushCCScriptValueDict(dict);
|
this->pushCCLuaValueDict(dict);
|
||||||
ret = this->executeFunctionByHandler(nScriptHandler, 1);
|
ret = this->executeFunctionByHandler(nScriptHandler, 1);
|
||||||
}
|
}
|
||||||
} while (0);
|
} while (0);
|
||||||
|
@ -308,7 +327,7 @@ int CCLuaEngine::executeMenuItemEvent(CCMenuItem* pMenuItem)
|
||||||
{
|
{
|
||||||
int nScriptHandler = pMenuItem->getScriptTapHandler();
|
int nScriptHandler = pMenuItem->getScriptTapHandler();
|
||||||
CC_BREAK_IF(0 == nScriptHandler);
|
CC_BREAK_IF(0 == nScriptHandler);
|
||||||
ret = this->pushIntegerData(pMenuItem->getTag());
|
ret = this->pushInt(pMenuItem->getTag());
|
||||||
ret = this->executeFunctionByHandler(nScriptHandler, 1);
|
ret = this->executeFunctionByHandler(nScriptHandler, 1);
|
||||||
} while (0);
|
} while (0);
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -321,7 +340,7 @@ int CCLuaEngine::executeNotificationEvent(CCNotificationCenter* pNotificationCen
|
||||||
{
|
{
|
||||||
int nScriptHandler = pNotificationCenter->getScriptHandler();
|
int nScriptHandler = pNotificationCenter->getScriptHandler();
|
||||||
CC_BREAK_IF(0 == nScriptHandler);
|
CC_BREAK_IF(0 == nScriptHandler);
|
||||||
ret = this->pushStringData(pszName);
|
ret = this->pushString(pszName);
|
||||||
ret = this->executeFunctionByHandler(nScriptHandler, 1);
|
ret = this->executeFunctionByHandler(nScriptHandler, 1);
|
||||||
} while (0);
|
} while (0);
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -350,7 +369,7 @@ int CCLuaEngine::executeSchedule(CCTimer* pTimer, float dt, CCNode* pNode/* = NU
|
||||||
{
|
{
|
||||||
int nScriptHandler = pTimer->getScriptHandler();
|
int nScriptHandler = pTimer->getScriptHandler();
|
||||||
CC_BREAK_IF(0 == nScriptHandler);
|
CC_BREAK_IF(0 == nScriptHandler);
|
||||||
ret = this->pushFloatData(dt);
|
ret = this->pushFloat(dt);
|
||||||
ret = this->executeFunctionByHandler(nScriptHandler, 1);
|
ret = this->executeFunctionByHandler(nScriptHandler, 1);
|
||||||
} while (0);
|
} while (0);
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -462,64 +481,76 @@ int CCLuaEngine::executeFunctionByHandler(int nHandler, int numArgs)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int CCLuaEngine::pushIntegerData(int data)
|
int CCLuaEngine::pushInt(int data)
|
||||||
{
|
{
|
||||||
lua_pushinteger(m_state, data);
|
lua_pushinteger(m_state, data);
|
||||||
return lua_gettop(m_state);
|
return lua_gettop(m_state);
|
||||||
}
|
}
|
||||||
|
|
||||||
int CCLuaEngine::pushFloatData(float data)
|
int CCLuaEngine::pushFloat(float data)
|
||||||
{
|
{
|
||||||
lua_pushnumber(m_state, data);
|
lua_pushnumber(m_state, data);
|
||||||
return lua_gettop(m_state);
|
return lua_gettop(m_state);
|
||||||
}
|
}
|
||||||
|
|
||||||
int CCLuaEngine::pushBooleanData(bool data)
|
int CCLuaEngine::pushBoolean(bool data)
|
||||||
{
|
{
|
||||||
lua_pushboolean(m_state, data);
|
lua_pushboolean(m_state, data);
|
||||||
return lua_gettop(m_state);
|
return lua_gettop(m_state);
|
||||||
}
|
}
|
||||||
|
|
||||||
int CCLuaEngine::pushStringData(const char* data)
|
int CCLuaEngine::pushString(const char* data)
|
||||||
{
|
{
|
||||||
lua_pushstring(m_state, data);
|
lua_pushstring(m_state, data);
|
||||||
return lua_gettop(m_state);
|
return lua_gettop(m_state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int CCLuaEngine::pushString(const char* data, int length)
|
||||||
|
{
|
||||||
|
lua_pushlstring(m_state, data, length);
|
||||||
|
return lua_gettop(m_state);
|
||||||
|
}
|
||||||
|
|
||||||
|
int CCLuaEngine::pushNil(void)
|
||||||
|
{
|
||||||
|
lua_pushnil(m_state);
|
||||||
|
return lua_gettop(m_state);
|
||||||
|
}
|
||||||
|
|
||||||
int CCLuaEngine::pushCCObject(CCObject* pObject, const char* typeName)
|
int CCLuaEngine::pushCCObject(CCObject* pObject, const char* typeName)
|
||||||
{
|
{
|
||||||
toluafix_pushusertype_ccobject(m_state, pObject->m_uID, &pObject->m_nLuaID, pObject, typeName);
|
toluafix_pushusertype_ccobject(m_state, pObject->m_uID, &pObject->m_nLuaID, pObject, typeName);
|
||||||
return lua_gettop(m_state);
|
return lua_gettop(m_state);
|
||||||
}
|
}
|
||||||
|
|
||||||
int CCLuaEngine::pushCCScriptValue(const CCScriptValue& value)
|
int CCLuaEngine::pushCCLuaValue(const CCLuaValue& value)
|
||||||
{
|
{
|
||||||
const CCScriptValueType type = value.getType();
|
const CCLuaValueType type = value.getType();
|
||||||
if (type == CCScriptValueTypeInt)
|
if (type == CCLuaValueTypeInt)
|
||||||
{
|
{
|
||||||
return pushIntegerData(value.intValue());
|
return pushInt(value.intValue());
|
||||||
}
|
}
|
||||||
else if (type == CCScriptValueTypeFloat)
|
else if (type == CCLuaValueTypeFloat)
|
||||||
{
|
{
|
||||||
return pushFloatData(value.floatValue());
|
return pushFloat(value.floatValue());
|
||||||
}
|
}
|
||||||
else if (type == CCScriptValueTypeBoolean)
|
else if (type == CCLuaValueTypeBoolean)
|
||||||
{
|
{
|
||||||
return pushBooleanData(value.booleanValue());
|
return pushBoolean(value.booleanValue());
|
||||||
}
|
}
|
||||||
else if (type == CCScriptValueTypeString)
|
else if (type == CCLuaValueTypeString)
|
||||||
{
|
{
|
||||||
return pushStringData(value.stringValue().c_str());
|
return pushString(value.stringValue().c_str());
|
||||||
}
|
}
|
||||||
else if (type == CCScriptValueTypeDict)
|
else if (type == CCLuaValueTypeDict)
|
||||||
{
|
{
|
||||||
pushCCScriptValueDict(value.dictValue());
|
pushCCLuaValueDict(value.dictValue());
|
||||||
}
|
}
|
||||||
else if (type == CCScriptValueTypeArray)
|
else if (type == CCLuaValueTypeArray)
|
||||||
{
|
{
|
||||||
pushCCScriptValueArray(value.arrayValue());
|
pushCCLuaValueArray(value.arrayValue());
|
||||||
}
|
}
|
||||||
else if (type == CCScriptValueTypeCCObject)
|
else if (type == CCLuaValueTypeCCObject)
|
||||||
{
|
{
|
||||||
pushCCObject(value.ccobjectValue(), value.getCCObjectTypename().c_str());
|
pushCCObject(value.ccobjectValue(), value.getCCObjectTypename().c_str());
|
||||||
}
|
}
|
||||||
|
@ -527,26 +558,26 @@ int CCLuaEngine::pushCCScriptValue(const CCScriptValue& value)
|
||||||
return lua_gettop(m_state);
|
return lua_gettop(m_state);
|
||||||
}
|
}
|
||||||
|
|
||||||
int CCLuaEngine::pushCCScriptValueDict(const CCScriptValueDict& dict)
|
int CCLuaEngine::pushCCLuaValueDict(const CCLuaValueDict& dict)
|
||||||
{
|
{
|
||||||
lua_newtable(m_state); /* stack: table */
|
lua_newtable(m_state); /* stack: table */
|
||||||
for (CCScriptValueDictIterator it = dict.begin(); it != dict.end(); ++it)
|
for (CCLuaValueDictIterator it = dict.begin(); it != dict.end(); ++it)
|
||||||
{
|
{
|
||||||
lua_pushstring(m_state, it->first.c_str()); /* stack: table key */
|
lua_pushstring(m_state, it->first.c_str()); /* stack: table key */
|
||||||
pushCCScriptValue(it->second); /* stack: table key value */
|
pushCCLuaValue(it->second); /* stack: table key value */
|
||||||
lua_rawset(m_state, -3); /* table.key = value, stack: table */
|
lua_rawset(m_state, -3); /* table.key = value, stack: table */
|
||||||
}
|
}
|
||||||
|
|
||||||
return lua_gettop(m_state);
|
return lua_gettop(m_state);
|
||||||
}
|
}
|
||||||
|
|
||||||
int CCLuaEngine::pushCCScriptValueArray(const CCScriptValueArray& array)
|
int CCLuaEngine::pushCCLuaValueArray(const CCLuaValueArray& array)
|
||||||
{
|
{
|
||||||
lua_newtable(m_state); /* stack: table */
|
lua_newtable(m_state); /* stack: table */
|
||||||
int index = 1;
|
int index = 1;
|
||||||
for (CCScriptValueArrayIterator it = array.begin(); it != array.end(); ++it)
|
for (CCLuaValueArrayIterator it = array.begin(); it != array.end(); ++it)
|
||||||
{
|
{
|
||||||
pushCCScriptValue(*it); /* stack: table value */
|
pushCCLuaValue(*it); /* stack: table value */
|
||||||
lua_rawseti(m_state, -2, index); /* table[index] = value, stack: table */
|
lua_rawseti(m_state, -2, index); /* table[index] = value, stack: table */
|
||||||
++index;
|
++index;
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,60 +38,61 @@ extern "C" {
|
||||||
|
|
||||||
NS_CC_BEGIN
|
NS_CC_BEGIN
|
||||||
|
|
||||||
// #pragma mark -
|
typedef int LUA_FUNCTION;
|
||||||
// #pragma mark CCScriptValue
|
typedef int LUA_TABLE;
|
||||||
|
typedef int LUA_STRING;
|
||||||
|
|
||||||
class CCScriptValue;
|
class CCLuaValue;
|
||||||
|
|
||||||
typedef std::map<std::string, CCScriptValue> CCScriptValueDict;
|
typedef std::map<std::string, CCLuaValue> CCLuaValueDict;
|
||||||
typedef CCScriptValueDict::const_iterator CCScriptValueDictIterator;
|
typedef CCLuaValueDict::const_iterator CCLuaValueDictIterator;
|
||||||
typedef std::list<CCScriptValue> CCScriptValueArray;
|
typedef std::list<CCLuaValue> CCLuaValueArray;
|
||||||
typedef CCScriptValueArray::const_iterator CCScriptValueArrayIterator;
|
typedef CCLuaValueArray::const_iterator CCLuaValueArrayIterator;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
CCScriptValueTypeInt,
|
CCLuaValueTypeInt,
|
||||||
CCScriptValueTypeFloat,
|
CCLuaValueTypeFloat,
|
||||||
CCScriptValueTypeBoolean,
|
CCLuaValueTypeBoolean,
|
||||||
CCScriptValueTypeString,
|
CCLuaValueTypeString,
|
||||||
CCScriptValueTypeDict,
|
CCLuaValueTypeDict,
|
||||||
CCScriptValueTypeArray,
|
CCLuaValueTypeArray,
|
||||||
CCScriptValueTypeCCObject
|
CCLuaValueTypeCCObject
|
||||||
} CCScriptValueType;
|
} CCLuaValueType;
|
||||||
|
|
||||||
typedef union {
|
typedef union {
|
||||||
int intValue;
|
int intValue;
|
||||||
float floatValue;
|
float floatValue;
|
||||||
bool booleanValue;
|
bool booleanValue;
|
||||||
std::string* stringValue;
|
std::string* stringValue;
|
||||||
CCScriptValueDict* dictValue;
|
CCLuaValueDict* dictValue;
|
||||||
CCScriptValueArray* arrayValue;
|
CCLuaValueArray* arrayValue;
|
||||||
CCObject* ccobjectValue;
|
CCObject* ccobjectValue;
|
||||||
} CCScriptValueField;
|
} CCLuaValueField;
|
||||||
|
|
||||||
class CCScriptValue
|
class CCLuaValue
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static const CCScriptValue intValue(const int intValue);
|
static const CCLuaValue intValue(const int intValue);
|
||||||
static const CCScriptValue floatValue(const float floatValue);
|
static const CCLuaValue floatValue(const float floatValue);
|
||||||
static const CCScriptValue booleanValue(const bool booleanValue);
|
static const CCLuaValue booleanValue(const bool booleanValue);
|
||||||
static const CCScriptValue stringValue(const char* stringValue);
|
static const CCLuaValue stringValue(const char* stringValue);
|
||||||
static const CCScriptValue stringValue(const std::string& stringValue);
|
static const CCLuaValue stringValue(const std::string& stringValue);
|
||||||
static const CCScriptValue dictValue(const CCScriptValueDict& dictValue);
|
static const CCLuaValue dictValue(const CCLuaValueDict& dictValue);
|
||||||
static const CCScriptValue arrayValue(const CCScriptValueArray& arrayValue);
|
static const CCLuaValue arrayValue(const CCLuaValueArray& arrayValue);
|
||||||
static const CCScriptValue ccobjectValue(CCObject* ccobjectValue, const char* objectTypename);
|
static const CCLuaValue ccobjectValue(CCObject* ccobjectValue, const char* objectTypename);
|
||||||
static const CCScriptValue ccobjectValue(CCObject* ccobjectValue, const std::string& objectTypename);
|
static const CCLuaValue ccobjectValue(CCObject* ccobjectValue, const std::string& objectTypename);
|
||||||
|
|
||||||
CCScriptValue(void)
|
CCLuaValue(void)
|
||||||
: m_type(CCScriptValueTypeInt)
|
: m_type(CCLuaValueTypeInt)
|
||||||
, m_ccobjectType(NULL)
|
, m_ccobjectType(NULL)
|
||||||
{
|
{
|
||||||
memset(&m_field, 0, sizeof(m_field));
|
memset(&m_field, 0, sizeof(m_field));
|
||||||
}
|
}
|
||||||
CCScriptValue(const CCScriptValue& rhs);
|
CCLuaValue(const CCLuaValue& rhs);
|
||||||
CCScriptValue& operator=(const CCScriptValue& rhs);
|
CCLuaValue& operator=(const CCLuaValue& rhs);
|
||||||
~CCScriptValue(void);
|
~CCLuaValue(void);
|
||||||
|
|
||||||
const CCScriptValueType getType(void) const {
|
const CCLuaValueType getType(void) const {
|
||||||
return m_type;
|
return m_type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,11 +116,11 @@ public:
|
||||||
return *m_field.stringValue;
|
return *m_field.stringValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const CCScriptValueDict& dictValue(void) const {
|
const CCLuaValueDict& dictValue(void) const {
|
||||||
return *m_field.dictValue;
|
return *m_field.dictValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const CCScriptValueArray& arrayValue(void) const {
|
const CCLuaValueArray& arrayValue(void) const {
|
||||||
return *m_field.arrayValue;
|
return *m_field.arrayValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -128,11 +129,11 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CCScriptValueField m_field;
|
CCLuaValueField m_field;
|
||||||
CCScriptValueType m_type;
|
CCLuaValueType m_type;
|
||||||
std::string* m_ccobjectType;
|
std::string* m_ccobjectType;
|
||||||
|
|
||||||
void copy(const CCScriptValue& rhs);
|
void copy(const CCLuaValue& rhs);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -140,18 +141,13 @@ private:
|
||||||
class CCLuaEngine : public CCScriptEngineProtocol
|
class CCLuaEngine : public CCScriptEngineProtocol
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
static CCLuaEngine* defaultEngine(void);
|
||||||
static CCLuaEngine* create(void);
|
static CCLuaEngine* create(void);
|
||||||
~CCLuaEngine(void);
|
virtual ~CCLuaEngine(void);
|
||||||
|
|
||||||
virtual ccScriptType getScriptType() { return kScriptTypeLua; };
|
virtual ccScriptType getScriptType() {
|
||||||
|
return kScriptTypeLua;
|
||||||
/**
|
};
|
||||||
@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.
|
|
||||||
*/
|
|
||||||
virtual lua_State* getLuaState(void) {
|
|
||||||
return m_state;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@brief Remove CCObject from lua state
|
@brief Remove CCObject from lua state
|
||||||
|
@ -200,19 +196,29 @@ public:
|
||||||
virtual int executeLayerTouchesEvent(CCLayer* pLayer, int eventType, CCSet *pTouches);
|
virtual int executeLayerTouchesEvent(CCLayer* pLayer, int eventType, CCSet *pTouches);
|
||||||
virtual int executeLayerTouchEvent(CCLayer* pLayer, int eventType, CCTouch *pTouch);
|
virtual int executeLayerTouchEvent(CCLayer* pLayer, int eventType, CCTouch *pTouch);
|
||||||
|
|
||||||
virtual int pushIntegerData(int data);
|
/**
|
||||||
virtual int pushFloatData(float data);
|
@brief Method used to get a pointer to the lua_State that the script module is attached to.
|
||||||
virtual int pushBooleanData(bool data);
|
@return A pointer to the lua_State that the script module is attached to.
|
||||||
virtual int pushStringData(const char* data);
|
*/
|
||||||
virtual int pushCCObject(CCObject* pObject, const char* typeName);
|
lua_State* getLuaState(void) {
|
||||||
virtual int pushCCScriptValue(const CCScriptValue& value);
|
return m_state;
|
||||||
virtual int pushCCScriptValueDict(const CCScriptValueDict& dict);
|
}
|
||||||
virtual int pushCCScriptValueArray(const CCScriptValueArray& array);
|
|
||||||
|
int pushInt(int data);
|
||||||
|
int pushFloat(float data);
|
||||||
|
int pushBoolean(bool data);
|
||||||
|
int pushString(const char* data);
|
||||||
|
int pushString(const char* data, int length);
|
||||||
|
int pushNil(void);
|
||||||
|
int pushCCObject(CCObject* pObject, const char* typeName);
|
||||||
|
int pushCCLuaValue(const CCLuaValue& value);
|
||||||
|
int pushCCLuaValueDict(const CCLuaValueDict& dict);
|
||||||
|
int pushCCLuaValueArray(const CCLuaValueArray& array);
|
||||||
int executeFunctionByHandler(int nHandler, int numArgs);
|
int executeFunctionByHandler(int nHandler, int numArgs);
|
||||||
virtual void cleanStack(void);
|
void cleanStack(void);
|
||||||
|
|
||||||
// Add lua loader, now it is used on android
|
// Add lua loader, now it is used on android
|
||||||
virtual void addLuaLoader(lua_CFunction func);
|
void addLuaLoader(lua_CFunction func);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CCLuaEngine(void)
|
CCLuaEngine(void)
|
||||||
|
@ -224,6 +230,7 @@ private:
|
||||||
bool pushFunction(int nHandler);
|
bool pushFunction(int nHandler);
|
||||||
|
|
||||||
lua_State* m_state;
|
lua_State* m_state;
|
||||||
|
static CCLuaEngine* m_defaultEngine;
|
||||||
};
|
};
|
||||||
|
|
||||||
NS_CC_END
|
NS_CC_END
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
5411b3665d5a2e6ec0c0f519d3b93714065bd780
|
6f56a41a68d8e682e9bd47bc0d7e6d1960608e8b
|
|
@ -11,6 +11,7 @@ extern "C" {
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "tolua_fix.h"
|
#include "tolua_fix.h"
|
||||||
#include "cocos2d.h"
|
#include "cocos2d.h"
|
||||||
|
#include "CCLuaEngine.h"
|
||||||
#include "SimpleAudioEngine.h"
|
#include "SimpleAudioEngine.h"
|
||||||
|
|
||||||
using namespace cocos2d;
|
using namespace cocos2d;
|
||||||
|
|
Loading…
Reference in New Issue