2
0
Эх сурвалжийг харах

[lua] fix errors masked by incorrect error code

Justin Donaldson 8 жил өмнө
parent
commit
accc7054e7

+ 2 - 3
src/generators/genlua.ml

@@ -1573,7 +1573,6 @@ let generate_class ctx c =
 		let bend = open_block ctx in
 		let bend = open_block ctx in
 		newline ctx;
 		newline ctx;
 		let count = ref 0 in
 		let count = ref 0 in
-
 		List.iter (fun f -> if can_gen_class_field ctx f then (gen_class_field ctx c f (!count > 0); incr count;) ) c.cl_ordered_fields;
 		List.iter (fun f -> if can_gen_class_field ctx f then (gen_class_field ctx c f (!count > 0); incr count;) ) c.cl_ordered_fields;
 		if (has_class ctx c) then begin
 		if (has_class ctx c) then begin
 			newprop ctx;
 			newprop ctx;
@@ -1644,13 +1643,13 @@ let generate_enum ctx e =
 			print ctx "function(%s) local _x = _hx_tab_array({[0]=\"%s\",%d,%s,__enum__=%s}, %i);" sargs f.ef_name f.ef_index sargs p (count + 2);
 			print ctx "function(%s) local _x = _hx_tab_array({[0]=\"%s\",%d,%s,__enum__=%s}, %i);" sargs f.ef_name f.ef_index sargs p (count + 2);
 			if has_feature ctx "may_print_enum" then
 			if has_feature ctx "may_print_enum" then
 				(* TODO: better namespacing for _estr *)
 				(* TODO: better namespacing for _estr *)
-				spr ctx " _x.toString = _estr;";
+				spr ctx " rawset(_x, 'toString', _estr);";
 			spr ctx " return _x; end ";
 			spr ctx " return _x; end ";
 			ctx.separator <- true;
 			ctx.separator <- true;
 		| _ ->
 		| _ ->
 			println ctx "_hx_tab_array({[0]=\"%s\",%d,__enum__ = %s},2)" f.ef_name f.ef_index p;
 			println ctx "_hx_tab_array({[0]=\"%s\",%d,__enum__ = %s},2)" f.ef_name f.ef_index p;
 			if has_feature ctx "may_print_enum" then begin
 			if has_feature ctx "may_print_enum" then begin
-				println ctx "%s%s.toString = _estr" p (field f.ef_name);
+				println ctx "rawset(%s%s, 'toString', _estr)" p (field f.ef_name);
 			end;
 			end;
 		);
 		);
 		newline ctx
 		newline ctx

+ 1 - 8
std/lua/Boot.hx

