Explorar el Código

Lua : Fix array removal

We're adding values to the "0" index of an array, even though this isn't
a default by lua standards.  One place we need to work this situation is
in the "remove" method.  This will need to do an extra check if we're
removing from 0.
Justin Donaldson hace 10 años
padre
commit
3491f45847
Se han modificado 1 ficheros con 10 adiciones y 1 borrados
  1. 10 1
      std/lua/_std/Array.hx

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

@@ -81,7 +81,16 @@ class Array<T> {
 		for (i in 0...this.length){
 			var a = this[i];
 			if (a == x){
-				lua.TableTools.remove(cast this, i+1);
+				if (i == 0){
+					if (length == 1){
+						this[0] = null;
+					} else {
+						this[0] = this[1];
+						lua.TableTools.remove(cast this, 1);
+					}
+				} else {
+					lua.TableTools.remove(cast this, i);
+				}
 				this.length-=1;
 				return true;
 			}