From 4f9ff698019b26a5600f0d0ea9f73f280ac2c2e7 Mon Sep 17 00:00:00 2001 From: maelstrom Date: Fri, 22 Nov 2024 18:56:34 +0100 Subject: [PATCH] Descriptors for instance stuff --- src/objects/base/metadata.h | 59 +++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 src/objects/base/metadata.h diff --git a/src/objects/base/metadata.h b/src/objects/base/metadata.h new file mode 100644 index 0000000..3bff353 --- /dev/null +++ b/src/objects/base/metadata.h @@ -0,0 +1,59 @@ +#pragma once + +#include +#include +#include +#include +#include + +#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 backingField; + std::optional getter; + std::optional setter; +}; + +// + +typedef DataValue(*InstanceMethodHandler)(std::vector); + +struct MemberMethodDescriptor { + DataType returnType; + // This may need to be converted into a vector in the future for overloaded methods + std::vector parameters; + InstanceMethodHandler handler; +}; + +// TODO: Add MemberCallbackDescriptor +typedef std::map> InstanceMemberTable; \ No newline at end of file