Compare commits

...

3 commits

Author SHA1 Message Date
maelstrom 4f9ff69801 Descriptors for instance stuff 2024-11-22 18:56:34 +01:00
maelstrom 64e6ea4ed6 More data types and macro for wrapping primitives 2024-11-22 18:49:45 +01:00
maelstrom 29c85b58c7 Basic datatypes 2024-11-22 18:27:34 +01:00
4 changed files with 106 additions and 0 deletions

14
src/datatype.h Normal file
View 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
};

View 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)

View 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

View 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;