Skip to content

Commit

Permalink
Wrap enums with prettier enums
Browse files Browse the repository at this point in the history
  • Loading branch information
LunaTheFoxgirl committed Nov 15, 2020
1 parent 4faa19f commit 318768a
Show file tree
Hide file tree
Showing 4 changed files with 212 additions and 11 deletions.
6 changes: 3 additions & 3 deletions source/as/engine.d
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public:
/**
Registers an object type
*/
void registerObjectType(string name, int byteSize, asDWORD flags) {
void registerObjectType(string name, int byteSize, TypeFlags flags) {
int err = asEngine_RegisterObjectType(engine, name.toStringz, byteSize, flags);
assert(err != asERetCodes.asINVALID_ARG, "Invalid flags");
assert(err != asERetCodes.asINVALID_NAME, "Invalid name");
Expand All @@ -210,7 +210,7 @@ public:
/**
Registers a method for an object
*/
void registerObjectMethod(T)(string obj, string decl, T func, asDWORD callConv = DCall, void* aux = null) if (isFunctionPointer!T) {
void registerObjectMethod(T)(string obj, string decl, T func, CallConv callConv = DCall, void* aux = null) if (isFunctionPointer!T) {
int err = asEngine_RegisterObjectMethod(engine, obj.toStringz, decl.toStringz, cast(asFUNCTION_t)func, callConv, aux);
assert(err != asERetCodes.asWRONG_CONFIG_GROUP, "Object type was registered in a different config group");
assert(err != asERetCodes.asNOT_SUPPORTED, "The calling convention is not supported");
Expand All @@ -225,7 +225,7 @@ public:
/**
Registers a behaviour for an object
*/
void registerObjectBehaviour(T)(string obj, asEBehaviours behaviour, string decl, T func, asDWORD callConv = DCall, void* aux = null) if (isFunctionPointer!T) {
void registerObjectBehaviour(T)(string obj, Behaviours behaviour, string decl, T func, CallConv callConv = DCall, void* aux = null) if (isFunctionPointer!T) {
int err = asEngine_RegisterObjectBehaviour(engine, obj.toStringz, behaviour, decl.toStringz, cast(asFUNCTION_t)func, callConv, aux);
assert(err != asERetCodes.asWRONG_CONFIG_GROUP, "Object type was registered in a different config group");
assert(err != asERetCodes.asINVALID_ARG, "obj not set, global behaviour given in behaviour or the objForThiscall pointer wasn't set correctly");
Expand Down
71 changes: 71 additions & 0 deletions source/as/func.d
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,77 @@ import as.engine;
import as.mod;
import std.string;

/**
Supported calling conventions
*/
enum CallConv : asECallConvTypes {

/**
The CDECL standard calling convention
*/
CDecl = asECallConvTypes.asCALL_CDECL,

/**
The STDCall calling convention
*/
STDCall = asECallConvTypes.asCALL_STDCALL,

/**
The ThisCall calling convention that emulates a global object
*/
ThisCallASGlobal = asECallConvTypes.asCALL_THISCALL_ASGLOBAL,

/**
The ThisCall calling convention
*/
ThisCall = asECallConvTypes.asCALL_THISCALL,

/**
CDECL calling convention where object pointer is the first int argument
*/
CDeclObjFirst = asECallConvTypes.asCALL_CDECL_OBJFIRST,

/**
CDECL calling convention where the object pointer is the last int argument
*/
CDeclObjLast = asECallConvTypes.asCALL_CDECL_OBJLAST,

/**
The Generic calling convention, requires writing specialized code to handle it
*/
Generic = asECallConvTypes.asCALL_GENERIC,

/**
ThisCall calling convention where the object pointer is the last int argument
*/
ThisCallObjLast = asECallConvTypes.asCALL_THISCALL_OBJLAST,

/**
ThisCall calling convention where the object pointer is the last int argument
*/
ThisCallObjFirst = asECallConvTypes.asCALL_THISCALL_OBJFIRST,

/**
The DDECL standard calling convention
DDECL is CDECL but with int registers in reverse order
*/
DDecl = asECallConvTypes.asCALL_DDECL,

/**
DDECL calling convention where the object pointer is the last int argument
*/
DDeclObjLast = asECallConvTypes.asCALL_DDECL_OBJLAST,

/**
DDECL calling convention where the object pointer is the last int argument
*/
DDeclObjFirst = asECallConvTypes.asCALL_DDECL_OBJFIRST,
}

/**
Function types
*/
enum FuncType : asEFuncType {
/**
A dummy no-op function
Expand Down
86 changes: 83 additions & 3 deletions source/as/obj.d
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,86 @@ import as.def;
import as.engine;
import std.string;

enum TypeFlags : asEObjTypeFlags {
Ref = asEObjTypeFlags.asOBJ_REF,
Value = asEObjTypeFlags.asOBJ_VALUE,
GC = asEObjTypeFlags.asOBJ_GC,
POD = asEObjTypeFlags.asOBJ_POD,
NoHandle = asEObjTypeFlags.asOBJ_NOHANDLE,
Scoped = asEObjTypeFlags.asOBJ_SCOPED,
Template = asEObjTypeFlags.asOBJ_TEMPLATE,
ASHandle = asEObjTypeFlags.asOBJ_ASHANDLE,
Class = asEObjTypeFlags.asOBJ_APP_CLASS,
ClassConstruct = asEObjTypeFlags.asOBJ_APP_CLASS_CONSTRUCTOR,
ClassDestruct = asEObjTypeFlags.asOBJ_APP_CLASS_DESTRUCTOR,
ClassAssign = asEObjTypeFlags.asOBJ_APP_CLASS_ASSIGNMENT,
ClassCopyConstruct = asEObjTypeFlags.asOBJ_APP_CLASS_COPY_CONSTRUCTOR,
C = asEObjTypeFlags.asOBJ_APP_CLASS_C,
CD = asEObjTypeFlags.asOBJ_APP_CLASS_CD,
CA = asEObjTypeFlags.asOBJ_APP_CLASS_CA,
CK = asEObjTypeFlags.asOBJ_APP_CLASS_CK,
CDA = asEObjTypeFlags.asOBJ_APP_CLASS_CDA,
CDK = asEObjTypeFlags.asOBJ_APP_CLASS_CDK,
CAK = asEObjTypeFlags.asOBJ_APP_CLASS_CAK,
CDAK = asEObjTypeFlags.asOBJ_APP_CLASS_CDAK,
D = asEObjTypeFlags.asOBJ_APP_CLASS_D,
DA = asEObjTypeFlags.asOBJ_APP_CLASS_DA,
DK = asEObjTypeFlags.asOBJ_APP_CLASS_DK,
DAK = asEObjTypeFlags.asOBJ_APP_CLASS_DAK,
A = asEObjTypeFlags.asOBJ_APP_CLASS_A,
AK = asEObjTypeFlags.asOBJ_APP_CLASS_AK,
K = asEObjTypeFlags.asOBJ_APP_CLASS_K,
Primitive = asEObjTypeFlags.asOBJ_APP_PRIMITIVE,
Float = asEObjTypeFlags.asOBJ_APP_FLOAT,
Array = asEObjTypeFlags.asOBJ_APP_ARRAY,
AllInts = asEObjTypeFlags.asOBJ_APP_CLASS_ALLINTS,
AllFloats = asEObjTypeFlags.asOBJ_APP_CLASS_ALLFLOATS,
NoCount = asEObjTypeFlags.asOBJ_NOCOUNT,
Align8 = asEObjTypeFlags.asOBJ_APP_CLASS_ALIGN8,
ImplicitHandle = asEObjTypeFlags.asOBJ_IMPLICIT_HANDLE,
ValidFlagsMask = asEObjTypeFlags.asOBJ_MASK_VALID_FLAGS,

// Internal flags
ScriptObject = asEObjTypeFlags.asOBJ_SCRIPT_OBJECT,
Shared = asEObjTypeFlags.asOBJ_SHARED,
NoInherit = asEObjTypeFlags.asOBJ_NOINHERIT,
FuncDef = asEObjTypeFlags.asOBJ_FUNCDEF,
ListPattern = asEObjTypeFlags.asOBJ_LIST_PATTERN,
Enum = asEObjTypeFlags.asOBJ_ENUM,
TemplateSubtype = asEObjTypeFlags.asOBJ_TEMPLATE_SUBTYPE,
TypeDef = asEObjTypeFlags.asOBJ_TYPEDEF,
Abstract = asEObjTypeFlags.asOBJ_ABSTRACT,
Align16 = asEObjTypeFlags.asOBJ_APP_ALIGN16
}

enum Behaviours : asEBehaviours {
// Value object memory management
Construct = asEBehaviours.asBEHAVE_CONSTRUCT,
ListConstruct = asEBehaviours.asBEHAVE_LIST_CONSTRUCT,
Destruct = asEBehaviours.asBEHAVE_DESTRUCT,

// Reference object memory management
Factory = asEBehaviours.asBEHAVE_FACTORY,
ListFactory = asEBehaviours.asBEHAVE_LIST_FACTORY,
AddRef = asEBehaviours.asBEHAVE_ADDREF,
Release = asEBehaviours.asBEHAVE_RELEASE,
GetWeakrefFlag = asEBehaviours.asBEHAVE_GET_WEAKREF_FLAG,

// Object operators
TemplateCallback = asEBehaviours.asBEHAVE_TEMPLATE_CALLBACK,

// Garbage collection behaviours
FirstGC = asEBehaviours.asBEHAVE_FIRST_GC,
GetRefCount = asEBehaviours.asBEHAVE_GETREFCOUNT,
SetGCFlag = asEBehaviours.asBEHAVE_SETGCFLAG,
GetGCFlag = asEBehaviours.asBEHAVE_GETGCFLAG,
EnumRefs = asEBehaviours.asBEHAVE_ENUMREFS,
ReleaseRefs = asEBehaviours.asBEHAVE_RELEASEREFS,
LastGC = asEBehaviours.asBEHAVE_LAST_GC,

BehaveMax = asEBehaviours.asBEHAVE_MAX
}

class ScriptObject {
private:
ScriptEngine engine;
Expand Down Expand Up @@ -62,7 +142,7 @@ public:
Get the name of a property
*/
string getPropertyName(asUINT prop) {
return cast(string)asObject_GetPropertyName(obj, prop).fromStringz;
return cast(string) asObject_GetPropertyName(obj, prop).fromStringz;
}

/**
Expand All @@ -71,7 +151,7 @@ public:
void* getPropertyAddress(asUINT prop) {
return asObject_GetAddressOfProperty(obj, prop);
}

/**
Copy content from an other object of the same type
*/
Expand All @@ -95,4 +175,4 @@ public:
return asObject_GetUserData(obj, type);
}

}
}
60 changes: 55 additions & 5 deletions source/as/package.d
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@ public import as.context;
public import as.tinf;
public import as.obj;

enum CDECL = asECallConvTypes.asCALL_CDECL;
enum DCall = asECallConvTypes.asCALL_DDECL;
enum DCallObjLast = asECallConvTypes.asCALL_DDECL_OBJLAST;
enum DCallObjFirst = asECallConvTypes.asCALL_DDECL_OBJFIRST;

/**
Gets the version of the angelscript library
*/
Expand All @@ -27,6 +22,61 @@ string getLibraryOptions() {
return cast(string)asGetLibraryOptions().fromStringz;
}

/**
Shorthand for CallConv.CDecl
*/
enum CDECL = CallConv.CDecl;

/**
Shorthand for CallConv.DDecl
*/
enum DCall = CallConv.DDecl;

/**
Shorthand for CallConv.DDeclObjLast
*/
enum DCallObjLast = CallConv.DDeclObjLast;

/**
Shorthand for CallConv.DDeclObjFirst
*/
enum DCallObjFirst = CallConv.DDeclObjFirst;

/**
All the error codes AngelScript can return
*/
enum ReturnCodes : asERetCodes {
Success = asERetCodes.asSUCCESS,
Error = asERetCodes.asERROR,
ContextActive = asERetCodes.asCONTEXT_ACTIVE,
ContextNotFinished = asERetCodes.asCONTEXT_NOT_FINISHED,
ContextNotPrepared = asERetCodes.asCONTEXT_NOT_PREPARED,
InvalidArg = asERetCodes.asINVALID_ARG,
NoFunction = asERetCodes.asNO_FUNCTION,
NotSupported = asERetCodes.asNOT_SUPPORTED,
InvalidName = asERetCodes.asINVALID_NAME,
NameTaken = asERetCodes.asNAME_TAKEN,
InvalidDeclaration = asERetCodes.asINVALID_DECLARATION,
InvalidObject = asERetCodes.asINVALID_OBJECT,
InvalidType = asERetCodes.asINVALID_TYPE,
AlreadyRegistered = asERetCodes.asALREADY_REGISTERED,
MultipleFunctions = asERetCodes.asMULTIPLE_FUNCTIONS,
NoModule = asERetCodes.asNO_MODULE,
NoGlobalVar = asERetCodes.asNO_GLOBAL_VAR,
InvalidConfiguration = asERetCodes.asINVALID_CONFIGURATION,
InvalidInterface = asERetCodes.asINVALID_INTERFACE,
CantBindAllFunctions = asERetCodes.asCANT_BIND_ALL_FUNCTIONS,
LowerArrayDimensionNotRegistered = asERetCodes.asLOWER_ARRAY_DIMENSION_NOT_REGISTERED,
WrongConfigGroup = asERetCodes.asWRONG_CONFIG_GROUP,
ConfigGroupInUse = asERetCodes.asCONFIG_GROUP_IS_IN_USE,
IllegalBehaviourForType = asERetCodes.asILLEGAL_BEHAVIOUR_FOR_TYPE,
WrongCallingConv = asERetCodes.asWRONG_CALLING_CONV,
BuildInProgress = asERetCodes.asBUILD_IN_PROGRESS,
InitGlobalVarsFailed = asERetCodes.asINIT_GLOBAL_VARS_FAILED,
OutOfMemory = asERetCodes.asOUT_OF_MEMORY,
ModuleInUse = asERetCodes.asMODULE_IS_IN_USE
}

/**
The type of a message
*/
Expand Down

0 comments on commit 318768a

Please sign in to comment.