瀏覽代碼

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;
 			}