Browse Source

[lua] refactor table creation to only use Table.create method

Justin Donaldson 9 years ago
parent
commit
aacabc1a4e
4 changed files with 7 additions and 4 deletions
  1. 1 0
      src/generators/genlua.ml
  2. 3 1
      std/lua/Table.hx
  3. 1 1
      std/lua/_std/Reflect.hx
  4. 2 2
      std/lua/_std/haxe/ds/ObjectMap.hx

+ 1 - 0
src/generators/genlua.ml

@@ -373,6 +373,7 @@ let rec gen_call ctx e el in_value =
 				gen_value ctx e
 			    ) fields;
 			    if List.length(fields) > 0 then incr count;
+		    | { eexpr = TConst(TNull)} -> ()
 		    | _ ->
 			    error "__lua_table__ only accepts array or anonymous object arguments" e.epos;
 		)) el;

+ 3 - 1
std/lua/Table.hx

@@ -5,7 +5,9 @@ package lua;
 **/
 @:native("_G.table")
 extern class Table<A,B> implements ArrayAccess<B> implements Dynamic<B> {
-	static inline function create<A,B>():Table<A,B> return untyped __lua__("{}");
+	public inline static function create<A,B>(?arr:Array<B>, ?hsh:Dynamic<B>) : Table<A,B> {
+		return untyped __lua_table__(arr,hsh);
+	}
 
 	@:overload(function<A,B>(table:Table<A,B>):Void{})
 	public static function concat<A,B>(table:Table<A,B>, ?sep:String) : String;

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

@@ -74,7 +74,7 @@ import lua.Boot;
 				// self or not
 				self_arg = true;
 			}
-			var new_args = lua.Boot.createTable();
+			var new_args = lua.Table.create();
 			for (i in 0...args.length){
 				// copy args to 1-indexed table
 				new_args[i + 1] = args[i];

+ 2 - 2
std/lua/_std/haxe/ds/ObjectMap.hx

@@ -36,8 +36,8 @@ class ObjectMap<A,B> implements haxe.Constraints.IMap<A,B> {
 	var k : Dynamic;
 
 	public inline function new() : Void {
-		h = lua.Boot.createTable();
-		k = lua.Boot.createTable();
+		h = lua.Table.create();
+		k = lua.Table.create();
 	}
 
 	public inline function set( key : A, value : B ) : Void untyped {