From 07a2331ca30c44aefc7b43bf2cf658396ce7c89d Mon Sep 17 00:00:00 2001 From: "alexey.lysiuk" Date: Sat, 10 Aug 2019 16:30:25 +0300 Subject: [PATCH] - exposed Append() method to ZScript dynamic array https://forum.zdoom.org/viewtopic.php?t=65570 --- src/scripting/backend/dynarrays.cpp | 81 ++++++++++++++++++++++++++--- wadsrc/static/zscript/dynarrays.zs | 8 +++ 2 files changed, 83 insertions(+), 6 deletions(-) diff --git a/src/scripting/backend/dynarrays.cpp b/src/scripting/backend/dynarrays.cpp index b95e02f4d..daedd60e6 100644 --- a/src/scripting/backend/dynarrays.cpp +++ b/src/scripting/backend/dynarrays.cpp @@ -54,12 +54,6 @@ typedef TArray FDynArray_Ptr; typedef TArray FDynArray_Obj; typedef TArray FDynArray_String; -//----------------------------------------------------- -// -// Int8 array -// -//----------------------------------------------------- - template void ArrayCopy(T *self, T *other) { *self = *other; @@ -70,6 +64,11 @@ template void ArrayMove(T *self, T* other) *self = std::move(*other); } +template void ArrayAppend(T *self, const T *other) +{ + self->Append(*other); +} + template int ArrayFind(T *self, U val) { return self->Find(static_cast(val)); @@ -139,6 +138,12 @@ template void ArrayClear(T *self) // without this the two-argument templates cannot be used in macros. #define COMMA , +//----------------------------------------------------- +// +// Int8 array +// +//----------------------------------------------------- + DEFINE_ACTION_FUNCTION_NATIVE(FDynArray_I8, Copy, ArrayCopy) { PARAM_SELF_STRUCT_PROLOGUE(FDynArray_I8); @@ -155,6 +160,14 @@ DEFINE_ACTION_FUNCTION_NATIVE(FDynArray_I8, Move, ArrayMove) return 0; } +DEFINE_ACTION_FUNCTION_NATIVE(FDynArray_I8, Append, ArrayAppend) +{ + PARAM_SELF_STRUCT_PROLOGUE(FDynArray_I8); + PARAM_POINTER(other, FDynArray_I8); + self->Append(*other); + return 0; +} + DEFINE_ACTION_FUNCTION_NATIVE(FDynArray_I8, Find, ArrayFind) { PARAM_SELF_STRUCT_PROLOGUE(FDynArray_I8); @@ -258,6 +271,14 @@ DEFINE_ACTION_FUNCTION_NATIVE(FDynArray_I16, Move, ArrayMove) return 0; } +DEFINE_ACTION_FUNCTION_NATIVE(FDynArray_I16, Append, ArrayAppend) +{ + PARAM_SELF_STRUCT_PROLOGUE(FDynArray_I16); + PARAM_POINTER(other, FDynArray_I16); + self->Append(*other); + return 0; +} + DEFINE_ACTION_FUNCTION_NATIVE(FDynArray_I16, Find, ArrayFind) { PARAM_SELF_STRUCT_PROLOGUE(FDynArray_I16); @@ -361,6 +382,14 @@ DEFINE_ACTION_FUNCTION_NATIVE(FDynArray_I32, Move, ArrayMove) return 0; } +DEFINE_ACTION_FUNCTION_NATIVE(FDynArray_I32, Append, ArrayAppend) +{ + PARAM_SELF_STRUCT_PROLOGUE(FDynArray_I32); + PARAM_POINTER(other, FDynArray_I32); + self->Append(*other); + return 0; +} + DEFINE_ACTION_FUNCTION_NATIVE(FDynArray_I32, Find, ArrayFind) { PARAM_SELF_STRUCT_PROLOGUE(FDynArray_I32); @@ -464,6 +493,14 @@ DEFINE_ACTION_FUNCTION_NATIVE(FDynArray_F32, Move, ArrayMove) return 0; } +DEFINE_ACTION_FUNCTION_NATIVE(FDynArray_F32, Append, ArrayAppend) +{ + PARAM_SELF_STRUCT_PROLOGUE(FDynArray_F32); + PARAM_POINTER(other, FDynArray_F32); + self->Append(*other); + return 0; +} + DEFINE_ACTION_FUNCTION_NATIVE(FDynArray_F32, Find, ArrayFind) { PARAM_SELF_STRUCT_PROLOGUE(FDynArray_F32); @@ -567,6 +604,14 @@ DEFINE_ACTION_FUNCTION_NATIVE(FDynArray_F64, Move, ArrayMove) return 0; } +DEFINE_ACTION_FUNCTION_NATIVE(FDynArray_F64, Append, ArrayAppend) +{ + PARAM_SELF_STRUCT_PROLOGUE(FDynArray_F64); + PARAM_POINTER(other, FDynArray_F64); + self->Append(*other); + return 0; +} + DEFINE_ACTION_FUNCTION_NATIVE(FDynArray_F64, Find, ArrayFind) { PARAM_SELF_STRUCT_PROLOGUE(FDynArray_F64); @@ -670,6 +715,14 @@ DEFINE_ACTION_FUNCTION_NATIVE(FDynArray_Ptr, Move, ArrayMove) return 0; } +DEFINE_ACTION_FUNCTION_NATIVE(FDynArray_Ptr, Append, ArrayAppend) +{ + PARAM_SELF_STRUCT_PROLOGUE(FDynArray_Ptr); + PARAM_POINTER(other, FDynArray_Ptr); + self->Append(*other); + return 0; +} + DEFINE_ACTION_FUNCTION_NATIVE(FDynArray_Ptr, Find, ArrayFind) { PARAM_SELF_STRUCT_PROLOGUE(FDynArray_Ptr); @@ -774,6 +827,14 @@ DEFINE_ACTION_FUNCTION_NATIVE(FDynArray_Obj, Move, ArrayMove) return 0; } +DEFINE_ACTION_FUNCTION_NATIVE(FDynArray_Obj, Append, ArrayAppend) +{ + PARAM_SELF_STRUCT_PROLOGUE(FDynArray_Obj); + PARAM_POINTER(other, FDynArray_Obj); + self->Append(*other); + return 0; +} + DEFINE_ACTION_FUNCTION_NATIVE(FDynArray_Obj, Find, ArrayFind) { PARAM_SELF_STRUCT_PROLOGUE(FDynArray_Obj); @@ -890,6 +951,14 @@ DEFINE_ACTION_FUNCTION_NATIVE(FDynArray_String, Move, ArrayMove) +{ + PARAM_SELF_STRUCT_PROLOGUE(FDynArray_String); + PARAM_POINTER(other, FDynArray_String); + self->Append(*other); + return 0; +} + DEFINE_ACTION_FUNCTION_NATIVE(FDynArray_String, Find, ArrayFind) { PARAM_SELF_STRUCT_PROLOGUE(FDynArray_String); diff --git a/wadsrc/static/zscript/dynarrays.zs b/wadsrc/static/zscript/dynarrays.zs index df10b70b2..2e80820cd 100644 --- a/wadsrc/static/zscript/dynarrays.zs +++ b/wadsrc/static/zscript/dynarrays.zs @@ -7,6 +7,7 @@ struct DynArray_I8 native native void Copy(DynArray_I8 other); native void Move(DynArray_I8 other); + native void Append (DynArray_I8 other); native uint Find(int item) const; native uint Push (int item); native bool Pop (); @@ -26,6 +27,7 @@ struct DynArray_I16 native native void Copy(DynArray_I16 other); native void Move(DynArray_I16 other); + native void Append (DynArray_I16 other); native uint Find(int item) const; native uint Push (int item); native bool Pop (); @@ -45,6 +47,7 @@ struct DynArray_I32 native native void Copy(DynArray_I32 other); native void Move(DynArray_I32 other); + native void Append (DynArray_I32 other); native uint Find(int item) const; native uint Push (int item); native bool Pop (); @@ -64,6 +67,7 @@ struct DynArray_F32 native native void Copy(DynArray_F32 other); native void Move(DynArray_F32 other); + native void Append (DynArray_F32 other); native uint Find(double item) const; native uint Push (double item); native bool Pop (); @@ -83,6 +87,7 @@ struct DynArray_F64 native native void Copy(DynArray_F64 other); native void Move(DynArray_F64 other); + native void Append (DynArray_F64 other); native uint Find(double item) const; native uint Push (double item); native bool Pop (); @@ -102,6 +107,7 @@ struct DynArray_Ptr native native void Copy(DynArray_Ptr other); native void Move(DynArray_Ptr other); + native void Append (DynArray_Ptr other); native uint Find(voidptr item) const; native uint Push (voidptr item); native bool Pop (); @@ -121,6 +127,7 @@ struct DynArray_Obj native native void Copy(DynArray_Obj other); native void Move(DynArray_Obj other); + native void Append (DynArray_Obj other); native uint Find(Object item) const; native uint Push (Object item); native bool Pop (); @@ -140,6 +147,7 @@ struct DynArray_String native native void Copy(DynArray_String other); native void Move(DynArray_String other); + native void Append (DynArray_String other); native uint Find(String item) const; native uint Push (String item); native bool Pop ();