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 years ago
parent
commit
3491f45847
1 changed files with 10 additions and 1 deletions
  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;
 			}