(int) SortArray(array, size, descend,
indices)
This function will sort the elements of the array passed as the first
argument. The number of elements to sort is given in the second
argument. The function will fail if size is negative, or will
return without action if size is 0. The size is implicitly
limited to the size of the array. The sorted values will be ascending
if the third argument is 0, descending otherwise. The fourth
argument, if nonzero, is an array which will be filled in with the
index mapping applied to the array. For example, if array[5] is moved
to array[0] during the sort, the value of indices[0] will be 5. This
array will be resized if necessary, but the function will fail if
resizing fails.
If the array being sorted is multi-dimensional, the sorting will use
the internal linear order. The return value is the actual number of
items sorted, which will be the value of size unless this was limited
by the actual array size.