Browse Source

Lua : Use table.maxn + 1 for inferring array length from tables. Close #5048

Justin Donaldson 9 years ago
parent
commit
7ede374a24
2 changed files with 2 additions and 2 deletions
  1. 1 1
      std/lua/Boot.hx
  2. 1 1
      std/lua/_std/Sys.hx

+ 1 - 1
std/lua/Boot.hx

@@ -253,7 +253,7 @@ class Boot {
 	   Define an array from the given table
 	   Define an array from the given table
 	*/
 	*/
 	public inline static function defArray<T>(tab: Table<Int,T>, ?length : Int) : Array<T> {
 	public inline static function defArray<T>(tab: Table<Int,T>, ?length : Int) : Array<T> {
-		if (length == null) length = Table.maxn(tab);
+		if (length == null) length = Table.maxn(tab) + 1; // maxn doesn't count 0 index
 		return untyped _hx_tabArray(tab, length);
 		return untyped _hx_tabArray(tab, length);
 	}
 	}
 
 

+ 1 - 1
std/lua/_std/Sys.hx

@@ -44,7 +44,7 @@ class Sys {
 	public inline static function args() : Array<String> {
 	public inline static function args() : Array<String> {
 		var args = lua.Lib.tableToArray(lua.Lua.arg).copy();
 		var args = lua.Lib.tableToArray(lua.Lua.arg).copy();
 		args.shift();
 		args.shift();
-		return args; 
+		return args;
 	}
 	}
 	public static function command( cmd : String, ?args : Array<String> ) : Int  {
 	public static function command( cmd : String, ?args : Array<String> ) : Int  {
 		cmd = Boot.shellEscapeCmd(cmd, args);
 		cmd = Boot.shellEscapeCmd(cmd, args);