Przeglądaj źródła

Lua: Array.slice with negative pos argument needs to be wrapped from end of array, and mod to length

Justin Donaldson 9 lat temu
rodzic
commit
c11eac8b36
1 zmienionych plików z 1 dodań i 1 usunięć
  1. 1 1
      std/lua/_std/Array.hx

+ 1 - 1
std/lua/_std/Array.hx

@@ -72,7 +72,7 @@ class Array<T> {
 	public function slice( pos : Int, ?end : Int ) : Array<T> {
 		if (end == null || end > length) end = length;
 		else if (end < 0) end = length-(-end % length);
-		if (pos < 0) pos = length -(-pos % length);
+		if (pos < 0) pos = (length -(-pos % length)) % length; // negative pos needs to be wrapped from the end, and mod according to array length
 		if (pos > end || pos > length) return [];
 
 		var ret = [];