lib/sys.nim
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
import tables, os, osproc, strutils import ../core/types, ../core/parser, ../core/interpreter, ../core/utils # OS define("sys") .symbol("pwd") do (i: In): i.push newVal(getCurrentDir()) .symbol("cd") do (i: In): var f: MinValue i.reqString f f.strVal.setCurrentDir .symbol("ls") do (i: In): var a: MinValue i.reqString a var list = newSeq[MinValue](0) for i in walkdir(a.strVal): list.add newVal(i.path) i.push list.newVal .symbol("system") do (i: In): var a: MinValue i.reqString a i.push execShellCmd(a.strVal).newVal .symbol("run") do (i: In): var a: MinValue i.reqString a let words = a.strVal.split(" ") let cmd = words[0] var args = newSeq[string](0) if words.len > 1: args = words[1..words.len-1] i.push execProcess(cmd, args, nil, {poUsePath}).newVal .symbol("getenv") do (i: In): var a: MinValue i.reqString a i.push a.strVal.getEnv.newVal .symbol("putenv") do (i: In): var key, value: MinValue i.reqTwoStrings key, value key.strVal.putEnv value.strVal .symbol("os") do (i: In): i.push hostOS.newVal .symbol("cpu") do (i: In): i.push hostCPU.newVal .symbol("file?") do (i: In): var f: MinValue i.reqString f i.push f.strVal.fileExists.newVal .symbol("dir?") do (i: In): var f: MinValue i.reqString f i.push f.strVal.dirExists.newVal .symbol("rm") do (i: In): var f: MinValue i.reqString f f.strVal.removeFile .symbol("cp") do (i: In): var a, b: MinValue i.reqTwoStrings a, b copyFile b.strVal, a.strVal .symbol("mv") do (i: In): var a, b: MinValue i.reqTwoStrings a, b moveFile b.strVal, a.strVal .symbol("rmdir") do (i: In): var f: MinValue i.reqString f f.strVal.removeDir .symbol("mkdir") do (i: In): var f: MinValue i.reqString f f.strVal.createDir .symbol("sleep") do (i: In): var ms: MinValue i.reqInt ms sleep ms.intVal .finalize() |