@@ -192,9 +192,8 @@ class Boot {
 			    if (o.__enum__ != null) printEnum(o,s);
 			    if (o.__enum__ != null) printEnum(o,s);
 				else if (o.toString != null && !isArray(o)) o.toString();
 				else if (o.toString != null && !isArray(o)) o.toString();
 				else if (isArray(o)) {
 				else if (isArray(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  cast(o,Array<Dynamic>)) __string_rec(i,s+1)].join(",")}]';
 				}
 				}
 				else if (o.__class__ != null) printClass(o,s+"\t");
 				else if (o.__class__ != null) printClass(o,s+"\t");
 				else {
 				else {
@@ -304,12 +303,6 @@ class Boot {
 		return extendsOrImplements(untyped cl1.__super__, cl2);
 		return extendsOrImplements(untyped cl1.__super__, cl2);
 	}
 	}
 
 
-	/*
-	   Create an empty table.
-	*/
-	public inline static function createTable<K,V>(?arr:Array<V>, ?hsh:Dynamic<V>) : Table<K,V> {
-		return untyped __lua_table__(arr,hsh);
-	}
 
 
 	/*
 	/*
 	   Create an empty table for vectors
 	   Create an empty table for vectors

+ 7 - 2
std/lua/Os.hx

@@ -52,12 +52,12 @@ extern class Os {
 		Deletes the file or directory with the given name.
 		Deletes the file or directory with the given name.
 		Directories must be empty to be removed. 
 		Directories must be empty to be removed. 
 	**/
 	**/
-	public static function remove(filename : String) : Void;
+	public static function remove(filename : String) : OsSuccess;
 
 
 	/**
 	/**
 		Renames file or directory named `oldname` to `newname`.
 		Renames file or directory named `oldname` to `newname`.
 	**/
 	**/
-	public static function rename(oldname : String, newname : String) : Void;
+	public static function rename(oldname : String, newname : String) : OsSuccess;
 
 
 	/**
 	/**
 		Sets the current locale of the program.
 		Sets the current locale of the program.
@@ -120,3 +120,8 @@ typedef DateType = {
 	var output  : String;
 	var output  : String;
 	var status  : Int;
 	var status  : Int;
 }
 }
+
+@:multiReturn extern class OsSuccess {
+	var success : Bool;
+	var message : String;
+}

+ 8 - 4
std/lua/_std/Array.hx

@@ -41,12 +41,16 @@ class Array<T> {
 	}
 	}
 
 
 	public function pop() : Null<T> {
 	public function pop() : Null<T> {
-		return this.length == 0 ? null : this[this.length-- -1];
+		if (length == 0 ) return null;
+		var rawlength = lua.Lua.rawget(cast this, 'length');
+		var ret = lua.Lua.rawget(cast this, rawlength-1);
+		lua.Lua.rawset(cast this, 'length', rawlength-1);
+		return ret;
 	}
 	}
 	public function push(x : T) : Int {
 	public function push(x : T) : Int {
-		this[length] = x;
-		length++;
-		return length;
+		lua.Lua.rawset(cast this,length,x);
+		lua.Lua.rawset(cast this,'length', length + 1);
+		return lua.Lua.rawget(cast this,'length');
 	}
 	}
 	public function reverse() : Void {
 	public function reverse() : Void {
 		var tmp:T;
 		var tmp:T;

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

@@ -106,7 +106,12 @@ class Sys {
 	}
 	}
 
 
 	public inline static function getCwd() : String {
 	public inline static function getCwd() : String {
-		return lua.lib.lfs.Lfs.currentdir();
+		var ret = lua.lib.lfs.Lfs.currentdir();
+		if (ret.status == null){
+			throw ret.message;
+		} else {
+			return ret.status;
+		}
 	}
 	}
 
 
 	public inline static function setCwd(s : String) : Void {
 	public inline static function setCwd(s : String) : Void {

+ 13 - 4
std/lua/_std/sys/FileSystem.hx

@@ -42,7 +42,10 @@ class FileSystem {
 	}
 	}
 
 
 	public inline static function rename( path : String, newPath : String ) : Void {
 	public inline static function rename( path : String, newPath : String ) : Void {
-		return  Os.rename(path, newPath);
+		var ret = Os.rename(path, newPath);
+		if (!ret.success){
+			throw ret.message;
+		}
 	}
 	}
 
 
 	public inline static function stat( path : String ) : FileStat {
 	public inline static function stat( path : String ) : FileStat {
@@ -71,13 +74,16 @@ class FileSystem {
 
 
 	public inline static function absolutePath( relPath : String ) : String {
 	public inline static function absolutePath( relPath : String ) : String {
 		if (relPath == null) return null;
 		if (relPath == null) return null;
-		var pwd = Lfs.currentdir() ;
+		var pwd = Lfs.currentdir().status;
 		if (pwd == null) return relPath;
 		if (pwd == null) return relPath;
 		return Path.join([pwd, relPath]);
 		return Path.join([pwd, relPath]);
 	}
 	}
 
 
 	public inline static function deleteFile( path : String ) : Void {
 	public inline static function deleteFile( path : String ) : Void {
-		lua.Os.remove(path);
+		var ret = lua.Os.remove(path);
+		if (!ret.success){
+			throw ret.message;
+		}
 	}
 	}
 
 
 	public inline static function readDirectory( path : String ) : Array<String> {
 	public inline static function readDirectory( path : String ) : Array<String> {
@@ -97,7 +103,10 @@ class FileSystem {
 	}
 	}
 
 
 	public inline static function deleteDirectory( path : String ) : Void {
 	public inline static function deleteDirectory( path : String ) : Void {
-		Lfs.rmdir(path);
+		var ret = Lfs.rmdir(path);
+		if (ret.status == null){
+			throw ret.message;
+		}
 	}
 	}
 
 
 	public inline static function createDirectory( path : String ) : Void {
 	public inline static function createDirectory( path : String ) : Void {

+ 24 - 9
std/lua/lib/lfs/Lfs.hx

@@ -25,16 +25,31 @@ extern class Lfs {
 	@:overload(   function			 (filepath : String, aname : String) : Dynamic {})
 	@:overload(   function			 (filepath : String, aname : String) : Dynamic {})
 	public static function attributes(filepath : String) : LfsFileStat;
 	public static function attributes(filepath : String) : LfsFileStat;
 
 
-	public static function chdir(path : String) : Bool;
-	public static function lock_dir(path : String, ?second_stale : Int) : String; 
-	public static function currentdir() : String;
+	public static function chdir(path : String) : LfsStatus<Bool>;
+	public static function lock_dir(path : String, ?second_stale : Int) : LfsStatus<String>; 
+	public static function currentdir() : LfsStatus<String>;
 	public static function dir(path : String) : Void->String;
 	public static function dir(path : String) : Void->String;
-	public static function lock(filename : String, mode : String, ?start : Int, ?length : Int) : Bool;
+	public static function lock(filename : String, mode : String, ?start : Int, ?length : Int) : LfsStatus<Bool>;
 	public static function link(old : String, _new :String, ?symlink : Bool) : Void;
 	public static function link(old : String, _new :String, ?symlink : Bool) : Void;
-	public static function mkdir(dirname : String) : Bool;
-	public static function rmdir(dirname : String) : Bool;
-	public static function setmode(file: String, mode : String) : String;
+	public static function mkdir(dirname : String) : LfsStatus<Bool>;
+	public static function rmdir(dirname : String) : LfsStatus<Bool>;
+	public static function setmode(file: String, mode : String) : LfsStatus<Bool>;
 	public static function symlinkattributes(filepath : String, ?aname : String) : Table<String, String>;
 	public static function symlinkattributes(filepath : String, ?aname : String) : Table<String, String>;
-	public static function touch(filepath : String, ?atime : Int, ?mtime : Int) : Bool;
-	public static function unlock(filehandle : String, ?start : Int, ?length : Int) : Bool;
+	public static function touch(filepath : String, ?atime : Int, ?mtime : Int) : LfsStatus<Bool>;
+	public static function unlock(filehandle : String, ?start : Int, ?length : Int) : LfsStatus<Bool>;
 }
 }
+
+@:multiReturn extern class LfsStatus<T> {
+	var status : T;
+	var message : String;
+}
+
+@:multiReturn extern class LfsDir {
+	var iter : DirObj->String;
+	var dirobj : DirObj;
+}
+
+typedef DirObj = {
+	next : Void->String,
+	close : Void->Void
+};

+ 2 - 1
tests/unit/compile-lua.hxml

@@ -1,3 +1,4 @@
 compile-each.hxml
 compile-each.hxml
 -main unit.TestMain
 -main unit.TestMain
--lua bin/unit.lua
+-lua bin/unit.lua
+-dce no

+ 4 - 1
tests/unit/src/unit/Test.hx

@@ -272,5 +272,8 @@ class Test {
 		success = false;
 		success = false;
 		reportInfos = null;
 		reportInfos = null;
 		trace("STACK :\n"+stack);
 		trace("STACK :\n"+stack);
+#if lua
+		Sys.exit(1);
+#end
 	}
 	}
-}
+}