2019-11-23 20:27:39 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2011-2012 cocos2d-x.org
|
|
|
|
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
http://www.cocos2d-x.org
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include "scripting/lua-bindings/manual/CCLuaValue.h"
|
|
|
|
|
|
|
|
NS_CC_BEGIN
|
|
|
|
|
|
|
|
const LuaValue LuaValue::intValue(const int intValue)
|
|
|
|
{
|
|
|
|
LuaValue value;
|
2021-12-25 10:04:45 +08:00
|
|
|
value._type = LuaValueTypeInt;
|
2019-11-23 20:27:39 +08:00
|
|
|
value._field.intValue = intValue;
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
const LuaValue LuaValue::floatValue(const float floatValue)
|
|
|
|
{
|
|
|
|
LuaValue value;
|
2021-12-25 10:04:45 +08:00
|
|
|
value._type = LuaValueTypeFloat;
|
2019-11-23 20:27:39 +08:00
|
|
|
value._field.floatValue = floatValue;
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
const LuaValue LuaValue::booleanValue(const bool booleanValue)
|
|
|
|
{
|
|
|
|
LuaValue value;
|
2021-12-25 10:04:45 +08:00
|
|
|
value._type = LuaValueTypeBoolean;
|
2019-11-23 20:27:39 +08:00
|
|
|
value._field.booleanValue = booleanValue;
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
const LuaValue LuaValue::stringValue(const char* stringValue)
|
|
|
|
{
|
|
|
|
LuaValue value;
|
2021-12-25 10:04:45 +08:00
|
|
|
value._type = LuaValueTypeString;
|
2019-11-23 20:27:39 +08:00
|
|
|
value._field.stringValue = new std::string(stringValue ? stringValue : "");
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2021-12-31 12:12:40 +08:00
|
|
|
const LuaValue LuaValue::stringValue(std::string_view stringValue)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
LuaValue value;
|
2021-12-25 10:04:45 +08:00
|
|
|
value._type = LuaValueTypeString;
|
2019-11-23 20:27:39 +08:00
|
|
|
value._field.stringValue = new std::string(stringValue);
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
const LuaValue LuaValue::dictValue(const LuaValueDict& dictValue)
|
|
|
|
{
|
|
|
|
LuaValue value;
|
2021-12-25 10:04:45 +08:00
|
|
|
value._type = LuaValueTypeDict;
|
2021-12-08 00:11:53 +08:00
|
|
|
value._field.dictValue = new LuaValueDict(dictValue);
|
2019-11-23 20:27:39 +08:00
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
const LuaValue LuaValue::arrayValue(const LuaValueArray& arrayValue)
|
|
|
|
{
|
|
|
|
LuaValue value;
|
2021-12-25 10:04:45 +08:00
|
|
|
value._type = LuaValueTypeArray;
|
2021-12-08 00:11:53 +08:00
|
|
|
value._field.arrayValue = new LuaValueArray(arrayValue);
|
2019-11-23 20:27:39 +08:00
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
const LuaValue LuaValue::ccobjectValue(Ref* ccobjectValue, const char* objectTypename)
|
|
|
|
{
|
|
|
|
LuaValue value;
|
2021-12-25 10:04:45 +08:00
|
|
|
value._type = LuaValueTypeObject;
|
2019-11-23 20:27:39 +08:00
|
|
|
value._field.ccobjectValue = ccobjectValue;
|
|
|
|
ccobjectValue->retain();
|
|
|
|
value._ccobjectType = new std::string(objectTypename);
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2021-12-31 12:12:40 +08:00
|
|
|
const LuaValue LuaValue::ccobjectValue(Ref* ccobjectValue, std::string_view objectTypename)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-31 12:12:40 +08:00
|
|
|
return LuaValue::ccobjectValue(ccobjectValue, objectTypename.data());
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
LuaValue::LuaValue(const LuaValue& rhs)
|
|
|
|
{
|
|
|
|
copy(rhs);
|
|
|
|
}
|
|
|
|
|
|
|
|
LuaValue& LuaValue::operator=(const LuaValue& rhs)
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
if (this != &rhs)
|
|
|
|
copy(rhs);
|
2019-11-23 20:27:39 +08:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
LuaValue::~LuaValue()
|
|
|
|
{
|
|
|
|
if (_type == LuaValueTypeString)
|
|
|
|
{
|
|
|
|
delete _field.stringValue;
|
|
|
|
}
|
|
|
|
else if (_type == LuaValueTypeDict)
|
|
|
|
{
|
|
|
|
delete _field.dictValue;
|
|
|
|
}
|
|
|
|
else if (_type == LuaValueTypeArray)
|
|
|
|
{
|
|
|
|
delete _field.arrayValue;
|
|
|
|
}
|
|
|
|
else if (_type == LuaValueTypeObject)
|
|
|
|
{
|
|
|
|
_field.ccobjectValue->release();
|
|
|
|
delete _ccobjectType;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void LuaValue::copy(const LuaValue& rhs)
|
|
|
|
{
|
|
|
|
memcpy(&_field, &rhs._field, sizeof(_field));
|
|
|
|
_type = rhs._type;
|
|
|
|
if (_type == LuaValueTypeString)
|
|
|
|
{
|
|
|
|
_field.stringValue = new std::string(*rhs._field.stringValue);
|
|
|
|
}
|
|
|
|
else if (_type == LuaValueTypeDict)
|
|
|
|
{
|
2021-12-08 00:11:53 +08:00
|
|
|
_field.dictValue = new LuaValueDict(*rhs._field.dictValue);
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
else if (_type == LuaValueTypeArray)
|
|
|
|
{
|
2021-12-08 00:11:53 +08:00
|
|
|
_field.arrayValue = new LuaValueArray(*rhs._field.arrayValue);
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
else if (_type == LuaValueTypeObject)
|
|
|
|
{
|
|
|
|
_field.ccobjectValue = rhs._field.ccobjectValue;
|
|
|
|
_field.ccobjectValue->retain();
|
|
|
|
_ccobjectType = new std::string(*rhs._ccobjectType);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_CC_END
|