Browse Source

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 10 năm trước cách đây
mục cha
commit
3491f45847
1 tập tin đã thay đổi với 10 bổ sung1 xóa
  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){
 		for (i in 0...this.length){
 			var a = this[i];
 			var a = this[i];
 			if (a == x){
 			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;
 				this.length-=1;
 				return true;
 				return true;
 			}
 			}