Browse Source

[lua] inline _hx_bind as a pure lua helper method in the compiler, rather than in Boot

Justin Donaldson 9 years ago
parent
commit
5019d12065
2 changed files with 18 additions and 24 deletions
  1. 17 1
      src/generators/genlua.ml
  2. 1 23
      std/lua/Boot.hx

+ 17 - 1
src/generators/genlua.ml

@@ -1866,7 +1866,23 @@ let generate com =
 		add_feature ctx "use._hx_bind";
 		add_feature ctx "use._hx_bind";
 		println ctx "function _hx_iterator(o)  if ( lua.Boot.__instanceof(o, Array) ) then return function() return HxOverrides.iter(o) end elseif (typeof(o.iterator) == 'function') then return  _hx_bind(o,o.iterator) else return  o.iterator end end";
 		println ctx "function _hx_iterator(o)  if ( lua.Boot.__instanceof(o, Array) ) then return function() return HxOverrides.iter(o) end elseif (typeof(o.iterator) == 'function') then return  _hx_bind(o,o.iterator) else return  o.iterator end end";
 	end;
 	end;
-	if has_feature ctx "use._hx_bind" then println ctx "_hx_bind = lua.Boot.bind";
+
+	if has_feature ctx "use._hx_bind" then begin
+	    println ctx "_hx_bind = function(o,m)";
+	    println ctx "  if m == nil then return nil end;";
+	    println ctx "  local f;";
+	    println ctx "  if o._hx__closures == nil then";
+	    println ctx "    _G.rawset(o, '_hx__closures', {});";
+	    println ctx "  else ";
+	    println ctx "    f = o._hx__closures[m];";
+	    println ctx "  end";
+	    println ctx "  if (f == nil) then";
+	    println ctx "    f = function(...) return m(o, ...) end;";
+	    println ctx "    o._hx__closures[m] = f;";
+	    println ctx "  end";
+	    println ctx "  return f;";
+	    println ctx "end";
+	end;
 
 
 
 
 	List.iter (generate_enumMeta_fields ctx) com.types;
 	List.iter (generate_enumMeta_fields ctx) com.types;

+ 1 - 23
std/lua/Boot.hx

@@ -31,7 +31,6 @@ class Boot {
 	// Used temporarily for bind()
 	// Used temporarily for bind()
 	static var _;
 	static var _;
 	static var _fid = 0;
 	static var _fid = 0;
-	static var empty_iterator : Iterator<Dynamic> = {next : function() return null, hasNext: function() return false};
 
 
 	public static var platformBigEndian = NativeStringTools.byte(NativeStringTools.dump(function(){}),7) > 0;
 	public static var platformBigEndian = NativeStringTools.byte(NativeStringTools.dump(function(){}),7) > 0;
 
 
@@ -41,24 +40,6 @@ class Boot {
 	static function __unhtml(s : String)
 	static function __unhtml(s : String)
 		return s.split("&").join("&amp;").split("<").join("&lt;").split(">").join("&gt;");
 		return s.split("&").join("&amp;").split("<").join("&lt;").split(">").join("&gt;");
 
 
-	/*
-	   Binds a function definition to the given instance
-	*/
-	@:keep
-	public static function bind(o:Dynamic, m: Function) : Function{
-		if (m == null) return null;
-		// if (m.__id.__ == nil) m.__id__ = _fid + 1;
-		var f: Function = null;
-		if ( o.hx__closures__ == null )
-			Lua.rawset(o,"hx__closures__", {});
-		else untyped f = o.hx__closures__[m];
-		if (f == null){
-			f = untyped __lua__("function(...) return m(o, ...) end");
-			untyped o.hx__closures__[m] = f;
-		}
-		return f;
-	}
-
 	/*
 	/*
 	   Indicates if the given object is a class.
 	   Indicates if the given object is a class.
 	*/
 	*/
@@ -214,10 +195,7 @@ class Boot {
 					var o2 : Array<Dynamic> = untyped o;
 					var o2 : Array<Dynamic> = untyped o;
 					if (s.length > 5) "[...]"
 					if (s.length > 5) "[...]"
 					else '[${[for (i in  o2) __string_rec(i,s+1)].join(",")}]';
 					else '[${[for (i in  o2) __string_rec(i,s+1)].join(",")}]';
-				} else if (s.length > 5){
-					"{...}";
 				}
 				}
-				else if (o.__tostring != null) Lua.tostring(o);
 				else if (o.__class__ != null) printClass(o,s+"\t");
 				else if (o.__class__ != null) printClass(o,s+"\t");
 				else {
 				else {
 					var fields = fieldIterator(o);
 					var fields = fieldIterator(o);
@@ -227,7 +205,7 @@ class Boot {
 					for (f in fields){
 					for (f in fields){
 						if (first) first = false;
 						if (first) first = false;
 						else Table.insert(buffer,", ");
 						else Table.insert(buffer,", ");
-						Table.insert(buffer,'${s}${Std.string(f)} : ${untyped Std.string(o[f])}');
+						Table.insert(buffer,'${Std.string(f)} : ${untyped Std.string(o[f])}');
 					}
 					}
 					Table.insert(buffer, " }");
 					Table.insert(buffer, " }");
 					Table.concat(buffer, "");
 					Table.concat(buffer, "");