瀏覽代碼

Lua: introduce coroutine thread as a basic type

Justin Donaldson 9 年之前
父節點
當前提交
e8b652e49b
共有 3 個文件被更改,包括 39 次插入1 次删除
  1. 4 0
      std/lua/Boot.hx
  2. 4 1
      std/lua/Coroutine.hx
  3. 31 0
      std/lua/Thread.hx

+ 4 - 0
std/lua/Boot.hx

@@ -19,11 +19,13 @@
  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  * DEALINGS IN THE SOFTWARE.
  * DEALINGS IN THE SOFTWARE.
  */
  */
+
 package lua;
 package lua;
 
 
 // Bit and Table must be imported for basic haxe datatypes to work.
 // Bit and Table must be imported for basic haxe datatypes to work.
 import lua.Bit;
 import lua.Bit;
 import lua.Table;
 import lua.Table;
+import lua.Thread;
 
 
 import haxe.Constraints.Function;
 import haxe.Constraints.Function;
 using lua.PairTools;
 using lua.PairTools;
@@ -106,6 +108,8 @@ class Boot {
 				return Lua.type(o) == "boolean";
 				return Lua.type(o) == "boolean";
 			case String:
 			case String:
 				return Lua.type(o) == "string";
 				return Lua.type(o) == "string";
+			case Thread:
+				return Lua.type(o) == "thread";
 			case Array:
 			case Array:
 				return Lua.type(o) == "table"
 				return Lua.type(o) == "table"
 					&& untyped o.__enum__ == null
 					&& untyped o.__enum__ == null

+ 4 - 1
std/lua/Coroutine.hx

@@ -19,6 +19,7 @@
  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  * DEALINGS IN THE SOFTWARE.
  * DEALINGS IN THE SOFTWARE.
  */
  */
+
 package lua;
 package lua;
 
 
 import haxe.Constraints.Function;
 import haxe.Constraints.Function;
@@ -29,10 +30,11 @@ import haxe.extern.Rest;
  **/
  **/
 @:native("_G.coroutine")
 @:native("_G.coroutine")
 extern class Coroutine {
 extern class Coroutine {
-	public static function create(f : Function)  : Coroutine;
+	public static function create(f : Function)  : Thread;
 	public static function status(c : Coroutine) : ThreadState;
 	public static function status(c : Coroutine) : ThreadState;
 	public static function resume(c : Coroutine, args : Rest<Dynamic>) : Dynamic;
 	public static function resume(c : Coroutine, args : Rest<Dynamic>) : Dynamic;
 	public static function yield(args : Rest<Dynamic>) : Dynamic;
 	public static function yield(args : Rest<Dynamic>) : Dynamic;
+	public static function wrap(f : Function) : Thread;
 }
 }
 
 
 @:enum
 @:enum
@@ -41,3 +43,4 @@ abstract ThreadState(String) {
 	var Running   = "running";
 	var Running   = "running";
 	var Dead      = "dead";
 	var Dead      = "dead";
 }
 }
+

+ 31 - 0
std/lua/Thread.hx

@@ -0,0 +1,31 @@
+
+/*
+ * 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 lua;
+
+/**
+  The sole purpose of this extern is to provide a concrete type for 
+  basic reflection purposes.
+**/
+
+class Thread {}