From 26462f284823a656b4d99fc5f85497de05dd5a48 Mon Sep 17 00:00:00 2001
From: JoinedSenses <joinedsenses@gmail.com>
Date: Thu, 9 May 2019 13:44:31 -0400
Subject: [PATCH] Add Sort and SortCustom to ArrayList methodmap (#1003)

---
 core/logic/smn_sorting.cpp    | 20 ++++++++++++--------
 plugins/include/adt_array.inc | 16 ++++++++++++++++
 2 files changed, 28 insertions(+), 8 deletions(-)

diff --git a/core/logic/smn_sorting.cpp b/core/logic/smn_sorting.cpp
index c60d8bf5..b67ae0fd 100644
--- a/core/logic/smn_sorting.cpp
+++ b/core/logic/smn_sorting.cpp
@@ -584,12 +584,16 @@ static cell_t sm_SortADTArrayCustom(IPluginContext *pContext, const cell_t *para
 
 REGISTER_NATIVES(sortNatives)
 {
-	{"SortIntegers",			sm_SortIntegers},
-	{"SortFloats",				sm_SortFloats},
-	{"SortStrings",				sm_SortStrings},
-	{"SortCustom1D",			sm_SortCustom1D},
-	{"SortCustom2D",			sm_SortCustom2D},
-	{"SortADTArray",			sm_SortADTArray},
-	{"SortADTArrayCustom",		sm_SortADTArrayCustom},
-	{NULL,						NULL},
+	{"SortIntegers",            sm_SortIntegers},
+	{"SortFloats",              sm_SortFloats},
+	{"SortStrings",             sm_SortStrings},
+	{"SortCustom1D",            sm_SortCustom1D},
+	{"SortCustom2D",            sm_SortCustom2D},
+	{"SortADTArray",            sm_SortADTArray},
+	{"SortADTArrayCustom",      sm_SortADTArrayCustom},
+	
+	{"ArrayList.Sort",          sm_SortADTArray},
+	{"ArrayList.SortCustom",    sm_SortADTArrayCustom},
+	
+	{NULL,                      NULL},
 };
diff --git a/plugins/include/adt_array.inc b/plugins/include/adt_array.inc
index 043898df..6713c382 100644
--- a/plugins/include/adt_array.inc
+++ b/plugins/include/adt_array.inc
@@ -208,6 +208,22 @@ methodmap ArrayList < Handle {
 	// @error               Invalid block index
 	public native int FindValue(any item, int block=0);
 
+	/**
+	 * Sort an ADT Array. Specify the type as Integer, Float, or String.
+	 *
+	 * @param order			Sort order to use, same as other sorts.
+	 * @param type			Data type stored in the ADT Array
+	 */
+	public native void Sort(SortOrder order, SortType type);
+
+	/**
+	 * Custom sorts an ADT Array. You must pass in a comparison function.
+	 *
+	 * @param sortfunc		Sort comparison function to use
+	 * @param hndl			Optional Handle to pass through the comparison calls.
+	 */
+	public native void SortCustom(SortFuncADTArray sortfunc, Handle hndl=INVALID_HANDLE); 
+
 	// Retrieve the size of the array.
 	property int Length {
 		public native get();