Browse Source

Generating a javascript "Hello World" as lua

Here's some minimal changes to standard types that enable the
compilation of a "hello world" program:

class Main {
    static function main() {
        trace("hello world");
    }
}

Of course, the output will be javascript.  Still, we've crossed two
important hurdles:  Getting the haxe compiler to accept the new lua
platform type, and to produce a trivial program output without standard
library type errors.
Justin Donaldson 10 years ago
parent
commit
9e82b37747
4 changed files with 12 additions and 21 deletions
  1. 1 10
      std/lua/Boot.hx
  2. 2 2
      std/lua/_std/Reflect.hx
  3. 4 4
      std/lua/_std/Std.hx
  4. 5 5
      std/lua/_std/Type.hx

+ 1 - 10
std/lua/Boot.hx

@@ -19,7 +19,7 @@
  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  * DEALINGS IN THE SOFTWARE.
  */
-package js;
+package lua;
 
 class Boot {
 
@@ -30,10 +30,6 @@ class Boot {
 	private static function __trace(v,i : haxe.PosInfos) {
 		untyped {
 			var msg = if( i != null ) i.fileName+":"+i.lineNumber+": " else "";
-			#if jsfl
-			msg += __string_rec(v,"");
-			fl.trace(msg);
-			#else
 			msg += __string_rec(v, "");
 			if( i != null && i.customParams != null )
 				for( v in i.customParams )
@@ -43,19 +39,14 @@ class Boot {
 				d.innerHTML += __unhtml(msg)+"<br/>";
 			else if( __js__("typeof console") != "undefined" && __js__("console").log != null )
 				__js__("console").log(msg);
-			#end
 		}
 	}
 
 	private static function __clear_trace() {
 		untyped {
-			#if jsfl
-			fl.outputPanel.clear();
-			#else
 			var d = document.getElementById("haxe:trace");
 			if( d != null )
 				d.innerHTML = "";
-			#end
 		}
 	}
 

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

@@ -59,7 +59,7 @@
 	}
 
 	public static function isFunction( f : Dynamic ) : Bool untyped {
-		return __js__("typeof(f)") == "function" && !(js.Boot.isClass(f) || js.Boot.isEnum(f));
+		return __js__("typeof(f)") == "function" && !(lua.Boot.isClass(f) || lua.Boot.isEnum(f));
 	}
 
 	public static function compare<T>( a : T, b : T ) : Int {
@@ -78,7 +78,7 @@
 		if( v == null )
 			return false;
 		var t = __js__("typeof(v)");
-		return (t == "string" || (t == "object" && v.__enum__ == null)) || (t == "function" && (js.Boot.isClass(v) || js.Boot.isEnum(v)) != null);
+		return (t == "string" || (t == "object" && v.__enum__ == null)) || (t == "function" && (lua.Boot.isClass(v) || lua.Boot.isEnum(v)) != null);
 	}
 
 	public static function isEnumValue( v : Dynamic ) : Bool {

+ 4 - 4
std/lua/_std/Std.hx

@@ -1,5 +1,5 @@
 /*
- * Copyright (C)2005-2012 Haxe Foundation
+ * Copyright (C)2005-2015 Haxe Foundation
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
@@ -19,13 +19,13 @@
  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  * DEALINGS IN THE SOFTWARE.
  */
-import js.Boot;
+import lua.Boot;
 
 @:keepInit
 @:coreApi class Std {
 
 	public static inline function is( v : Dynamic, t : Dynamic ) : Bool {
-		return untyped js.Boot.__instanceof(v,t);
+		return untyped lua.Boot.__instanceof(v,t);
 	}
 
 	public static inline function instance<T:{},S:T>( value : T, c : Class<S> ) : S {
@@ -33,7 +33,7 @@ import js.Boot;
 	}
 
 	public static function string( s : Dynamic ) : String {
-		return untyped js.Boot.__string_rec(s,"");
+		return untyped lua.Boot.__string_rec(s,"");
 	}
 
 	public static inline function int( x : Float ) : Int {

+ 5 - 5
std/lua/_std/Type.hx

@@ -36,7 +36,7 @@ enum ValueType {
 	public static function getClass<T>( o : T ) : Class<T> untyped {
 		if( o == null )
 			return null;
-		return js.Boot.getClass(o);
+		return lua.Boot.getClass(o);
 	}
 
 	public static function getEnum( o : EnumValue ) : Enum<Dynamic> untyped {
@@ -65,7 +65,7 @@ enum ValueType {
 	public static function resolveClass( name : String ) : Class<Dynamic> untyped {
 		var cl : Class<Dynamic> = $hxClasses[name];
 		// ensure that this is a class
-		if( cl == null || !js.Boot.isClass(cl) )
+		if( cl == null || !lua.Boot.isClass(cl) )
 			return null;
 		return cl;
 	}
@@ -73,7 +73,7 @@ enum ValueType {
 	public static function resolveEnum( name : String ) : Enum<Dynamic> untyped {
 		var e : Dynamic = $hxClasses[name];
 		// ensure that this is an enum
-		if( e == null || !js.Boot.isEnum(e) )
+		if( e == null || !lua.Boot.isEnum(e) )
 			return null;
 		return e;
 	}
@@ -166,12 +166,12 @@ enum ValueType {
 			var e = v.__enum__;
 			if( e != null )
 				return TEnum(e);
-			var c = js.Boot.getClass(v);
+			var c = lua.Boot.getClass(v);
 			if( c != null )
 				return TClass(c);
 			return TObject;
 		case "function":
-			if( js.Boot.isClass(v) || js.Boot.isEnum(v) )
+			if( lua.Boot.isClass(v) || lua.Boot.isEnum(v) )
 				return TObject;
 			return TFunction;
 		case "undefined":