Browse Source

Lua : Add extern and supporting typedefs for lua os module

Justin Donaldson 10 years ago
parent
commit
6a9b24f541
3 changed files with 64 additions and 0 deletions
  1. 10 0
      std/lua/LocaleCategory.hx
  2. 48 0
      std/lua/Os.hx
  3. 6 0
      std/lua/Time.hx

+ 10 - 0
std/lua/LocaleCategory.hx

@@ -0,0 +1,10 @@
+package lua;
+@:enum
+abstract LocaleCategory(String){
+	var All      = "all";
+	var Collate  = "collate";
+	var Ctype    = "ctype";
+	var Monetary = "monetary";
+	var Numeric  = "numeric";
+	var Time     = "time";
+}

+ 48 - 0
std/lua/Os.hx

@@ -0,0 +1,48 @@
+package lua;
+
+@:native("_G.os")
+extern class Os {
+	public static function clock() : Float;
+
+	@:overload(   function     (format : String, time : Time) : DateType {})
+	@:overload(   function     (format : String) : DateType {})
+	public static function date() : DateType;
+
+	public static function difftime(t2: Time, t1: Time) : Float;
+	public static function execute(command:String) : Int;
+	public static function exit(code: Int) : Int;
+	public static function getenv(varname : String) : String;
+	public static function remove(filename : String) : Void;
+	public static function rename(oldname : String, newname : String) : Void;
+	public static function setlocale(locale : String, ?category : LocaleCategory ) : String;
+	public static function time(?arg : DateArg) : Time;
+	public static function tmpname() : String;
+}
+
+/**
+  A typedef that matches describes the date parameter time() will accept.
+ **/
+typedef DateArg = {
+	year   : Float,
+	month  : Float,
+	day    : Float,
+	?hour  : Int,
+	?min   : Int,
+	?sec   : Int,
+	?isdst : Bool
+}
+
+/**
+  A typedef that describes the output of date().
+ **/
+typedef DateType = {
+	hour  : Int,
+	min   : Int,
+	sec   : Int,
+	isdst : Bool,
+	year  : Int,
+	month : Int,
+	wday  : Int,
+	yday  : Int,
+	day   : Int,
+}

+ 6 - 0
std/lua/Time.hx

@@ -0,0 +1,6 @@
+package lua;
+/*
+   Note: Lua timestamps are usually ints. Platform differences can produce 
+   Floats in certain cases.
+ */
+typedef Time = Float;