소스 검색

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 년 전
부모
커밋
3491f45847
1개의 변경된 파일10개의 추가작업 그리고 1개의 파일을 삭제
  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;
 			}