2013-02-02 02:05:52 +08:00
|
|
|
/****************************************************************************
|
2014-01-07 11:47:11 +08:00
|
|
|
Copyright (c) 2011-2012 cocos2d-x.org
|
|
|
|
Copyright (c) 2013-2014 Chukong Technologies Inc.
|
2013-02-02 02:05:52 +08:00
|
|
|
|
|
|
|
http://www.cocos2d-x.org
|
|
|
|
|
|
|
|
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:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
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.
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef __CC_LUA_VALUE_H_
|
|
|
|
#define __CC_LUA_VALUE_H_
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <map>
|
|
|
|
#include <list>
|
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
#include "lua.h"
|
|
|
|
}
|
|
|
|
|
|
|
|
#include "ccTypes.h"
|
2013-10-16 17:19:02 +08:00
|
|
|
#include "CCObject.h"
|
2013-02-02 02:05:52 +08:00
|
|
|
|
2013-04-27 14:45:00 +08:00
|
|
|
#if CC_TARGET_PLATFORM == CC_PLATFORM_BLACKBERRY
|
|
|
|
using std::memset;
|
|
|
|
using std::memcpy;
|
|
|
|
#endif
|
|
|
|
|
2013-02-02 02:05:52 +08:00
|
|
|
NS_CC_BEGIN
|
|
|
|
|
|
|
|
typedef int LUA_FUNCTION;
|
|
|
|
typedef int LUA_TABLE;
|
|
|
|
typedef int LUA_STRING;
|
|
|
|
|
2013-06-20 14:33:59 +08:00
|
|
|
class LuaValue;
|
2013-02-02 02:05:52 +08:00
|
|
|
|
2013-06-20 14:33:59 +08:00
|
|
|
typedef std::map<std::string, LuaValue> LuaValueDict;
|
|
|
|
typedef LuaValueDict::const_iterator LuaValueDictIterator;
|
|
|
|
typedef std::list<LuaValue> LuaValueArray;
|
|
|
|
typedef LuaValueArray::const_iterator LuaValueArrayIterator;
|
2013-02-02 02:05:52 +08:00
|
|
|
|
|
|
|
typedef enum {
|
2013-06-20 14:33:59 +08:00
|
|
|
LuaValueTypeInt,
|
|
|
|
LuaValueTypeFloat,
|
|
|
|
LuaValueTypeBoolean,
|
|
|
|
LuaValueTypeString,
|
|
|
|
LuaValueTypeDict,
|
|
|
|
LuaValueTypeArray,
|
|
|
|
LuaValueTypeObject
|
|
|
|
} LuaValueType;
|
2013-02-02 02:05:52 +08:00
|
|
|
|
|
|
|
typedef union {
|
|
|
|
int intValue;
|
|
|
|
float floatValue;
|
|
|
|
bool booleanValue;
|
|
|
|
std::string* stringValue;
|
2013-06-20 14:33:59 +08:00
|
|
|
LuaValueDict* dictValue;
|
|
|
|
LuaValueArray* arrayValue;
|
|
|
|
Object* ccobjectValue;
|
|
|
|
} LuaValueField;
|
2013-02-02 02:05:52 +08:00
|
|
|
|
2013-06-20 14:33:59 +08:00
|
|
|
class LuaValue
|
2013-02-02 02:05:52 +08:00
|
|
|
{
|
|
|
|
public:
|
2013-06-20 14:33:59 +08:00
|
|
|
static const LuaValue intValue(const int intValue);
|
|
|
|
static const LuaValue floatValue(const float floatValue);
|
|
|
|
static const LuaValue booleanValue(const bool booleanValue);
|
|
|
|
static const LuaValue stringValue(const char* stringValue);
|
|
|
|
static const LuaValue stringValue(const std::string& stringValue);
|
|
|
|
static const LuaValue dictValue(const LuaValueDict& dictValue);
|
|
|
|
static const LuaValue arrayValue(const LuaValueArray& arrayValue);
|
|
|
|
static const LuaValue ccobjectValue(Object* ccobjectValue, const char* objectTypename);
|
|
|
|
static const LuaValue ccobjectValue(Object* ccobjectValue, const std::string& objectTypename);
|
2013-02-02 02:05:52 +08:00
|
|
|
|
2013-06-20 14:33:59 +08:00
|
|
|
LuaValue(void)
|
|
|
|
: _type(LuaValueTypeInt)
|
2013-06-15 14:03:30 +08:00
|
|
|
, _ccobjectType(NULL)
|
2013-02-02 02:05:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
memset(&_field, 0, sizeof(_field));
|
2013-02-02 02:05:52 +08:00
|
|
|
}
|
2013-06-20 14:33:59 +08:00
|
|
|
LuaValue(const LuaValue& rhs);
|
|
|
|
LuaValue& operator=(const LuaValue& rhs);
|
|
|
|
~LuaValue(void);
|
2013-02-02 02:05:52 +08:00
|
|
|
|
2013-06-20 14:33:59 +08:00
|
|
|
const LuaValueType getType(void) const {
|
2013-06-15 14:03:30 +08:00
|
|
|
return _type;
|
2013-02-02 02:05:52 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:33:59 +08:00
|
|
|
const std::string& getObjectTypename(void) const {
|
2013-06-15 14:03:30 +08:00
|
|
|
return *_ccobjectType;
|
2013-02-02 02:05:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int intValue(void) const {
|
2013-06-15 14:03:30 +08:00
|
|
|
return _field.intValue;
|
2013-02-02 02:05:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
float floatValue(void) const {
|
2013-06-15 14:03:30 +08:00
|
|
|
return _field.floatValue;
|
2013-02-02 02:05:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool booleanValue(void) const {
|
2013-06-15 14:03:30 +08:00
|
|
|
return _field.booleanValue;
|
2013-02-02 02:05:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const std::string& stringValue(void) const {
|
2013-06-15 14:03:30 +08:00
|
|
|
return *_field.stringValue;
|
2013-02-02 02:05:52 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:33:59 +08:00
|
|
|
const LuaValueDict& dictValue(void) const {
|
2013-06-15 14:03:30 +08:00
|
|
|
return *_field.dictValue;
|
2013-02-02 02:05:52 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:33:59 +08:00
|
|
|
const LuaValueArray& arrayValue(void) const {
|
2013-06-15 14:03:30 +08:00
|
|
|
return *_field.arrayValue;
|
2013-02-02 02:05:52 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:33:59 +08:00
|
|
|
Object* ccobjectValue(void) const {
|
2013-06-15 14:03:30 +08:00
|
|
|
return _field.ccobjectValue;
|
2013-02-02 02:05:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2013-06-20 14:33:59 +08:00
|
|
|
LuaValueField _field;
|
|
|
|
LuaValueType _type;
|
2013-06-15 14:03:30 +08:00
|
|
|
std::string* _ccobjectType;
|
2013-02-02 02:05:52 +08:00
|
|
|
|
2013-06-20 14:33:59 +08:00
|
|
|
void copy(const LuaValue& rhs);
|
2013-02-02 02:05:52 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
NS_CC_END
|
|
|
|
|
|
|
|
#endif // __CC_LUA_VALUE_H_
|