Commit | Line | Data |
---|---|---|
034e82ad DM |
1 | def argv List<string> { |
2 | return process.argv.slice(2) | |
3 | } | |
4 | ||
5 | def timeMs int { | |
6 | return Date.new.getTime() | |
7 | } | |
8 | ||
9 | var fs = require("fs") | |
10 | ||
11 | def readFile(filename string) string { | |
12 | return fs.readFileSync(filename, "utf-8") | |
13 | } | |
14 | ||
15 | def writeString(s string) { | |
16 | fs.writeSync(1, s) | |
17 | } | |
18 | ||
19 | def printLn(s string) { | |
20 | writeString(s) | |
21 | writeString("\n") | |
22 | } | |
23 | ||
24 | def readLine(prompt string) string { | |
25 | writeString(prompt) | |
26 | var buffer = Buffer.new(1024) # in newer Node this should be Buffer.alloc | |
27 | var stdin = fs.openSync("/dev/stdin", "rs") | |
28 | var bytesread int | |
29 | var anycharseen = false | |
30 | var total = 0 | |
31 | while (bytesread = fs.readSync(stdin, buffer, total, 1)) > 0 { | |
32 | anycharseen = true | |
33 | var lastchar = buffer.slice(total, total + bytesread).toString() | |
34 | if lastchar == "\n" { | |
35 | break | |
36 | } | |
37 | total += bytesread | |
38 | } | |
39 | fs.closeSync(stdin) | |
40 | return anycharseen ? buffer.slice(0, total).toString() : null | |
41 | } | |
42 | ||
43 | def stringToInt(str string) int { | |
44 | return parseInt(str) | |
45 | } | |
46 | ||
47 | @import { | |
48 | const process dynamic | |
49 | const Buffer dynamic | |
50 | const Date dynamic | |
51 | const Error dynamic | |
52 | ||
53 | def parseInt(str string) int | |
54 | def require(name string) dynamic | |
55 | } |