Os.hx 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. package lua;
  2. /**
  3. Operating System Facilities.
  4. **/
  5. @:native("_G.os")
  6. extern class Os {
  7. /**
  8. Returns an approximation of the amount in seconds of CPU time used by the
  9. program.
  10. **/
  11. public static function clock() : Float;
  12. @:overload( function (format : String, time : Time) : DateType {})
  13. @:overload( function (format : String) : DateType {})
  14. public static function date() : DateType;
  15. /**
  16. Returns the number of seconds from time `t1` to time `t2`.
  17. In POSIX, Windows, and some other systems, this value is exactly `t2-t1`.
  18. **/
  19. public static function difftime(t2: Time, t1: Time) : Float;
  20. // TODO: multi-return
  21. /**
  22. This function is equivalent to the C function system. It passes command to
  23. be executed by an operating system shell. It returns a status code,
  24. which is system-dependent. If command is absent, then it returns
  25. nonzero if a shell is available and zero otherwise.
  26. **/
  27. #if (lua_ver < 5.2)
  28. public static function execute(?command:String) : Int;
  29. #elseif (lua_ver >= 5.2)
  30. public static function execute(?command:String) : OsExecute;
  31. #else
  32. public static function execute(?command:String) : Dynamic;
  33. #end
  34. /**
  35. Calls the C function exit, with an optional code, to terminate the host program.
  36. The default value for code is the success code.
  37. **/
  38. public static function exit(code: Int) : Int;
  39. /**
  40. Returns the value of the process environment variable `varname`, or `null`
  41. if the variable is not defined.
  42. **/
  43. public static function getenv(varname : String) : String;
  44. /**
  45. Deletes the file or directory with the given name.
  46. Directories must be empty to be removed.
  47. **/
  48. public static function remove(filename : String) : OsSuccess;
  49. /**
  50. Renames file or directory named `oldname` to `newname`.
  51. **/
  52. public static function rename(oldname : String, newname : String) : OsSuccess;
  53. /**
  54. Sets the current locale of the program.
  55. **/
  56. public static function setlocale(locale : String, ?category : LocaleCategory ) : String;
  57. /**
  58. Returns the current time when called without arguments, or a time
  59. representing the date and time specified by the given table.
  60. The returned value is a number, whose meaning depends on your system.
  61. In POSIX, Windows, and some other systems, this number counts the number
  62. of seconds since some given start time (the "epoch").
  63. In other systems, the meaning is not specified, and the number returned
  64. by time can be used only as an argument to date and difftime.
  65. **/
  66. public static function time(?arg : TimeParam) : Time;
  67. /**
  68. Returns a string with a file name that can be used for a temporary file.
  69. The file must be explicitly opened before its use and explicitly removed
  70. when no longer needed.
  71. When possible, you may prefer to use `Io.tmpfile`, which automatically
  72. removes the file when the program ends.
  73. **/
  74. public static function tmpname() : String;
  75. }
  76. /**
  77. A typedef that matches the date parameter `Os.time()` will accept.
  78. **/
  79. typedef TimeParam = {
  80. year : Float,
  81. month : Float,
  82. day : Float,
  83. ?hour : Int,
  84. ?min : Int,
  85. ?sec : Int,
  86. ?isdst : Bool
  87. }
  88. /**
  89. A typedef that describes the output of `Os.date()`.
  90. **/
  91. typedef DateType = {
  92. hour : Int,
  93. min : Int,
  94. sec : Int,
  95. isdst : Bool,
  96. year : Int,
  97. month : Int,
  98. wday : Int,
  99. yday : Int,
  100. day : Int,
  101. }
  102. @:multiReturn extern class OsExecute {
  103. var success : Bool;
  104. var output : String;
  105. var status : Int;
  106. }
  107. @:multiReturn extern class OsSuccess {
  108. var success : Bool;
  109. var message : String;
  110. }