Compare commits
3 commits
cd906be4c9
...
4f9ff69801
Author | SHA1 | Date | |
---|---|---|---|
|
4f9ff69801 | ||
|
64e6ea4ed6 | ||
|
29c85b58c7 |
14
src/datatype.h
Normal file
14
src/datatype.h
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <variant>
|
||||||
|
#include "datatypes/primitives.h"
|
||||||
|
|
||||||
|
typedef std::variant<VoidData, BoolData, StringData, IntData, FloatData> DataValue;
|
||||||
|
|
||||||
|
enum class DataType {
|
||||||
|
VOID = 0,
|
||||||
|
BOOL = 1,
|
||||||
|
STRING = 2,
|
||||||
|
INT = 3,
|
||||||
|
FLOAT = 4
|
||||||
|
};
|
11
src/datatypes/primitives.cpp
Normal file
11
src/datatypes/primitives.cpp
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
#include "primitives.h"
|
||||||
|
|
||||||
|
#define IMPL_WRAPPER_CLASS(CLASS_NAME, WRAPPED_TYPE) CLASS_NAME::CLASS_NAME(WRAPPED_TYPE in) : wrapped(in) {}\
|
||||||
|
CLASS_NAME::operator WRAPPED_TYPE() { return wrapped; }
|
||||||
|
|
||||||
|
VoidData::VoidData() {};
|
||||||
|
|
||||||
|
IMPL_WRAPPER_CLASS(BoolData, bool)
|
||||||
|
IMPL_WRAPPER_CLASS(IntData, int)
|
||||||
|
IMPL_WRAPPER_CLASS(FloatData, float)
|
||||||
|
IMPL_WRAPPER_CLASS(StringData, std::string)
|
22
src/datatypes/primitives.h
Normal file
22
src/datatypes/primitives.h
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#define DEF_WRAPPER_CLASS(CLASS_NAME, WRAPPED_TYPE) class CLASS_NAME {\
|
||||||
|
WRAPPED_TYPE wrapped;\
|
||||||
|
public:\
|
||||||
|
CLASS_NAME(WRAPPED_TYPE); \
|
||||||
|
operator WRAPPED_TYPE(); \
|
||||||
|
};
|
||||||
|
|
||||||
|
class VoidData {
|
||||||
|
public:
|
||||||
|
VoidData();
|
||||||
|
};
|
||||||
|
|
||||||
|
DEF_WRAPPER_CLASS(BoolData, bool)
|
||||||
|
DEF_WRAPPER_CLASS(IntData, int)
|
||||||
|
DEF_WRAPPER_CLASS(FloatData, float)
|
||||||
|
DEF_WRAPPER_CLASS(StringData, std::string)
|
||||||
|
|
||||||
|
#undef DEF_WRAPPER_CLASS
|
59
src/objects/base/metadata.h
Normal file
59
src/objects/base/metadata.h
Normal file
|
@ -0,0 +1,59 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <optional>
|
||||||
|
#include <string>
|
||||||
|
#include <variant>
|
||||||
|
#include <map>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include "../../datatype.h"
|
||||||
|
|
||||||
|
class Instance;
|
||||||
|
typedef Instance(*InstanceConstructor)();
|
||||||
|
|
||||||
|
const uint INST_NOT_CREATABLE = 1;
|
||||||
|
// const uint INST_SINGLETON = 2;
|
||||||
|
|
||||||
|
typedef uint InstanceClassFlags;
|
||||||
|
|
||||||
|
struct InstanceClassDescriptor {
|
||||||
|
std::string className;
|
||||||
|
InstanceConstructor constructor;
|
||||||
|
InstanceClassFlags flags;
|
||||||
|
};
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
|
const uint PROP_READONLY = 1;
|
||||||
|
const uint PROP_NOSCRIPT = 2; // Cannot be read or written to by unpriveleged scripts
|
||||||
|
const uint PROP_NOSAVE = 4; // Property should not be serialized by the engine
|
||||||
|
const uint PROP_CLIENTONLY = 8; // Only accessible by the client
|
||||||
|
|
||||||
|
typedef uint PropertyFlags;
|
||||||
|
|
||||||
|
typedef DataValue(*InstancePropertyGetter)();
|
||||||
|
typedef void(*InstancePropertySetter)(DataValue);
|
||||||
|
|
||||||
|
// Properties may either have a backing field directly accessed by Instance,
|
||||||
|
// or, for more granular control may define a getter (and setter if writable).
|
||||||
|
struct MemberPropertyDescriptor {
|
||||||
|
DataType dataType;
|
||||||
|
PropertyFlags flags;
|
||||||
|
std::optional<DataValue*> backingField;
|
||||||
|
std::optional<InstancePropertyGetter> getter;
|
||||||
|
std::optional<InstancePropertySetter> setter;
|
||||||
|
};
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
|
typedef DataValue(*InstanceMethodHandler)(std::vector<DataValue>);
|
||||||
|
|
||||||
|
struct MemberMethodDescriptor {
|
||||||
|
DataType returnType;
|
||||||
|
// This may need to be converted into a vector in the future for overloaded methods
|
||||||
|
std::vector<DataType> parameters;
|
||||||
|
InstanceMethodHandler handler;
|
||||||
|
};
|
||||||
|
|
||||||
|
// TODO: Add MemberCallbackDescriptor
|
||||||
|
typedef std::map<std::string, std::variant<MemberPropertyDescriptor, MemberMethodDescriptor /*, MemberEventDescriptor */ /* , MemberCallbackDescriptor */>> InstanceMemberTable;
|
Loading…
Reference in a new issue