Sys.hx 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. import python.lib.Time;
  2. @:preCode("import sys")
  3. @:coreApi
  4. class Sys {
  5. static var environ:haxe.ds.StringMap<String>;
  6. public static function time():Float {
  7. return Time.time()/1000;
  8. }
  9. public static function exit(code:Int):Void {
  10. python.lib.Sys.exit(code);
  11. }
  12. public static function print(v:Dynamic):Void {
  13. var str = Std.string(v);
  14. untyped __python__('sys.stdout.buffer.write(("%s"%str).encode(\'utf-8\'))');
  15. }
  16. public static function println(v:Dynamic):Void {
  17. var str = Std.string(v);
  18. untyped __python__('sys.stdout.buffer.write(("%s\\n"%str).encode(\'utf-8\'))');
  19. }
  20. public static function args() : Array<String> {
  21. var argv = python.lib.Sys.argv;
  22. return argv.slice(1);
  23. }
  24. public static function getEnv( s : String ) : String {
  25. return environ.get(s);
  26. }
  27. public static function putEnv( s : String, v : String ) : Void {
  28. environ.set(s, v);
  29. }
  30. public static function environment() : haxe.ds.StringMap<String> {
  31. return environ;
  32. }
  33. public static function sleep( seconds : Float ) : Void {
  34. python.lib.Time.sleep(seconds);
  35. }
  36. public static function setTimeLocale( loc : String ) : Bool {
  37. return false;
  38. }
  39. public static function getCwd() : String {
  40. return python.lib.Os.getcwd();
  41. }
  42. public static function setCwd( s : String ) : Void {
  43. python.lib.Os.chdir(s);
  44. }
  45. public static function systemName() : String {
  46. return "";
  47. }
  48. public static function command( cmd : String, ?args : Array<String> ) : Int {
  49. var args = args == null ? [cmd] : [cmd].concat(args);
  50. return python.lib.Subprocess.call(args);
  51. }
  52. public static function cpuTime() : Float {
  53. return 0.0;
  54. }
  55. public static function executablePath() : String {
  56. return python.lib.Sys.argv[0];
  57. }
  58. public static function getChar( echo : Bool ) : Int {
  59. return 0;
  60. }
  61. public static function stdin() : haxe.io.Input {
  62. return null;
  63. }
  64. public static function stdout() : haxe.io.Output {
  65. return null;
  66. }
  67. public static function stderr() : haxe.io.Output {
  68. return null;
  69. }
  70. static function __init__():Void {
  71. environ = new haxe.ds.StringMap();
  72. var env = python.lib.Os.environ;
  73. for (key in env.keys()) {
  74. environ.set(key, env.get(key, null));
  75. }
  76. }
  77. }