1
1
mirror of https://github.com/kanaka/mal.git synced 2024-09-20 18:18:51 +03:00
mal/impls/haxe/Compat.hx
Joel Martin 8a19f60386 Move implementations into impls/ dir
- Reorder README to have implementation list after "learning tool"
  bullet.

- This also moves tests/ and libs/ into impls. It would be preferrable
  to have these directories at the top level.  However, this causes
  difficulties with the wasm implementations which need pre-open
  directories and have trouble with paths starting with "../../". So
  in lieu of that, symlink those directories to the top-level.

- Move the run_argv_test.sh script into the tests directory for
  general hygiene.
2020-02-10 23:50:16 -06:00

71 lines
1.6 KiB
Haxe

#if js
@:native("console")
extern class Console {
public static function log(s:Dynamic):Void;
}
@:native("process")
extern class Process {
public static var argv(default,null):Array<String>;
public static function exit(code:Int):Void;
}
@:jsRequire("fs")
extern class FS {
static function readFileSync(filename:String,
options:{encoding:String}):String;
}
@:jsRequire("./node_readline")
extern class RL {
static function readline(prompt:String):Null<String>;
}
#end
class Compat {
public static function println(s:String) {
#if js
Console.log(s);
#else
Sys.println(s);
#end
}
public static function slurp(filename:String) {
#if js
return FS.readFileSync(filename, {encoding: "utf-8"});
#else
return sys.io.File.getContent(filename);
#end
}
public static function exit(code:Int) {
#if js
Process.exit(0);
#else
Sys.exit(0);
#end
}
public static function cmdline_args() {
#if js
return Process.argv.slice(2);
#else
return Sys.args();
#end
}
public static function readline(prompt:String) {
#if js
var line = RL.readline("user> ");
if (line == null) { throw new haxe.io.Eof(); }
#else
Sys.print("user> ");
var line = Sys.stdin().readLine();
#end
return line;
}
}