axmol/cocos/scripting/lua/bindings/CCLuaValue.h

148 lines
4.2 KiB
C
Raw Normal View History

2013-02-02 02:05:52 +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"
#include "CCObject.h"
2013-02-02 02:05:52 +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;
class LuaValue;
2013-02-02 02:05:52 +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 {
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;
LuaValueDict* dictValue;
LuaValueArray* arrayValue;
Object* ccobjectValue;
} LuaValueField;
2013-02-02 02:05:52 +08:00
class LuaValue
2013-02-02 02:05:52 +08:00
{
public:
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
LuaValue(void)
: _type(LuaValueTypeInt)
, _ccobjectType(NULL)
2013-02-02 02:05:52 +08:00
{
memset(&_field, 0, sizeof(_field));
2013-02-02 02:05:52 +08:00
}
LuaValue(const LuaValue& rhs);
LuaValue& operator=(const LuaValue& rhs);
~LuaValue(void);
2013-02-02 02:05:52 +08:00
const LuaValueType getType(void) const {
return _type;
2013-02-02 02:05:52 +08:00
}
const std::string& getObjectTypename(void) const {
return *_ccobjectType;
2013-02-02 02:05:52 +08:00
}
int intValue(void) const {
return _field.intValue;
2013-02-02 02:05:52 +08:00
}
float floatValue(void) const {
return _field.floatValue;
2013-02-02 02:05:52 +08:00
}
bool booleanValue(void) const {
return _field.booleanValue;
2013-02-02 02:05:52 +08:00
}
const std::string& stringValue(void) const {
return *_field.stringValue;
2013-02-02 02:05:52 +08:00
}
const LuaValueDict& dictValue(void) const {
return *_field.dictValue;
2013-02-02 02:05:52 +08:00
}
const LuaValueArray& arrayValue(void) const {
return *_field.arrayValue;
2013-02-02 02:05:52 +08:00
}
Object* ccobjectValue(void) const {
return _field.ccobjectValue;
2013-02-02 02:05:52 +08:00
}
private:
LuaValueField _field;
LuaValueType _type;
std::string* _ccobjectType;
2013-02-02 02:05:52 +08:00
void copy(const LuaValue& rhs);
2013-02-02 02:05:52 +08:00
};
NS_CC_END
#endif // __CC_LUA_VALUE_H_