Browse Source

more HL api

Nicolas Cannasse 9 years ago
parent
commit
6e3774ec79
3 changed files with 152 additions and 1 deletions
  1. 14 1
      std/haxe/CallStack.hx
  2. 136 0
      std/hl/UI.hx
  3. 2 0
      std/hl/types/Api.hx

+ 14 - 1
std/haxe/CallStack.hx

@@ -142,6 +142,10 @@ class CallStack {
 			return []; // Unsupported
 			return []; // Unsupported
 		#end
 		#end
 	}
 	}
+	
+	#if hl
+	@:hlNative("std", "exception_stack") static function _getExceptionStack() : hl.types.NativeArray<hl.types.Bytes> { return null; }
+	#end
 
 
 	/**
 	/**
 		Return the exception stack : this is the stack elements between
 		Return the exception stack : this is the stack elements between
@@ -154,6 +158,8 @@ class CallStack {
 			return makeStack(untyped __dollar__excstack());
 			return makeStack(untyped __dollar__excstack());
 		#elseif as3
 		#elseif as3
 			return new Array();
 			return new Array();
+		#elseif hl
+			return makeStack(_getExceptionStack());
 		#elseif flash
 		#elseif flash
 			var err : flash.errors.Error = untyped flash.Boot.lastError;
 			var err : flash.errors.Error = untyped flash.Boot.lastError;
 			if( err == null ) return new Array();
 			if( err == null ) return new Array();
@@ -251,7 +257,7 @@ class CallStack {
 	}
 	}
 
 
 	#if cpp @:noStack #end /* Do not mess up the exception stack */
 	#if cpp @:noStack #end /* Do not mess up the exception stack */
-	private static function makeStack(s #if cs : cs.system.diagnostics.StackTrace #end) {
+	private static function makeStack(s #if cs : cs.system.diagnostics.StackTrace #elseif hl : hl.types.NativeArray<hl.types.Bytes> #end) {
 		#if neko
 		#if neko
 			var a = new Array();
 			var a = new Array();
 			var l = untyped __dollar__asize(s);
 			var l = untyped __dollar__asize(s);
@@ -354,6 +360,13 @@ class CallStack {
 					stack.push(method);
 					stack.push(method);
 			}
 			}
 			return stack;
 			return stack;
+		#elseif hl
+			var stack = [];
+			for( i in 0...s.length-1 ) {
+				var str = @:privateAccess String.fromUCS2(s[i]);
+				stack.push(Module(str));
+			}
+			return stack;
 		#else
 		#else
 			return null;
 			return null;
 		#end
 		#end

+ 136 - 0
std/hl/UI.hx

@@ -0,0 +1,136 @@
+/*
+ * Copyright (C)2005-2016 Haxe Foundation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+package hl;
+
+typedef WinHandle = hl.types.NativeAbstract<"ui_window">;
+
+class Window {
+
+	var h : WinHandle;
+
+	public function setText( text : String ) {
+		win_set_text(h, @:privateAccess text.bytes);
+	}
+
+	public function setEnable( b : Bool ) {
+		win_set_enable(h, b);
+	}
+
+	public function destroy() {
+		win_destroy(h);
+	}
+	
+	
+	@:hlNative("ui","ui_win_destroy")
+	static function win_destroy( win : WinHandle ) : Void {
+	}
+
+	@:hlNative("ui","ui_win_set_text")
+	static function win_set_text( win : WinHandle, text : hl.types.Bytes ) : Void {
+	}
+
+	@:hlNative("ui","ui_win_set_enable")
+	static function win_set_enable( win : WinHandle, enable : Bool ) : Void {
+	}
+
+	
+}
+
+class Button extends Window {
+	
+	public function new( parent : Window, text : String ) {
+		h = button_new(parent.h, @:privateAccess text.bytes, function() this.onClick());
+	}
+	
+	public dynamic function onClick() {
+	}
+	
+	@:hlNative("ui", "ui_button_new")
+	static function button_new( parent : WinHandle, text : hl.types.Bytes, onClick : Void -> Void ) : WinHandle {
+		return null;
+	}
+	
+}
+
+class WinLog extends Window {
+	
+	public function new( title : String, width, height ) {
+		h = winlog_new(@:privateAccess title.bytes,width, height);
+	}
+	
+	public function setTextContent( text : String, autoScroll = false ) {
+		winlog_set_text(h, @:privateAccess text.bytes,autoScroll);
+	}
+
+	
+	@:hlNative("ui","ui_winlog_new")
+	static function winlog_new( text : hl.types.Bytes, width : Int, height : Int ) : WinHandle {
+		return null;
+	}
+	
+	@:hlNative("ui","ui_winlog_set_text")
+	static function winlog_set_text( win : WinHandle, text : hl.types.Bytes, autoScroll : Bool ) : Void {
+	}
+
+}
+
+enum DialogFlags {
+	YesNo;
+	IsError;
+}
+
+@:enum abstract LoopResult(Int) {
+	var NoMessage = 0;
+	var HandledMessage = 1;
+	var Quit = 2;
+}
+
+/**
+	These are the bindings for the HL `ui.hdll` library, which contains some low level system access.
+**/
+class UI {
+
+	@:hlNative("ui","ui_init") static function init() {}
+
+	static function __init__() {
+		init();
+	}
+
+	@:hlNative("ui","ui_dialog")
+	static function _dialog( title : hl.types.Bytes, text : hl.types.Bytes, flags : Int ) : Int {
+		return 0;
+	}
+	
+	public static function dialog( title : String, text : String, flags : haxe.EnumFlags<DialogFlags> ) {
+		@:privateAccess _dialog(title.bytes,text.bytes,flags.toInt());
+	}
+	
+	@:hlNative("ui","ui_loop")
+	public static function loop( blocking : Bool ) : LoopResult {
+		return Quit;
+	}
+
+	@:hlNative("ui","ui_stop_loop")
+	public static function stopLoop() : Void {
+	}
+
+}

+ 2 - 0
std/hl/types/Api.hx

@@ -34,4 +34,6 @@ extern class Api {
 	@:hlNative("std", "value_cast") static function safeCast( v : Dynamic, t : Type ) : Dynamic;
 	@:hlNative("std", "value_cast") static function safeCast( v : Dynamic, t : Type ) : Dynamic;
 	@:hlNative("std", "make_var_args") static function makeVarArgs( v : NativeArray<Dynamic> -> Dynamic ) : haxe.Constraints.Function;
 	@:hlNative("std", "make_var_args") static function makeVarArgs( v : NativeArray<Dynamic> -> Dynamic ) : haxe.Constraints.Function;
 	@:hlNative("std", "get_virtual_value") static function getVirtualValue( v : Dynamic ) : Dynamic;
 	@:hlNative("std", "get_virtual_value") static function getVirtualValue( v : Dynamic ) : Dynamic;
+	@:hlNative("std", "set_error_handler") static function setErrorHandler( v : Dynamic -> Void ) : Void;
+	
 }
 }