Browse Source

Lua : move ugly casts and untyped calls to Boot, use Lib for a public interface for useful methods

Justin Donaldson 9 years ago
parent
commit
f540501cad
2 changed files with 22 additions and 6 deletions
  1. 13 0
      std/lua/Boot.hx
  2. 9 6
      std/lua/Lib.hx

+ 13 - 0
std/lua/Boot.hx

@@ -228,6 +228,19 @@ class Boot {
 
 	}
 
+	public inline static function tableToArray<T>(t:Table<Int,T>, ?length:Int) : Array<T> {
+		if (length == null) length = Table.maxn(t);
+		return cast defArray(t,length);
+	}
+
+	public static function defArray<T>(tab: Table<Int,T>, length : Int) : Array<T> {
+		return untyped _hx_tabArray(tab, length);
+	}
+
+	public inline static function tableToObject<T>(t:Table<String,T>) : Dynamic<T> {
+		return untyped _hx_o(t);
+	}
+
 	public static function dateStr( date : std.Date ) : String {
 		var m = date.getMonth() + 1;
 		var d = date.getDate();

+ 9 - 6
std/lua/Lib.hx

@@ -26,23 +26,26 @@ class Lib {
 	public static inline function println( v : Dynamic ) : Void {
 		lua.Lua.print(Std.string(v));
 	}
-	
+
 	public static inline function print(v:Dynamic) : Void {
 		lua.Io.write(Std.string(v));
 		lua.Io.flush();
 	}
 
 	public inline static function tableToArray<T>(t:Table<Int,T>, ?length:Int) : Array<T> {
-		if (length == null) length = Table.maxn(t);
-		return cast Lib.defArray(t,length);
+		return lua.Boot.tableToArray(t, length);
+	}
+
+	public inline static function tableToObject<T>(t:Table<String,T>) : Dynamic<T> {
+		return lua.Boot.tableToObject(t);
 	}
 
-	public static function patternQuote(str:String) : String {
+	public inline static function patternQuote(str:String) : String {
 		return lua.StringTools.gsub(str, "[%(%)%.%%%+%-%*%?%[%]%^%$]", function(c:String){ return "%" + c; });
 	}
 
-	public static function defArray<T>(tab: Table<Int,T>, length : Int) : Array<T> {
-		return untyped _hx_tabArray(tab, length);
+	public inline static function defArray<T>(tab: Table<Int,T>, length : Int) : Array<T> {
+		return lua.Boot.defArray(tab, length);
 	}
 
 	public static function fillArray<T>(itr:Void->T) : Array<T> {